|
@@ -2,8 +2,11 @@
|
|
|
|
|
|
namespace app\admin\controller;
|
|
|
|
|
|
-
|
|
|
use payment\wechat\WechatTransfers;
|
|
|
+use WeChatPay\Builder;
|
|
|
+use WeChatPay\Crypto\Rsa;
|
|
|
+use WeChatPay\Transformer;
|
|
|
+use WeChatPay\Util\PemUtil;
|
|
|
|
|
|
class Index
|
|
|
{
|
|
@@ -13,9 +16,46 @@ class Index
|
|
|
}
|
|
|
|
|
|
public function t1()
|
|
|
+ {
|
|
|
+ // 商户号
|
|
|
+ $merchantId = config('wxconfig.payMchId');
|
|
|
+
|
|
|
+// 从本地文件中加载「商户API私钥」,「商户API私钥」会用来生成请求的签名
|
|
|
+ $merchantPrivateKeyFilePath = file_get_contents(root_path('/extend/payment/cert') . 'apiclient_key.pem');
|
|
|
+ $merchantPrivateKeyInstance = Rsa::from($merchantPrivateKeyFilePath, Rsa::KEY_TYPE_PRIVATE);
|
|
|
+
|
|
|
+// 「商户API证书」的「证书序列号」
|
|
|
+ $merchantCertificateSerial = config('wxconfig.serial');
|
|
|
+
|
|
|
+// 从本地文件中加载「微信支付平台证书」,用来验证微信支付应答的签名
|
|
|
+ $platformCertificateFilePath = file_get_contents(root_path('/extend/payment/cert') . 'apiclient_cert.pem');
|
|
|
+ $platformPublicKeyInstance = Rsa::from($platformCertificateFilePath, Rsa::KEY_TYPE_PUBLIC);
|
|
|
+
|
|
|
+// 从「微信支付平台证书」中获取「证书序列号」
|
|
|
+ $platformCertificateSerial = PemUtil::parseCertificateSerialNo($platformCertificateFilePath);
|
|
|
+
|
|
|
+// 构造一个 APIv3 客户端实例
|
|
|
+ $instance = Builder::factory([
|
|
|
+ 'mchid' => $merchantId,
|
|
|
+ 'serial' => $merchantCertificateSerial,
|
|
|
+ 'privateKey' => $merchantPrivateKeyInstance,
|
|
|
+ 'certs' => [
|
|
|
+ $platformCertificateSerial => $platformPublicKeyInstance,
|
|
|
+ ],
|
|
|
+ ]);
|
|
|
+
|
|
|
+// 发送请求
|
|
|
+ $resp = $instance->chain('v3/certificates')->get(
|
|
|
+ ['debug' => true] // 调试模式,https://docs.guzzlephp.org/en/stable/request-options.html#debug
|
|
|
+ );
|
|
|
+ halt($resp->getBody());
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public function t2()
|
|
|
{
|
|
|
$server = new WechatTransfers(config('wxconfig.appId'),config('wxconfig.payMchId'),config('wxconfig.appSecret'),$_SERVER['SERVER_ADDR']);
|
|
|
$res = $server->sendMoney(1,'o4a9g5cDIEVzS7zVzE-_VEK8y9Yg');
|
|
|
halt($res);
|
|
|
}
|
|
|
-}
|
|
|
+}
|