您现在的位置:爱折腾>> web>>正文内容

微信卡卷测试代码

创建卡卷:

  1. public function createcard(){//新建卡卷  
  2.     $appid=C('APPID');  
  3.          $appsecret=C('SCRETID');  
  4.         $asstonek = $this->get_token($appid,$appsecret);  
  5.         $url = "https://api.weixin.qq.com/card/create?access_token=".$asstonek;  
  6.         $pjson ='{ "card": {  
  7. "card_type""GROUPON",  
  8. "groupon": {  
  9. "base_info": {  
  10. "logo_url":  
  11. "http://mmbiz.qpic.cn/mmbiz/ibkgH5qOticpLRCYTKmibPW028nOv2YYg42UsK8MWV5fVLRUUTrNyrg3nJgxThaP9tNg1JZXHk88FdLqxmmNq4CHg/0?wx_fmt=jpeg",  
  12. "brand_name":"海底捞123",  
  13. "code_type":" CODE_TYPE_TEXT ",  
  14. "title""132 元双人火锅套餐",  
  15. "sub_title""",  
  16. "color""Color010",  
  17. "notice""使用时向服务员出示此券",  
  18. "service_phone""020-88888888",  
  19. "description": "不可与其他优惠同享\n 如需团购券发票, 请在消费时向商户提出\n 店内均可  
  20. 使用,仅限堂食\n 餐前不可打包,餐后未吃完,可打包\n 本团购券不限人数,建议 2 人使用,超过建议人  
  21. 数须另收酱料费 5 元/位\n 本单谢绝自带酒水饮料",  
  22. "date_info": {  
  23. "type": 2,  
  24. "fixed_term": 30,  
  25. "fixed_begin_term": 0  
  26. },  
  27. "sku": {  
  28. "quantity": 500000  
  29. },  
  30. "get_limit": 3,  
  31. "use_custom_code"false,  
  32. "bind_openid"false,  
  33. "can_share"true,  
  34. "can_give_friend"true,  
  35. "location_id_list" : [123, 12321, 345345],  
  36. "custom_url_name""立即使用",  
  37. "custom_url""http://www.qq.com",  
  38. "custom_url_sub_title""6 个汉字 tips",  
  39. "promotion_url_name""更多优惠",  
  40. "promotion_url""http://www.qq.com",  
  41. "source""大众点评" 
  42. },  
  43. "deal_detail": "以下锅底 2 选 1(有菌王锅、麻辣锅、大骨锅、番茄锅、清补凉锅、酸菜鱼锅可  
  44. 选):\n 大锅 1 份 12 元\n 小锅 2 份 16 元\n 以下菜品 2 选 1\n 特级肥牛 1 份 30 元\n 洞庭鮰鱼卷 1 份  
  45. 20 元\n 其他\n 鲜菇猪肉滑 1 份 18 元\n 金针菇 1 份 16 元\n 黑木耳 1 份 9 元\n 娃娃菜 1 份 8 元\n 冬  
  46. 瓜 1 份 6 元\n 火锅面 2 个 6 元\n 欢乐畅饮 2 位 12 元\n 自助酱料 2 位 10 元"}  
  47. }  
  48. }';  
  49.  
  50.  
  51. $re3 = $this->curlp($url,$pjson);  
  52.         $re3arr = json_decode($re3,true);  
  53.         dump($re3arr);  
  54.       
  55.     }  
  56. 卡卷领取测试:(二维码)  
  57.  
  58. public function tcard(){//卡卷测试  
  59.     header ( "Content-Type: text/html; charset=UTF-8" );  
  60.       
  61.       
  62.         $appid=C('APPID');  
  63.          $appsecret=C('SCRETID');  
  64.         $asstonek = $this->get_token($appid,$appsecret);          
  65.         $ticket = $this->get_card_ticket($asstonek);  
  66.         dump($asstonek);  
  67.         dump($ticket);  
  68.           
  69.           
  70.         /*  获取卡卷列表
  71.         $url = "https://api.weixin.qq.com/card/batchget?access_token=".$asstonek;  
  72.         $jsondata = '{"offset":0,"count":10}';  
  73.         $re = $this->curlp($url,$jsondata);  
  74.         dump($re);  
  75.         */ 
  76.           
  77.         //  获取卡卷详情  
  78.         $url3 = "https://api.weixin.qq.com/card/get?access_token=".$asstonek;  
  79.         $getcardinfo = '{  
  80. "card_id":"pYKCus2uC2fwIf3STA-agJ_XhqfI" 
  81. }';  
  82.  
  83.     $re3 = $this->curlp($url3,$getcardinfo);  
  84.         $re3arr = json_decode($re3,true);  
  85.         dump($re3arr);  
  86.         //  status =  CARD_STATUS_VERIFY_OK  卡卷审核通过  
  87.         //  获取卡卷详情  
  88.           
  89.           
  90.         $fcardjson = '{  
  91. "action_name""QR_CARD",  
  92. "action_info": {  
  93. "card": {  
  94. "card_id""pYKCus2uC2fwIf3STA-agJ_XhqfI",  
  95. "is_unique_code"false ,  
  96. }  
  97. }  
  98. }';  
  99.  
  100. $url2 = "https://api.weixin.qq.com/card/qrcode/create?access_token=".$asstonek;  
  101. $re2 = $this->curlp($url2,$fcardjson);  
  102. $re2arr = json_decode($re2,true);  
  103. $ewmticket = $re2arr['ticket'];  
  104. if($re2arr['errmsg']!='ok') exit($re2arr['errmsg']);  
  105. dump($re2arr);  
  106. echo '<img src="https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket='.$ewmticket.'">';  
  107.           
  108.           
  109.           
  110.     }  

卡卷投放(领取):html5 js api

  1. public function get_h5_card($data=array()){  
  2.     $appid=$this->appid;  
  3.     $appsecret=$this->appsecret;  
  4.     $asstonek = $this->get_token($appid,$appsecret);          
  5.     $ticket = $this->get_card_ticket($asstonek);  
  6.     $data['api_ticket']=$ticket;  
  7.     $data['timestamp']=time();  
  8.     $data['signature'] = self::getSign($data);    
  9.     //echo $ticket;  
  10.     $data2['card_id']=$data['card_id'];  
  11.     unset($data['api_ticket']);  
  12.     unset($data['card_id']);  
  13.     $data2['card_ext']=json_encode($data);  
  14.     return $data2;  
  15.     dump($data);  
  16. }     
  17.       
  18.  
  19. public function tcard1(){//html5 js api 卡卷投放  
  20.         $card = new \Org\Util\Card('wx37445*******3ae8','6854f901**********4f9a3');  
  21.         $cardid = 'pYKCus4Tmp_sBh6eiqfG-hN_ySzc';  
  22.         $data['card_id']=$cardid;  
  23.         $data['code']='';  
  24.         $data['openid']='';  
  25.         $data2 = $card->get_h5_card($data);  
  26.         $this->assign('carddata',json_encode($data2));  
  27.         //dump(($data2));  
  28.         $this->siteDisplay ( 'card' );  

需要完整卡卷投放接口请淘宝联系我。

相关文章