yansongda / pay

可能是我用过的最优雅的 Alipay/WeChat/Unipay/江苏银行 的支付 SDK 扩展包了
http://pay.yansongda.cn
MIT License
4.99k stars 1.02k forks source link

配置微信公钥证书 提示 5003 #636

Closed linshunwei closed 2 years ago

linshunwei commented 2 years ago

包版本号

3.1.8

问题描述

不配置微信公钥证书路径可正常生成支付参数 已开启如报错详情 前面那段是成功的 后面提示5003

你的代码

配置

"alipay": {
      "default": {
      ……
      }
    },
    "wechat": {
      "default": {
        "mch_id": "1602***5",
        "mch_secret_key": "FD***B52",
        "mch_secret_cert": "/xxx/storage/files/pem/mch_secret_cert_path.pem",
        "mch_public_cert_path": "/xxx/storage/files/pem/mch_public_cert_path.pem",
        "notify_url": "https://xxx.com/api/callback/wechatpay",
        "mp_app_id": "wx7a6xx22cdd",
        "mini_app_id": "wxfexx04c29",
        "app_id": "wx58xxb652",
        "wechat_public_cert_path": {
          "7E8ExxxB28": "/xxx/storage/files/pem/mch_public_cert_path.pem"

通过 ./bin/CertificateDownloader.php -k FD***B52 -m 1602118085 -f  ./apiclient_key.pem(同mch_secret_cert) -s 38xx141(api证书序列号) -o ./
生成 Serial Number: 7E8ExxxB28 的平台证书 /xxx/storage/files/pem/mch_public_cert_path.pem
把wechat_public_cert_path配置成 wechat_public_cert_path:null 是可以正常生成参数的
        },
        "mode": 0
      }
    },
    "logger": {
      "enable": true,
      "file": "/xxx/storage/logs/pay.log",
      "level": "debug",
      "type": "daily",
      "max_file": 30
    },
    "http": {
      "timeout": 5,
      "connect_timeout": 5
    }

请求代码

$order = [
            'out_trade_no' => time(),
            'description' => 'subject-测试',
            'amount' => [
                'total' => 1,
            ],
        ];

$result = Pay::wechat($config)->scan($order)

报错详情

Yansongda\Pay\Exception\InvalidResponseException {#613
  +exception: null
  +response: array:2 [
    "headers" => array:15 [
      ……
    ]
    "body" => "{"code_url":"weixin://wxpay/bizpayurl?pr=FPWxxx"}"
  ]
  +extra: array:2 [
    "headers" => array:15 [
      ……
      ]
    ]
    "body" => "{"code_url":"weixin://wxpay/bizpayurl?pr=FPWxxx"}"
  ]
 #message: ""
#code: 5003
  #file: "/usr/local/var/wwwroot/demo/demo_api/vendor/yansongda/pay/src/Functions.php"
  #line: 219
  trace: {
    /usr/local/var/wwwroot/demo/demo_api/vendor/yansongda/pay/src/Functions.php:219 {
      verify_wechat_sign(MessageInterface $message, array $params): void …
      › if (!$result) {
      ›     throw new InvalidResponseException(Exception::INVALID_RESPONSE_SIGN, '', ['headers' => $message->getHeaders(), 'body' => $body]);
      › }
    }
    /usr/local/var/wwwroot/demo/demo_api/vendor/yansongda/pay/src/Plugin/Wechat/LaunchPlugin.php:32 {
      Yansongda\Pay\Plugin\Wechat\LaunchPlugin->assembly(Rocket $rocket, Closure $next): Rocket …
      › if (should_do_http_request($rocket->getDirection())) {
      ›     verify_wechat_sign($rocket->getDestinationOrigin(), $rocket->getParams());
      › 
      arguments: {
        $message: GuzzleHttp\Psr7\Response {#600 …}
        $params: array:3 [ …3]
      }
    }
 ……
yansongda commented 2 years ago

mch_public_cert_path 这个是你商户公钥吧,不是 微信支付的 公钥吧

你配置错了

所以验签失败了

linshunwei commented 2 years ago

这两个参数对应的 mch_secret_cert 对应的是v2版的 'cert_client' => './cert/apiclient_cert.pem', mch_public_cert_path 对应的是v2版的 'cert_key' => './cert/apiclient_key.pem',

是通过 https://kf.qq.com/faq/161222NneAJf161222U7fARv.html 这个文档获取的密钥和公钥

yansongda commented 2 years ago

wechat_public_cert_path 微信支付公钥 配置错了

linshunwei commented 2 years ago

wechat_public_cert_path 这个公钥匙根据 https://github.com/wechatpay-apiv3/wechatpay-php/blob/main/bin/README.md 这个生成的证书文件

通过 ./bin/CertificateDownloader.php -k FD***B52 -m 1602118085 -f ./apiclient_key.pem(同mch_secret_cert) -s 38xx141(api证书序列号) -o ./ 生成 Serial Number: 7E8ExxxB28 的平台证书 /xxx/storage/files/pem/mch_public_cert_path.pem

linshunwei commented 2 years ago

感谢 可以了,参数都没问题,我这边自己的问题

hubs commented 1 year ago

感谢 可以了,参数都没问题,我这边自己的问题

请问是怎么处理的?我也遇到这问题了。。

linshunwei commented 1 year ago

感谢 可以了,参数都没问题,我这边自己的问题

请问是怎么处理的?我也遇到这问题了。。

我只是密钥地址配置错了 参数对 能用

carefreezi commented 1 year ago

我也遇到这个问题 麻烦请问下是不是必须配置wechat_public_cert_path

linshunwei commented 1 year ago

我也遇到这个问题 麻烦请问下是不是必须配置wechat_public_cert_path

是的 这个生成的证书编号:路径

linshunwei commented 1 year ago

感谢 可以了,参数都没问题,我这边自己的问题

请问是怎么处理的?我也遇到这问题了。。

我是自己参数设置错了