小程序支付签名一直报签名校验异常,请使用正确的签名,换了N多种方法都是一直这个问
530 浏览2023年09月12日作者:lyxxw

{"err_no":2008,"err_tips":"签名校验异常,请使用正确的签名","data":null}"



public function dy_pay()
    {
        $url = 'https://developer.toutiao.com/api/apps/ecpay/v1/create_order';
        $postdata['app_id'] = 'tt8880XXXXX';
        $postdata['out_order_no'] = '32781738';//订单号
        $postdata['total_amount'] = 1000;//支付金额
        $postdata['subject'] = '中文';
        $postdata['body'] = '这是个备注';//备注
        $postdata['valid_time'] = 86400;//订单有效时间
        $postdata['cp_extra'] = urlencode(json_encode(['aaa'=>234,'bbb'=>'aaa']));
        $postdata['notify_url'] = 'https://zhaoping.nycch.cn/api/index/douying';
        $postdata['thirdparty_id'] = '';
        $postdata['disable_msg'] = 0;
        $postdata['msg_page'] = 'asger';
        $postdata['store_uid'] = '1';
        $postdata['sign'] = $this->sign($postdata);//获取签名
        $res = $this->json_post($url, $postdata);
        print_r($res);
    }


    public function sign($map) {
        $rList = array();
        foreach($map as $k =>$v) {
            if ($k == "other_settle_params" || $k == "app_id" || $k == "sign" || $k == "thirdparty_id")
                continue;
            $value = trim(strval($v));
            $len = strlen($value);
            if ($len > 1 && substr($value, 0,1)=="\"" && substr($value,$len, $len-1)=="\"")
                $value = substr($value,1, $len-1);
            $value = trim($value);
            if ($value == "" || $value == "null")
                continue;
            array_push($rList, $value);
        }
        array_push($rList, "您的担保支付密钥 在支付里的担保交易设置里的SALT获取");
        sort($rList, 2);
        return md5(implode('&', $rList));
    }

    public function json_post($url, $data = NULL)
    {
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
        if (!$data) {
            return 'data is null';
        }
        if (is_array($data)) {
            $data = json_encode($data,320);
        }
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        curl_setopt($curl, CURLOPT_HEADER, 0);
        curl_setopt($curl, CURLOPT_HTTPHEADER, array(
            'Content-Type: application/json; charset=utf-8',
            'Content-Length:' . strlen($data),
            'Cache-Control: no-cache',
            'Pragma: no-cache'
        ));
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $res = curl_exec($curl);
        curl_close($curl);
        return $res;
    }

代码是这样的。但是一直报签名错误
用签名工具生成的签名和下单生成的签名是样的,但就是一直说签名效验异常

最后一次编辑于 2023 年 09 月 12 日
2 条评论

相关问答

专题推荐

热门文章

热门问答