1、微信商户后台获取 v3支付证书「证书名字前面加一个 v3_ ,便于以后区分」
2、前往证书目录,获取v3证书序列号,执行命令行:
openssl x509 -in ./v3_apiclient_cert.pem -noout -serial
3、安装依赖:
composer require wechatpay/wechatpay
4、获取微信支付平台证书:cd到根目录/vendor/wechatpay/wechatpay/bin目录,执行命令:
php -f ./CertificateDownloader.php -- -k v3支付密钥 -m 商户号 -f 密钥证书路径 -s v3商户证书的序列号 -o ./
会发现当前目录会生成一个 wechatpay_**.pem的文件,最好修改个名字方便区分,v3_wechatpay_cert.pem
5、前往shopro企业付款逻辑页面
> 根目录/addons/shopro/library/PayService.php 大概184行> public function transfer($payload)方法> case 'wechat': 里面放入以下代码
// v3版本 start$payload['amount'] = $payload['amount'] * 100;// 从本地文件中加载「商户API私钥」,「商户API私钥」会用来生成请求的签名$merchantPrivateKeyFilePath = 'file://' . ROOT_PATH . '你存放的目录' . DS . 'v3_apiclient_key.pem';$merchantPrivateKeyInstance = WeChatPayCryptoRsa::from($merchantPrivateKeyFilePath, WeChatPayCryptoRsa::KEY_TYPE_PRIVATE);// v3证书序列号$merchantCertificateSerial = '5BBF82D649A5A75****';// 从本地文件中加载「微信支付平台证书」,用来验证微信支付应答的签名$platformCertificateFilePath = 'file://' . ROOT_PATH . '你存放的目录' . DS . 'v3_wechatpay_cert.pem';;$platformPublicKeyInstance = WeChatPayCryptoRsa::from($platformCertificateFilePath, WeChatPayCryptoRsa::KEY_TYPE_PUBLIC);// 从「微信支付平台证书」中获取「证书序列号」$platformCertificateSerial = WeChatPayUtilPemUtil::parseCertificateSerialNo($platformCertificateFilePath);// 构造一个 APIv3 客户端实例$instance = WeChatPayBuilder::factory([ 'mchid' => $this->config['mch_id'], 'serial' => $merchantCertificateSerial, 'privateKey' => $merchantPrivateKeyInstance, 'certs' => [ $platformCertificateSerial => $platformPublicKeyInstance, ], 'headers' => [ 'Wechatpay-Serial' => $platformCertificateSerial ]]);// 加密敏感信息$encryptor = static function(string $msg) use ($platformPublicKeyInstance): string { return WeChatPayCryptoRsa::encrypt($msg, $platformPublicKeyInstance);};// 企业付款到零钱$response = $instance ->chain('v3/transfer/batches') ->post(['json' => [ 'appid' => $this->config['miniapp_id'], 'out_batch_no' => $payload['partner_trade_no'], 'batch_name' => date('Y-m-d H:i:s') . '用户提现', 'batch_remark' => '用户提现', // $payload['desc'] 防止用户昵称编码不对导致转账失败 'total_amount' => intval($payload['amount']), 'total_num' => 1, 'transfer_detail_list' => [ [ 'out_detail_no' => $payload['partner_trade_no'], 'transfer_amount' => intval($payload['amount']), 'transfer_remark' => '用户提现', // $payload['desc'] 防止用户昵称编码不对导致转账失败 'openid' => $payload['openid'],// 'user_name' => $encryptor('张三') // 金额超过`2000`才填写 ] ] ]]);$code = 1;// v3版本 end// 原来的// $payload['amount'] = $payload['amount'] * 100;// $response = Pay::wechat($this->config)->transfer($payload);// if ($response['return_code'] === 'SUCCESS' && $response['result_code'] === 'SUCCESS') {// $code = 1;// }
6、以上步骤即可实现提现。这些全是作者一坑一坑踩来的,如帮助到你了请点个赞
希望以上内容对你有所帮助!如果还有其他问题,请随时提问。 各类知识收集 拥有多年CMS企业建站经验,对 iCMS, Fastadmin, ClassCMS, LeCMS, PbootCMS, PHPCMS, 易优CMS, YzmCMS, 讯睿CMS, 极致CMS, Wordpress, HkCMS, YznCMS, WellCMS, ThinkCMF, 等各类cms的相互转化,程序开发,网站制作,bug修复,程序杀毒,插件定制都可以提供最佳解决方案。