微信卡券核销

时间:2022-08-30 00:22:15

1.引入JS文件

<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.0.0.js "></script>


2.js配置

<script type="text/javascript">
wx.config({
// debug: true,
appId: '<?php echo $wxjs['appId']?>',
timestamp: <?php echo $wxjs['timestamp']?>,
nonceStr: '<?php echo $wxjs['nonceStr']?>',
signature: '<?php echo $wxjs['signature']?>',
jsApiList: [
'pauseVoice',
'chooseCard',
]
});
wx.error(function (res) {
alert(res.errMsg);
});
wx.ready(function(){
});
</script>


3.拉起店铺可用卡券列表

<script type="text/javascript">
function doFind(){
wx.chooseCard({
shopId: '', // 门店Id
cardType: '<?php echo $arr['card_type']?>', // 卡券类型
cardId: '', // 卡券Id
timestamp: '<?php echo $arr['time_stamp']?>', // 卡券签名时间戳
nonceStr: '<?php echo $arr['nonceStr']?>', // 卡券签名随机串
signType: 'SHA1', // 签名方式,默认'SHA1'
cardSign: '<?php echo $arr['sign']?>', // 卡券签名
success: function (res) {
var cardList= res.cardList; // 用户选中的卡券列表信息
$('#s').html(cardList);
}

})
}

</script>

4.Code解码

http请求方式: POST
https://api.weixin.qq.com/card/code/decrypt?access_token=TOKEN

POST数据

{
"encrypt_code":"XXIzTtMqCxwOaawoE91+VJdsFmv7b8g0VZIZkqf4GWA60Fzpc8ksZ/5ZZ0DVkXdE"
}

5.查询Code的有效应

http请求方式: POST
https://api.weixin.qq.com/card/code/consume?access_token=TOKEN

POST数据

非自定义Code卡券的请求{  "code": "12312313"}或自定义Code卡券的请求{  "code": "12312313",  "card_id": "pFS7Fjg8kV1IdDz01r4SQwMkuCKc"}

6.核销

接口调用请求说明

http请求方式: POST
https://api.weixin.qq.com/card/code/consume?access_token=TOKEN

POST数据

非自定义Code卡券的请求{  "code": "12312313"}或自定义Code卡券的请求{  "code": "12312313",  "card_id": "pFS7Fjg8kV1IdDz01r4SQwMkuCKc"}