wx.addCard 卡券添加显示签名错误
发布于 5 年前 作者 bzhu 5024 次浏览 来自 问答

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)
          }
        })
      }
    })
5 回复

同样的问题

请问解决了吗

“openid”: “” openid没有传入

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

楼主解决了吗?

回到顶部