jssdk - 为什么IOS设备,调用微信添加卡券接口,报签名错误,而安卓正常?
PHP中文网
PHP中文网 2017-04-17 17:25:01
0
2
583

使用安卓设备领取结果

使用ios设备领取结果

调用时的token:_j5pCqFql151jN3hrQZfdsULPBMCyMsL3-6PnQKhHHT1xd5LO_DOjYWG9ZTr_BPYNkNV3riYVJBsql34SSORlk7--nvpKyS9_Vu69eid08cXEUgAGAQXN
调用时的apiticket:m7RQzjA_ljjEkt-JCoklRAv1CEm-BtI3wtBMdD1vRTqF6-dSZw8DD0sOClSh9FbTQ-rqpBFsw4j0r-nXNqyncw
调用时的jsapiticket:bxLdikRXVbTPdHSM05e5u-nGyw_RTvOVBQl2rntjEm6Mia6_h_tArfj2hSKVtX0Fu5-MKPaU9muHpQt7yfpztg

微信web调试工具:
card_ext {5}
code :
nonce_str : hLucummFJqISxUx
openid :
signature : 5c2054a6a90e291bdc3bf15c29805e49ef0aeff5
timestamp : 1453186049
card_id : p2HbijhIYRhCA1YSHYNXbU93CtT4

调试工具生成的签名:

前端部分代码:

wx.config({
                    debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
                    appId: config.appId, // 必填,公众号的唯一标识
                    timestamp: config.timestamp, // 必填,生成签名的时间戳
                    nonceStr: config.nonceStr, // 必填,生成签名的随机串
                    signature: config.signature,// 必填,签名,见附录1
                    jsApiList: ['addCard', 'closeWindow']// 必填,需要使用的JS接口列表,所有JS接口列表见附录2
                });
                wx.ready(function () {
                    setTimeout("add_card_local();", 1000); 
                });
                wx.error(function (res) {
                });
                
                
         wx.addCard({
                cardList: [{
                    cardId: config1.card_id,
                    cardExt: config1.card_ext
                }], // 需要添加的卡券列表
                success: function (res) {
                    wx.closeWindow();
                },
                fail: function (res) {
                    //wx.closeWindow();
                },
                cancel: function (res) {
                  // wx.closeWindow();
                }
            });

系统运行环境:
winserver 2008.
.net framework 4.5.
IIS 7.5.

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(2)
阿神

I struggled with the problem for two days and posted it here. As a result, during the review process, I found a solution, but I did not continue to delve into the problem. I will verify it later.

The development document states:
See Appendix 4 for details on cardExt. It is worth noting that the card_ext parameter here must be consistent with the parameters involved in the signature, and the format is a string instead of Object, otherwise a signature error will be reported.

cardList: [{

                cardId: config1.card_id,
                cardExt: config1.card_ext
            }]

And I used var config1 = strToJson(wxconfigstr1);
function strToJson(str) {

if (str == "")
    return "";
var json = eval('(' + str + ')');
return json;

};
I think there are two possibilities.
The first one is that IOS parses card_ext in config1 as object, while Android parses it as string.
Second, IOS and Android parse the card_ext of config1 into object, but Android does a step of packet sealing and changes it into string.
To be further verified.

The final solution is to assign card_ext with a string value.

左手右手慢动作

I also encountered a strange problem, similar to yours.
The code is almost the same as yours. The problem is:
The closeWindow error in success and cancel after addCard
Is it also a cardExt problem?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!