wx.addCard 签名错误,请求帮助
发布于 5 年前 作者 mingzhong 11406 次浏览 来自 问答
  • 当前 Bug 的表现(可附上截图)

1、服务器端签名代码:

        var token =  ws.GetAccessToken(Appid, Secret);
 
        var timestamp = DateTime.Now.Ticks.ToString().Substring(0, 10);
 
        var jsapi_ticket =  Main.GetTicket(token);
 
        string nonce_str = "1000";
 
        string carid = "p1SK9wg2SA3-0JFqzlddT6w53Gnc";
 
        string order = timestamp + jsapi_ticket + carid + nonce_str;
 
        string signature = Main.MakeSha1Sign(order);
 
 
        ret = ret.Replace("{0}", carid);
 
        ret = ret.Replace("{1}", nonce_str);
 
        ret = ret.Replace("{2}", timestamp);
 
        ret = ret.Replace("{3}", jsapi_ticket);
 
        ret = ret.Replace("{4}", signature);
 
 
        HttpContext.Current.Response.Write(ret);

通过官方的签名校验工具,顺利通过

http://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=cardsign

2、微信前端代码如下:

{
    var timestamp = ""
    var signature = ""
    var cardid = ""
    var nonce_str
 
    wx.request({
      url: app.globalData.host + '/action/Handler.ashx?a=ticket&sid=' + app.globalData.shopid,
      header: {
        'content-type': 'application/json', // 默认值
        "X-SQL-AppKey": app.globalData.APPkey
      },
      success(res) {
        if (res.data) {
          console.log(res.data)
 
          cardid = res.data.carid
 
          var cardExt={}
          cardExt.timestamp = res.data.timestamp
          cardExt.signature = res.data.signature
          cardExt.nonceStr = res.data.nonce_str
 
 
          wx.addCard({
            cardList: [{
              cardId: res.data.carid,
              cardExt: JSON.stringify(cardExt)
            }, ],
            success(res) {
              console.log(res.cardList) // 卡券添加结果
            }
          })
        }
      }
    })
 
 
  }
服务器端值正常接收,现在打开提示:签名错误!

服务器端返回代码:

{carid: "p1SK9wg2SA3-0JFqzlddT6w53Gnc", nonce_str: "wxapp", timestamp: "6369869659", ticket: "IpK_1T69hDhZkLQTlwsAX2aXDM0lanFPJGw_1HYYb1bNF-NF70JbgTlOoJahIro2-ifNz4bHRR-8kdH2O4SuYQ", signature: "04f21bd32a7a6d95a504fc066eeb928377a6e564"}

cardExt: JSON.stringify(cardExt)

输出值是这个:

{"timestamp":"6369869659","signature":"04f21bd32a7a6d95a504fc066eeb928377a6e564","nonceStr":"wxapp"}

小程序已经和公众号做了关联处理!

不知道哪里出问了问题,请求帮助,谢谢!

3 回复

请问楼主是怎么解决的,我这边也是两个签名都一样但是小程序那边给提示签名错误。

问一下,那个卡券本身是不是有什么要求,我现在是用公众号appid和secret获取的token和ticket,校验也是一样的,但也是报签名错误

String url = “https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token="+accessToken+"&type=“wx_card”&offset_type=1”;

获取ticket这个没错吧

代码排版太乱了,看着头疼。

建议上个代码片段

回到顶部