From eacdc1f9a524fa2b7ee1f7d0cb4f492febabdf29 Mon Sep 17 00:00:00 2001 From: chenbo <709206448@qq.com> Date: Thu, 16 Nov 2023 14:04:58 +0800 Subject: [PATCH] =?UTF-8?q?debug=20=E6=94=AF=E4=BB=98=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../logic/setting/pay/PayConfigLogic.php | 2 +- .../WechatPayServiceMerchantPayController.php | 5 ++- .../service/pay/WeChatPayMerchantService.php | 45 +++++++++---------- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/app/adminapi/logic/setting/pay/PayConfigLogic.php b/app/adminapi/logic/setting/pay/PayConfigLogic.php index 468ccdf..53f6cee 100644 --- a/app/adminapi/logic/setting/pay/PayConfigLogic.php +++ b/app/adminapi/logic/setting/pay/PayConfigLogic.php @@ -46,7 +46,7 @@ class PayConfigLogic extends BaseLogic $config = [ 'interface_version' => $params['config']['interface_version'], 'merchant_type' => $params['config']['merchant_type'], - 'appid' => $params['config']['app_id'], + 'app_id' => $params['config']['app_id'], 'mch_id' => $params['config']['mch_id'], 'pay_sign_key' => $params['config']['pay_sign_key'], 'apiclient_cert' => $params['config']['apiclient_cert'], diff --git a/app/api/controller/WechatPayServiceMerchantPayController.php b/app/api/controller/WechatPayServiceMerchantPayController.php index 67d4c74..28a573b 100644 --- a/app/api/controller/WechatPayServiceMerchantPayController.php +++ b/app/api/controller/WechatPayServiceMerchantPayController.php @@ -11,6 +11,7 @@ use app\common\service\pay\WeChatPayService; class WechatPayServiceMerchantPayController extends BaseApiController { + public array $notNeedLogin = ['appPrePay']; /** * 微信服务商APP支付 */ @@ -23,9 +24,9 @@ class WechatPayServiceMerchantPayController extends BaseApiController return $this->fail('支付订单创建失败', $params); } //支付流程 - $result = WeChatPayMerchantService::wechatPayServiceMerchantAppPay($order); + $result = (new WeChatPayMerchantService())->wechatPayServiceMerchantAppPay($order); if (false === $result) { - return $this->fail(WeChatPayMerchantService::getError(), $params); + return $this->fail((new WeChatPayMerchantService())->getError(), $params); } return $this->success('', $result); } diff --git a/app/common/service/pay/WeChatPayMerchantService.php b/app/common/service/pay/WeChatPayMerchantService.php index 260ead8..41f150a 100644 --- a/app/common/service/pay/WeChatPayMerchantService.php +++ b/app/common/service/pay/WeChatPayMerchantService.php @@ -20,12 +20,14 @@ use app\common\enum\PayEnum; use app\common\enum\PayOrderEnum; use app\common\enum\user\UserTerminalEnum; use app\common\logic\PayNotifyLogic; +use app\common\model\pay\PayConfig; use app\common\model\recharge\RechargeOrder; use app\common\model\user\UserAuth; use app\common\service\wechat\WeChatConfigService; use app\common\service\wechat\WeChatPayMerchantConfigService; use EasyWeChat\Pay\Application; use EasyWeChat\Pay\Message; +use think\Log; /** @@ -74,29 +76,32 @@ class WeChatPayMerchantService extends BasePayService public function wechatPayServiceMerchantAppPay($order) { - try { - $response = $this->app->getClient()->postJson('pay/unifiedorder', [ - 'appid' => $this->config['app_id'], - 'mchid' => $this->config['mch_id'], - 'sub_mch_id' => $order['sub_mch_id'], +// try { + $pay = PayConfig::where(['pay_way' => PayEnum::WECHAT_PAY])->findOrEmpty()->toArray(); + $client = $this->app->getClient(); + $response = $client->postXml('pay/unifiedorder', [ + 'appid' => $pay['config']['app_id'], + 'mch_id' => $this->config['mch_id'], + 'sub_mch_id' => $order['collection_account'], 'description' => PayOrderEnum::getPayOrderTypeDesc($order['order_type']), 'out_trade_no' => $order['order_no'], 'notify_url' => $this->config['notify_url'], 'total_fee' => $order['total_fee'], 'spbill_create_ip' => $_SERVER['SERVER_ADDR'], // 调用微信支付API的机器IP - 'time_start' => date('YmdHis', $order['create_time']), + 'time_start' => date('YmdHis', intval($order['create_time'])), 'trade_type' => 'APP', - 'attach' => $order['order_no'] + 'attach' => $order['order_no'], + 'body' => PayOrderEnum::getPayOrderTypeDesc($order['order_type']).'订单' ]); - $result = $response->toArray(false); + $result = $response->toArray(false);dd($result); $this->checkResultFail($result); $re = $this->app->getUtils()->buildAppConfig($result['prepay_id'], $this->config['appid']); $re['partnerid'] = $order['sub_mch_id']; return $re; - } catch (\Exception $e) { - $this->setError($e->getMessage()); - return false; - } +// } catch (\Exception $e) { +// $this->setError($e->getMessage()); +// return false; +// } } @@ -188,25 +193,19 @@ class WeChatPayMerchantService extends BasePayService $server = $this->app->getServer(); // 支付通知 $server->handlePaid(function (Message $message) { + Log::info(['支付回调信息', $message]); if ($message['trade_state'] === 'SUCCESS') { - $extra['transaction_id'] = $message['transaction_id']; + $transaction_id = $message['transaction_id']; $attach = $message['attach']; - $message['out_trade_no'] = mb_substr($message['out_trade_no'], 0, 18); - switch ($attach) { - case 'recharge': - $order = RechargeOrder::where(['sn' => $message['out_trade_no']])->findOrEmpty(); - if($order->isEmpty() || $order->pay_status == PayEnum::ISPAID) { - return true; - } - PayNotifyLogic::handle('recharge', $message['out_trade_no'], $extra); - break; - } + $out_trade_no = $message['out_trade_no']; + } return true; }); // 退款通知 $server->handleRefunded(function (Message $message) { + Log::info(['退款回调信息', $message]); return true; }); return $server->serve();