扫描小程序码分享
微信支付 新申请的商户号只能用 微信支付公钥了,平台证书不能用了。支付时如何使用微信支付公钥呢?有参考代码吗?php的参考代码
2 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
微信SDK已支持公钥方案,详情请了解下文档https://github.com/wechatpay-apiv3/wechatpay-php
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
请按照你的商户号所能接入的方式选择对应实例化客户端
require_once('vendor/autoload.php'); use WeChatPay\Builder; use WeChatPay\Crypto\Rsa; // 商户号 $merchantId = '190000****'; // 从本地文件中加载「商户API私钥」,用于生成请求的签名 $merchantPrivateKeyFilePath = 'file:///path/to/merchant/apiclient_key.pem'; $merchantPrivateKeyInstance = Rsa::from($merchantPrivateKeyFilePath, Rsa::KEY_TYPE_PRIVATE); // 「商户API证书」的「证书序列号」 $merchantCertificateSerial = '3775B6A45ACD588826D15E583A95F5DD********'; // 从本地文件中加载「微信支付公钥」,用来验证微信支付应答的签名 $platformPublicKeyFilePath = 'file:///path/to/wechatpay/publickey.pem'; $platformPublicKeyInstance = Rsa::from($platformPublicKeyFilePath, Rsa::KEY_TYPE_PUBLIC); // 「微信支付公钥」的「微信支付公钥ID」 // 需要在 商户平台 -> 账户中心 -> API安全 查询 $platformPublicKeyId = 'PUB_KEY_ID_01142321349124100000000000********'; // 构造一个 APIv3 客户端实例(微信支付公钥模式) $instance = Builder::factory([ 'mchid' => $merchantId, 'serial' => $merchantCertificateSerial, 'privateKey' => $merchantPrivateKeyInstance, 'certs' => [ $platformPublicKeyId => $platformPublicKeyInstance, ] ]);
$instance->v3->pay->transactions->native->postAsync([ 'json' => [ 'appid' => 'wxd678efh567hg6787', 'mchid' => '1230000109', 'description' => 'Image形象店-深圳腾大-QQ公仔', 'attach' => '自定义数据', 'out_trade_no' => '1217752501201407033233368018', 'amount' => [ 'total' => 100, 'currency' => 'CNY', ], 'time_expire' => '2018-06-08T10:34:56+08:00', 'notify_url' => 'https://www.weixin.qq.com/wxpay/pay.php', 'goods_tag' => 'WXG', 'limit_pay' => ['no_balance'], 'support_fapiao' => true, 'detail' => [ 'cost_price' => 608800, 'invoice_id' => '微信123', 'goods_detail' => [[ 'merchant_goods_id' => '商品编码', 'wechatpay_goods_id' => '1001', 'goods_name' => 'iPhoneX 256G', 'quantity' => 1, 'unit_price' => 828800, ],], ], 'scene_info' => [ 'payer_client_ip' => '14.23.150.211', 'device_id' => '013467007045764', 'store_info' => [ 'id' => '0001', 'name' => '腾讯大厦分店', 'area_code' => '440305', 'address' => '广东省深圳市南山区科技中一道10000号', ], ], 'payer' => [ 'identity' => [ 'type' => 'IDCARD', 'number' => '6B46824C852FA29AAC3DCE6BFD852E27', 'name' => '6B46824C852FA29AAC3DCE6BFD852E27', ], ], 'settle_info' => [ 'profit_sharing' => true, ], ], 'headers' => [ 'Wechatpay-Serial' => 'PUB_KEY_ID_0114232134912410000000000000', ], ]) ->then(static function(\Psr\Http\Message\ResponseInterface $response) { print_r(json_decode((string) $response->getBody(), true)); }) ->wait();
摘自 https://wechatpay.im/guide/getting-startedhttps://wechatpay.im/guide/getting-started
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
微信SDK已支持公钥方案,详情请了解下文档https://github.com/wechatpay-apiv3/wechatpay-php
初始化
请按照你的商户号所能接入的方式选择对应实例化客户端
require_once('vendor/autoload.php'); use WeChatPay\Builder; use WeChatPay\Crypto\Rsa; // 商户号 $merchantId = '190000****'; // 从本地文件中加载「商户API私钥」,用于生成请求的签名 $merchantPrivateKeyFilePath = 'file:///path/to/merchant/apiclient_key.pem'; $merchantPrivateKeyInstance = Rsa::from($merchantPrivateKeyFilePath, Rsa::KEY_TYPE_PRIVATE); // 「商户API证书」的「证书序列号」 $merchantCertificateSerial = '3775B6A45ACD588826D15E583A95F5DD********'; // 从本地文件中加载「微信支付公钥」,用来验证微信支付应答的签名 $platformPublicKeyFilePath = 'file:///path/to/wechatpay/publickey.pem'; $platformPublicKeyInstance = Rsa::from($platformPublicKeyFilePath, Rsa::KEY_TYPE_PUBLIC); // 「微信支付公钥」的「微信支付公钥ID」 // 需要在 商户平台 -> 账户中心 -> API安全 查询 $platformPublicKeyId = 'PUB_KEY_ID_01142321349124100000000000********'; // 构造一个 APIv3 客户端实例(微信支付公钥模式) $instance = Builder::factory([ 'mchid' => $merchantId, 'serial' => $merchantCertificateSerial, 'privateKey' => $merchantPrivateKeyInstance, 'certs' => [ $platformPublicKeyId => $platformPublicKeyInstance, ] ]);
Native下单
$instance->v3->pay->transactions->native->postAsync([ 'json' => [ 'appid' => 'wxd678efh567hg6787', 'mchid' => '1230000109', 'description' => 'Image形象店-深圳腾大-QQ公仔', 'attach' => '自定义数据', 'out_trade_no' => '1217752501201407033233368018', 'amount' => [ 'total' => 100, 'currency' => 'CNY', ], 'time_expire' => '2018-06-08T10:34:56+08:00', 'notify_url' => 'https://www.weixin.qq.com/wxpay/pay.php', 'goods_tag' => 'WXG', 'limit_pay' => ['no_balance'], 'support_fapiao' => true, 'detail' => [ 'cost_price' => 608800, 'invoice_id' => '微信123', 'goods_detail' => [[ 'merchant_goods_id' => '商品编码', 'wechatpay_goods_id' => '1001', 'goods_name' => 'iPhoneX 256G', 'quantity' => 1, 'unit_price' => 828800, ],], ], 'scene_info' => [ 'payer_client_ip' => '14.23.150.211', 'device_id' => '013467007045764', 'store_info' => [ 'id' => '0001', 'name' => '腾讯大厦分店', 'area_code' => '440305', 'address' => '广东省深圳市南山区科技中一道10000号', ], ], 'payer' => [ 'identity' => [ 'type' => 'IDCARD', 'number' => '6B46824C852FA29AAC3DCE6BFD852E27', 'name' => '6B46824C852FA29AAC3DCE6BFD852E27', ], ], 'settle_info' => [ 'profit_sharing' => true, ], ], 'headers' => [ 'Wechatpay-Serial' => 'PUB_KEY_ID_0114232134912410000000000000', ], ]) ->then(static function(\Psr\Http\Message\ResponseInterface $response) { print_r(json_decode((string) $response->getBody(), true)); }) ->wait();
摘自 https://wechatpay.im/guide/getting-startedhttps://wechatpay.im/guide/getting-started