收藏
回答

wechatpay-php 报错Cannot load privateKey from

wechatpay-php 报错

Rsa::from 报错  Cannot load privateKey from(string), please take care about the \$thing input


/**
 * 构建一个客户端实例
 * wechatpay-php
 */
public static function instanceWeChatPay()
{
    // 商户号
    $merchantId = WeChat::$merchantId;
    // 从本地文件中加载商户API私钥,商户API私钥会用来生成请求的签名

    //dd(WeChat::$merchantPrivateKeyFilePath); 路径
    //"D:\web\3boat\storage\cert\wechat\4C1BBE189365B735FF1B7AE9A63EDCB7CDA49093\apiclient_key.pem"
    $merchantPrivateKeyInstance = Rsa::from(WeChat::$merchantPrivateKeyFilePath, Rsa::KEY_TYPE_PRIVATE);
    dd($merchantPrivateKeyInstance);
    // 商户API证书序列号
    $merchantCertificateSerial = WeChat::$merchantCertificateSerial;

    // 从本地文件中加载微信支付平台证书,用来验证微信支付应答的签名
    $platformPublicKeyInstance = Rsa::from(WeChat::$platformCertificateFilePath, Rsa::KEY_TYPE_PUBLIC);
    // 获取微信支付平台证书序列号
    $platformCertificateSerial = PemUtil::parseCertificateSerialNo(WeChat::$platformCertificateFilePath);

    // 构造一个 APIv3 客户端实例
    WeChat::$instance = Builder::factory([
        'mchid'      => $merchantId,
        'serial'     => $merchantCertificateSerial,
        'privateKey' => $merchantPrivateKeyInstance,
        'certs'      => [
            $platformCertificateSerial => $platformPublicKeyInstance,
        ],
    ]);

}



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

3 个回答

  • 北望沣渭
    北望沣渭
    发表于移动端
    2021-12-27
    两种处理方式: 1. file://D:\... 协议file://不能少(你少了); 2. file_get_content('d:\....'); (不推荐)
    2021-12-27
    有用 3
    回复 7
    • 浅默枫溯
      浅默枫溯
      2022-02-22
      大佬您好,想问一下,使用微信平台证书报错"Cannot load publicKey from(string)"  如果使用商户证书提示"The `certs(***)` contains the merchant's certificate serial number(***) which is not allowed here." 是微信平台证书不对吗?
      2022-02-22
      回复
    • 北望沣渭
      北望沣渭
      2022-02-22回复浅默枫溯
      记事本打开 … cert.pem,看下是不是——BEGIN——开头的文件
      2022-02-22
      回复
    • 浅默枫溯
      浅默枫溯
      2022-02-22回复北望沣渭
      开始是没有的 加了后还是Cannot load publicKey from(string),证书根据https://wechatpay-api.gitbook.io/wechatpay-api-v3/jie-kou-wen-dang/ping-tai-zheng-shu这个文档弄的 先生成待解密信息 然后进行解密得到证书信息复制内容,手动创建的文件
      2022-02-22
      回复
    • for ya
      for ya
      2022-06-24回复北望沣渭
      请问 获取平台证书的时候返回的数据怎么解析出来?
      2022-06-24
      回复
    • for ya
      for ya
      2022-06-24回复北望沣渭
      2022-06-24
      回复
    查看更多(2)
  • Hello,world!
    Hello,world!
    2023-01-27

    真是没有对比没有伤害,支付宝简单多了

    2023-01-27
    有用
    回复
  • 雅彤
    雅彤
    2021-12-30

    谢谢,大佬

    2021-12-30
    有用
    回复
登录 后发表内容