wechatpay-apiv3/wechatpay-php

Rsa::sign() 方法在 H5 支付会报错

MikeMaldini opened this issue · 1 comments

运行环境

- OS:Windows
- PHP:7.3
- wechatpay-php:1.4

描述你的问题现象

 $Params = [
                "amount"            => [ "total" => $Price, "currency" => $Currency ],
                "mchid"             => $this -> MerchantId,
                "description"       => $Description,
                "notify_url"        => "https://www.weixin.qq.com/wxpay/pay.php",
                "out_trade_no"      => $Order,
                "appid"             => $this -> AppId,
                "attach"            => "自定义数据说明",
                "scene_info"        => [ "payer_client_ip" => "14.23.150.211", "h5_info" => [ "type" => "Wap" ] ]
            ];
            $Resp = $Pay_Instance -> chain( 'v3/pay/transactions/h5' ) -> post([
                'json' => $Params,
                'headers' => [ 'Authorization' => Rsa::sign(
                    Formatter::joinedByLineFeed(...array_values( $Params )),
                    Rsa::from( $this -> MerchantPrivateKey_Path )
                ), 'signType' => 'RSA' ]
            ]);

二位数组会挂的 有更多的列子么 还有报错说签名不对 但你们的例子里又没签名步骤 不懂了

你并不需要传递$.headers.Authorization 请求头,SDK已经内置自动签名了,你的代码修型如下:

$Params = [
    "amount"            => [ "total" => $Price, "currency" => $Currency ],
    "mchid"             => $this -> MerchantId,
    "description"       => $Description,
    "notify_url"        => "https://www.weixin.qq.com/wxpay/pay.php",
    "out_trade_no"      => $Order,
    "appid"             => $this -> AppId,
    "attach"            => "自定义数据说明",
    "scene_info"        => [ "payer_client_ip" => "14.23.150.211", "h5_info" => [ "type" => "Wap" ] ]
];
$Resp = $Pay_Instance -> chain( 'v3/pay/transactions/h5' ) -> post([
    'json' => $Params,
]);
$RealData = json_decode((string) $Resp->getBody());
//print_r($RealData);