|
@@ -19,28 +19,35 @@ class Payment
|
|
|
function __construct()
|
|
|
{
|
|
|
// 从本地文件中加载「商户API私钥」,「商户API私钥」会用来生成请求的签名
|
|
|
- $merchantPrivateKeyFilePath = Config('wechat.pay.key');
|
|
|
+ //$merchantPrivateKeyFilePath = Config('wechatpay.private_key');
|
|
|
+ $merchantPrivateKeyFilePath = 'file://D:\phpstudy_pro\WWW\mall\kailin\resources\1612111355_20241118_cert\apiclient_key.pem';
|
|
|
$merchantPrivateKeyInstance = Rsa::from($merchantPrivateKeyFilePath, Rsa::KEY_TYPE_PRIVATE);
|
|
|
+
|
|
|
// 「商户API证书」的「证书序列号」
|
|
|
- // 从本地文件中加载「微信支付平台证书」,用来验证微信支付应答的签名
|
|
|
- $platformCertificateFilePath = Config('wechat.platformCertificate');
|
|
|
- $platformPublicKeyInstance = Rsa::from($platformCertificateFilePath, Rsa::KEY_TYPE_PUBLIC);
|
|
|
- // 从「微信支付平台证书」中获取「证书序列号」
|
|
|
- $platformCertificateSerial = PemUtil::parseCertificateSerialNo($platformCertificateFilePath);
|
|
|
+ $merchantCertificateSerial = '4A5F7CFCC3280CF8C09735D5FC2DEFBC9CCD6F46';
|
|
|
+
|
|
|
+ // 从本地文件中加载「微信支付平台证书」或者「微信支付平台公钥」,用来验证微信支付应答的签名
|
|
|
+ $platformCertificateOrPublicKeyFilePath = Config('wechatpay.platformCertificate');
|
|
|
+ $platformPublicKeyInstance = Rsa::from($platformCertificateOrPublicKeyFilePath, Rsa::KEY_TYPE_PUBLIC);
|
|
|
+
|
|
|
+ // 「微信支付平台证书」的「证书序列号」或者是「微信支付平台公钥ID」
|
|
|
+ // 「平台证书序列号」及/或「平台公钥ID」可以从 商户平台 -> 账户中心 -> API安全 直接查询到
|
|
|
+ $platformCertificateSerialOrPublicKeyId = 'PUB_KEY_ID_0116121113552024111800218500000334';
|
|
|
+
|
|
|
// 构造一个 APIv3 客户端实例
|
|
|
$instance = Builder::factory([
|
|
|
- 'mchid' => Config('wechat.pay.mch_id'),
|
|
|
- 'serial' => Config('wechat.pay.certificate'),
|
|
|
+ 'mchid' => Config('wechatpay.mchid'),
|
|
|
+ 'serial' => $merchantCertificateSerial,
|
|
|
'privateKey' => $merchantPrivateKeyInstance,
|
|
|
'certs' => [
|
|
|
- $platformCertificateSerial => $platformPublicKeyInstance,
|
|
|
+ $platformCertificateSerialOrPublicKeyId => $platformPublicKeyInstance,
|
|
|
],
|
|
|
]);
|
|
|
$this->instance = $instance;
|
|
|
- $this->appid = Config('wechat.pay.appid');
|
|
|
- $this->mchid = Config('wechat.pay.mch_id');
|
|
|
+ $this->appid = Config('wechatpay.appid');
|
|
|
+ $this->mchid = Config('wechatpay.mchid');
|
|
|
$this->merchantPrivateKeyInstance = $merchantPrivateKeyInstance;
|
|
|
- $this->merchantCertificateSerial = Config('wechat.pay.certificate');
|
|
|
+ $this->merchantCertificateSerial = Config('wechat.certificate');
|
|
|
return;
|
|
|
}
|
|
|
/**
|
|
@@ -48,21 +55,21 @@ class Payment
|
|
|
*/
|
|
|
public function pay($params)
|
|
|
{
|
|
|
- $notify_url = Config('wechat.pay.notify_url');
|
|
|
-
|
|
|
+ $notify_url = Config('wechatpay.notify_url');
|
|
|
//调用微信JSAPI下单获取预支付交易会话标识
|
|
|
- try {
|
|
|
+ //try {
|
|
|
$resp = $this->instance
|
|
|
->chain('v3/pay/transactions/jsapi')
|
|
|
->post(['json' => [
|
|
|
'mchid' => $this->mchid,
|
|
|
- 'out_trade_no' => $params['out_trade_no'],
|
|
|
+ 'out_trade_no' => (string)$params['out_trade_no'],
|
|
|
'appid' => $this->appid,
|
|
|
'description' => $params['description'],
|
|
|
- 'time_expire' => $this->timestampToRfc3339(time() + env('ORDER_OUT_TIME')*60),
|
|
|
- 'notify_url' => $notify_url,
|
|
|
+ /*'time_expire' => $this->timestampToRfc3339(time() + env('ORDER_OUT_TIME')*60),*/
|
|
|
+ 'notify_url' => env('APP_URL').'/api/wechat_pay/notify',
|
|
|
'amount' => [
|
|
|
- 'total' => $params['total_price'],
|
|
|
+ 'total' => 1,
|
|
|
+ //'total' => $params['total_price'],
|
|
|
'currency' => 'CNY'
|
|
|
],
|
|
|
'payer' => [
|
|
@@ -71,14 +78,14 @@ class Payment
|
|
|
]]);
|
|
|
$result = json_decode($resp->getBody(),true);
|
|
|
$prepay_id = $result['prepay_id'];
|
|
|
- } catch (\Exception $e) {
|
|
|
+ /*} catch (\Exception $e) {
|
|
|
if ($e instanceof \GuzzleHttp\Exception\RequestException && $e->hasResponse()) {
|
|
|
$r = $e->getResponse();
|
|
|
// 记录错误信息
|
|
|
Log::error('wechat/Payment','拉起小程序支付,出现错误'.$r->getBody().'参数'.json_encode($params));
|
|
|
}
|
|
|
return response()->json(['error' => '拉起支付失败'], 500);
|
|
|
- }
|
|
|
+ }*/
|
|
|
//根据返回的预支付交易会话标识,组装调起小程序支付参数
|
|
|
$data = [
|
|
|
'appId' => $this->appid,
|
|
@@ -90,7 +97,7 @@ class Payment
|
|
|
Formatter::joinedByLineFeed(...array_values($data)),
|
|
|
$this->merchantPrivateKeyInstance
|
|
|
), 'signType' => 'RSA'];
|
|
|
- return response()->json($data);
|
|
|
+ return json_send(['code'=>'success','msg'=>'成功','data'=>$data]);
|
|
|
}
|
|
|
|
|
|
//查询订单
|