wechatpay-apiv3 / wechatpay-php

微信支付 APIv3 的官方 PHP Library,同时也支持 APIv2
Apache License 2.0
475 stars 98 forks source link

提问,Rsa::verify的问题 #101

Closed MichonneHsu closed 1 year ago

MichonneHsu commented 1 year ago

运行环境

- OS:AliOS
- PHP:8.0.15
- wechatpay-php:latest

描述你的问题现象

   $wechat_params=[
            'wechatpay_timestamp'=>$wechatpay_timestamp,
            'wechatpay_signature'=>$wechatpay_signature,
            'wechatpay_serial'=>$wechatpay_serial,
            'wechatpa_nonce'=>$wechatpa_nonce
        ];
        $inBody=json_encode([
            'id'=>$id,
            'create_time'=>$create_time,
            'resource_type'=>$resource_type,
            'event_type'=>$event_type,
            'summary'=>$summary,
            'resource'=>$resource
        ]);
        $v=Util::verify($wechat_params,$inBody);

verify代码

   $message=Formatter::joinedByLineFeed($inWechatpayTimestamp, $inWechatpayNonce, $inBody);
   $verifiedStatus =Rsa::verify($message,$inWechatpaySignature,$platformPublicKeyInstance);

我在5分钟内去验证是否有效,为什么老是$verifiedStatus返回false ?

FlynnZhouZz commented 1 year ago
image

之前我也遇到了这个问题,研究大半天之后,原来是$inWechatpayTimestamp必须是整数类型。

MikeMaldini commented 1 year ago
image

之前我也遇到了这个问题,研究大半天之后,原来是$inWechatpayTimestamp必须是整数类型。

但我这还是不通

TheNorthMemory commented 1 year ago
$inBody=json_encode

这个就不是原始传过来的JSON字符串,PHP json_encode 默认的 int $flags = 0 意味着,当原始待编码的字符串含 UNICODE, SLASH, 此函数会转义成utf-8编码格式,例如:

$a = ['c' => 'http://x', 'k' => '测试'];
print_r(json_encode($a));

打印为:

{"c":"http:\/\/x","k":"\u6d4b\u8bd5"}

而原始推送的可能是:

{"c":"http://x","k":"测试"}

你怎么校验上述自行编码的字符串,都会返回false