欢迎光临,了解微信小程序开发,就上易用通!

微信小程序卡券开发(亲测)

发布:2017-12-16 14:57浏览: 来源:网络 作者:tianshu

提示:小程序卡券和公众平台调用基本一致,请先查看公众平台卡券文档 一、公众帐号/小程序绑定 由于微信卡券用的是一套逻辑。所以小程序需要先和公众账号绑定,才能在小程序中调起公众平台卡券 登录微信公众平台:h ...

 
 
 
提示:小程序卡券和公众平台调用基本一致,请先查看公众平台卡券文档

一、公众帐号/小程序绑定
由于微信卡券用的是一套逻辑。所以小程序需要先和公众账号绑定,才能在小程序中调起公众平台卡券
登录微信公众平台:https://open.weixin.qq.com/ 进行绑定操作
QQ截图20170603110606.png

二、公众号卡券添加小程序字段
更改卡券信息接口:https://api.weixin.qq.com/card/update?access_token=TOKEN
文档参考:https://mp.weixin.qq.com/cgi-bin ... ng=zh_CN&platform=2


[PHP] 

							
  1. $access_token = 'Yn6h-PM679IXWtndisSKGtxWHV3rHpIl9IrUVFgE96m4aKbhyVDiG34OuOUGs_SIIceQSplwLWWexURWiuXGyTkaYXU8pFW-goveJ8XQJvpSU1KX9UnUssssssssssQhAAAGWZ';
  2.  
  3. $post = '{
  4.  
  5. "card_id":"cccccccccccccccccc-dw",
  6.  
  7. "gift": {
  8.  
  9. "base_info": {
  10.  
  11. "custom_url_name": "小程序",
  12.  
  13. "custom_url": "https://www.qq.com",
  14.  
  15. "custom_app_brand_user_name": "gh_aaaaaaaaaaa@app",
  16.  
  17. "custom_app_brand_pass":"pages/index/index",
  18.  
  19. "custom_url_sub_title": "点击进入",
  20.  
  21. "promotion_url_name": "更多信息",
  22.  
  23. "promotion_url": "https://www.qq.com",
  24.  
  25. "promotion_app_brand_user_name": "gh_aaaaaaaaaaa@app",
  26.  
  27. "promotion_app_brand_pass":"pages/index/index"
  28.  
  29. }
  30.  
  31. }
  32.  
  33. }';
  34.  
  35. $url = "https://api.weixin.qq.com/card/update?access_token={$access_token}";
  36.  
  37.  
  38.  
  39. $curl = curl_init();
  40.  
  41. curl_setopt($curl, CURLOPT_URL, $url);
  42.  
  43. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
  44.  
  45. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
  46.  
  47. if (!empty($post)) {
  48.  
  49. curl_setopt($curl, CURLOPT_POST, 1);
  50.  
  51. curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
  52.  
  53. }
  54.  
  55. curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
  56.  
  57. $output = curl_exec($curl);
  58.  
  59. curl_close($curl);
  60.  
  61.  
  62.  
  63. var_dump($output);
  64.  
  65. die();
三、卡券签名 卡券签名与公众号卡券签名一致,注意使用api_ticket签名 参考文档:https://mp.weixin.qq.com/wiki?ac ... 52296&highline=card|%26amp%3Bcardext#fl4 卡券签名验证工具:https://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=cardsign 四、小程序调用 注意点: 1、卡券字段use_custom_code填写为false时,code字段不用加到cardExt 2、卡券字段bind_openid填写为false是,openid字段不用加到cardExt 3、当签名时使用nonce_str字段签名时,nonce_str字段需要加到cardExt
[JavaScript] 

							
  1. let cardExt='{"timestamp":"'+res.data[0].timestamp+'","signature":"'+res.data[0].signature+'","nonce_str":"'+res.data[0].nonce_str+'"}'
  2.  
  3. wx.addCard({
  4.  
  5. cardList: [
  6.  
  7. {
  8.  
  9. cardId: res.data[0].cardId,
  10.  
  11. cardExt: cardExt
  12.  
  13. }
  14.  
  15. ],
  16.  
  17. success: function(res) {
  18.  
  19. console.log(res)
  20.  
  21. }
  22.  
  23. })
  24.  
领取卡券后返回数据格式 QQ截图20170603143325.png





免责声明:本站所有文章和图片均来自用户分享和网络收集,文章和图片版权归原作者及原出处所有,仅供学习与参考,请勿用于商业用途,如果损害了您的权利,请联系网站客服处理。