Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

js端查看微信卡券接口 chooseCard #79

Closed
shouaya opened this issue Aug 14, 2015 · 3 comments
Closed

js端查看微信卡券接口 chooseCard #79

shouaya opened this issue Aug 14, 2015 · 3 comments
Labels
Milestone

Comments

@shouaya
Copy link

shouaya commented Aug 14, 2015

以下为php代码

$config = array(
     'use_alias'    => false,
     'app_id'       => WxPayConfig::APPID,
     'secret'       => WxPayConfig::APPSECRET,
     'token'        => WxPayConfig::APPTOKEN,
     'encoding_key' => WxPayConfig::ENCODING_KEY // 加密模式需要,其它模式不需要
);
$js = new Js($config);
$card = new Card($config);
$timestamp = time();
$nonce_str = $card->getNonce();
$api_ticket = $card->getTicket();
//根据http://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=cardsign 来看需要appid和cardType
$signature = $card->getSignature($api_ticket, $timestamp, WxPayConfig::APPID, 'CASH', $nonce_str);

以下为js代码

 wx.config(<?php echo $js->config(array('chooseCard'), true, true) ?>);
 wx.ready(function () {
     document.querySelector('#chooseCard').onclick = function () {
         wx.chooseCard({
             cardType: 'CASH', //需要与卡券签名传入参数保持一致
             timestamp: <?php echo $timestamp ?>, // 卡券签名时间戳
             nonceStr: '<?php echo $nonce_str ?>', // 卡券签名随机串
             cardSign: '<?php echo $signature ?>', // 卡券签名
             success: function (res) {
                 alert(res);
                 var cardList= res.cardList; // 用户选中的卡券列表信息
             }
         });
     }
 });
@overtrue
Copy link
Collaborator

https://github.com/overtrue/wechat/blob/2.0/src/Wechat/Card.php#L532

其实 getSignature 方法的参数并没有固定的

@shouaya
Copy link
Author

shouaya commented Aug 14, 2015

但是官方文档上cardType说是非必须的,感觉这里是不是可以做个专门生成chooseCard参数的方法,比如
$card->chooseCard('cardType'),前端就可以直接调用了

@overtrue
Copy link
Collaborator

这事儿,3.0版本我考虑一下,2.0 不会新增功能了。

@overtrue overtrue added this to the 3.0 milestone Aug 14, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants