html52.com
我爱小程序-开发者交流社区

addCard签名错误-天坑-爬坑血泪恩仇录

如果你发现了签名错误,注意了啊,如果其他都没问题,那有可能是你的URL出现了重大错误!

小程序添加卡券,签名这URL要改成wx_card来获取。


比如获取Ticket,URL要是这样的!!


https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=" . $token . "&type=wx_card";

俩灯泡瞪圆了啊!是type=wx_card

type=wx_card

type=wx_card

type=wx_card

重要事情多说几遍!!


获取AccessToken要使用微信公众号不是小程序的,实现见帖子:

https://www.jianshu.com/p/7d1f08f3a460


这里不再赘述过程,



官方曾经给的JSSDK的simple.zip文件中的jssdk.php文件中第52行

$url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi&access_token=$accessToken";

type=jsapi修改成type=wx_cardtype=jsapi修改成type=wx_cardtype=jsapi修改成type=wx_cardtype=jsapi修改成type=wx_card,签名方法:


function cardSignature($timestamp, $api_ticket, $noncestr, $card_id){
    $arr = array();
    $arr['timestamp'] = $timestamp;
    // $arr['code'] = $code;
    $arr['nonce_str'] = $noncestr;
    $arr['ticket'] = $api_ticket;
    // $arr['openid'] = $openid;
    $arr['card_id'] = $card_id;
//根据官网说明,卡券签名需要的参数有:timestamp(时间戳),code(卡的编号),nonce_str(随机字符串),ticket(卡券ticket),openid(用户的openid),card_id(卡券的ID)
    sort($arr, SORT_STRING); //排序,这一步一定要有,否则会不成功
    $str = implode($arr);
    // $str = '';
    // foreach ($arr as $v) {
    //     $str .= $v;
    // }
     
//通过foreach组装成字符串
    $signature = sha1($str); //最后通过sha1生成签名
    // return array('code' => $code,'openid' =>$openid,'timestamp'=>$timestamp,'nonce_str'=>$noncestr,'signature'=>$signature);
    return ['signature'=>$signature, 'timestamp'=>$timestamp, 'nonce_str'=>$noncestr, 'card_id'=>$card_id, 'api_ticket'=>$api_ticket];
}


爬坑记录


https://www.jianshu.com/p/7d1f08f3a460

https://www.jianshu.com/p/a0863e704405


评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

真正的个人免签约支付接口

云免签H5支付