// 获取卡包参数
uni.request({ url: \'***\', //接口地址。 data: { cardId: _this.cardId, }, method: \'POST\', success: (res) => { if (res.data.card_id) { //将请求回来的参数保存到wxCardData中 _this.wxCardData = res.data; } else { console.log(\'获取微信卡券信息失败!\'); return; } } });
1.领取卡券
在用户点击领取卡券的时候,执行下面方法
getCoupon(){ let _this = this;
//微信卡包参数 let cardExt = { api_ticket: _this.wxCardData.api_ticket, openid: _this.wxCardData.openid, timestamp: _this.wxCardData.timestamp, nonce_str: _this.wxCardData.nonceStr, signature: _this.wxCardData.signature, outer_str: \'miniProgram\' };
//添加到微信卡包 wx.addCard({ cardList: [ { cardId: _this.vipCard.cardId, cardExt: JSON.stringify(cardExt) } ], success: res => {
//添加成功跳转 uni.navigateTo({ url: \'****\' }); }, fail: err => { console.log(err); } }); },
2.领取会员卡
goWeixinCard(){ let _this = this; let cardExt = { api_ticket: _this.wxCardData.api_ticket, openid: _this.wxCardData.openid, timestamp: _this.wxCardData.timestamp, nonce_str: _this.wxCardData.nonceStr, signature: _this.wxCardData.signature, outer_str: \'miniProgram\' }; wx.addCard({ cardList: [ { cardId: _this.vipCard.cardId, cardExt: JSON.stringify(cardExt) } ], success: res => { uni.navigateTo({
//添加成功的跳转 url: \'***\' }); }, fail: err => { console.log(err); } }); },
至此,
已完成,
里面的具体参数,可以参官方文档
注意:卡券和会员卡的参数排列是固定的。