收藏
回答

requestCommonPayment signature 错误 702003

seeion_key 是每次都获取的, appkey 也是现网的,但是一直提示签名错误,哪位大佬给看看吧

 /**
     * @notes 主页
     * @param string $name
     * @return \think\response\Json|\think\response\View
     * @author 段誉
     * @date 2022/10/27 18:12
     */
    public function index($name = '你好,ysadmin')
    {
        $url = 'https://api.weixin.qq.com/sns/jscode2session?appid=是正确的&secret=是正确的&js_code='.input('code').'&grant_type=authorization_code';
        $se = file_get_contents($url);
        $se = json_decode($se,true);
        /*************************支付开始****************************/
        $mchid = '1722152560';//商户号
        $ddcode = '175273865318685216';//订单号
        $description = 'spgm';//支付描述
        $appkey = '使用的现网的正确的';//注意使用环境对用的appkey
        $session_key = $se['session_key'];//当前登录用户的session_key

        $postdata = [];
        $postdata['mchid'] = $mchid;
        $postdata['out_trade_no'] = $ddcode;
        $postdata['description'] = $description;
        $postdata['amount'] = [
            'order_amount'=>1,//支付金额 分
            'currency'=>'CNY',//固定人民币 CNY
        ];
        $postdata['env'] = 0; //0现网 1沙箱
        $postdata = json_encode($postdata);

        $paySign = $this->calc_pay_sig('requestCommonPayment',$postdata,$appkey);
        $signature = $this->calc_signature($postdata,$session_key);

        echo json_encode(array("code" => 200, "msg" => "获取成功",'data'=>[
            'paySign'=>$paySign,
            'signature'=>$signature,
            'signData'=>$postdata,
            'mode' => "retail_pay_goods",
        ]));
        die;

  
    }
//签名算法
    public function calc_pay_sig($uri, $post_body, $appkey)
    {
        $temp = $uri . '&' . $post_body;
        return hash_hmac('sha256', $temp, $appkey);
    }


//用户登录态signature签名算法
    public function calc_signature($post_body, $session_key)
    {
        return hash_hmac('sha256', $post_body, $session_key);
    }


回答关注问题邀请回答
收藏

1 个回答

登录 后发表内容