收藏
回答

wx.addCard 卡券添加显示签名错误

问题模块
API和组件

wx.addCard能够正常显示卡卷,但是领取按钮显示 “签名错误”


签名算法如下:

public function getCard($card_id,$sessionId){
        //获取openid
        $openid = $this->openId($sessionId);
        //获取ticket
        $res = $this->getApiTicket();
 
        //生成签名
        $now =time();
        $timestamp = $now;
        $nonceStr = $this->createNonceStr(8);
        $arr = array($card_id,$res['ticket'],$nonceStr,$openid,$timestamp);//组装参数
        asort($arr, SORT_STRING);
        $sortString = "";
        foreach($arr as $temp){
            $sortString = $sortString.$temp;
        }
        $signature = sha1($sortString);
 
        $card = array(
            'timestamp' => $timestamp,
            'signature' => $signature,
            'cardId' => $card_id,
            'ticket' => $res['ticket'],
            'nonce_str' => $nonceStr
        );
        return $card;
    }



小程序js

wx.request({
      url: url + '/api/app/getAppCard',
      data:{
        session_id : sessionId,
        card_id: 'pwJno0xiCS3HfuSpQoJtTCtEXODU'
      },
      success: function (res) {
        var card_info = res.data.cardArray
        console.log(res.data.cardArray)
        wx.addCard({
          cardList: [
            {
              cardId: card_info.cardId,
              cardExt: '{"code": "", "openid": "", "timestamp": "'+card_info.timestamp+'", "signature":"'+card_info.signature+'"}'
            }
          ],
          success: function (res) {
            console.log(res) // 卡券添加结果
          },
          fail: function (res) {
            console.log(res)
          },
          complete: function(res)
          {
            console.log(res)
          }
        })
      }
    })


最后一次编辑于  2017-09-16
回答关注问题邀请回答
收藏

5 个回答

  • 春风十里
    春风十里
    2018-08-24

    请问解决了吗

    2018-08-24
    赞同
    回复
  • 荣v格
    荣v格
    2018-06-01

    "openid": "" openid没有传入

    2018-06-01
    赞同
    回复
  • guhaoZhn
    guhaoZhn
    2018-05-07

    那是因为后端没有开启code自定义,又提供了code给前端传参数

    2018-05-07
    赞同
    回复
  • 微正
    微正
    2018-03-08

    同样的问题

    2018-03-08
    赞同
    回复
  • 微正
    微正
    2018-03-08

    楼主解决了吗?

    2018-03-08
    赞同
    回复