微信支付 api v3 支付通知 异步 验签失败 PHP

微信支付v3 异步验签失败

此处我们接收参数(报文主体)一般是通过框架 自带的request接收。
例如TP6:$this->request->param();
这里如果使用此接收方式在进行json转换验签会失败。

我们需要用原生的接收方式:file_get_contents(‘php://input’);
接收到之后直接拿此数据进行签名验证。
附以下代码:

public function verifySign()
    {
        $timestamp = "header头中的时间戳";
        $nonce = "header头中的随机串";
        $signature = "header头中的签名";
        $certZs = "平台证书";//        $data = $this->request->param();
        $data = file_get_contents('php://input');

        $message = "$timestamp\n$nonce\n$data\n";

        //校验签名

        if (!$this->verify($message, $signature, $certZs)) {
            throw new \Exception('验签失败', 123456);
        }
    }123456789101112131415161718

猜你喜欢

转载自blog.csdn.net/ny18002122997/article/details/112915293