diff --git a/app/api/controller/PayController.php b/app/api/controller/PayController.php index 5cf4e8e84..5bc88bf6c 100755 --- a/app/api/controller/PayController.php +++ b/app/api/controller/PayController.php @@ -16,8 +16,11 @@ namespace app\api\controller; use app\api\validate\PayValidate; +use app\common\enum\PayEnum; use app\common\enum\user\UserTerminalEnum; use app\common\logic\PaymentLogic; +use app\common\logic\PayRequestLogic; +use app\common\model\Company; use app\common\service\pay\WeChatPayService; use think\facade\Log; @@ -62,9 +65,19 @@ class PayController extends BaseApiController if (false === $order) { return $this->fail(PaymentLogic::getError(), $params); } - //支付流程 - $redirectUrl = $params['redirect'] ?? '/pages/payment/payment'; - $result = PaymentLogic::pay($params['pay_way'], $params['from'], $order, $this->userInfo['terminal'], $redirectUrl); + // 请求支付系统 + $companyInfo = Company::where(['company_id' => $this->userInfo['company_id']])->find(); + $requestData = [ + 'street' => $companyInfo['street'], + 'order_from' => 12, + 'order_type' => 101, + 'pay_user_role' => $this->userInfo['group_id'], + 'pay_user_info' => $this->userInfo, + 'business_order_no' => $order['order_no'], + 'total_fee' => $order['order_amount'], + 'business_callback_url' => (string)url('pay/notifyApp', [], false, true) + ]; + $result = PayRequestLogic::getPrePayId($requestData); if (false === $result) { return $this->fail(PaymentLogic::getError(), $params); } @@ -132,7 +145,8 @@ class PayController extends BaseApiController */ public function notifyApp() { - return (new WeChatPayService(UserTerminalEnum::ANDROID))->notify(); + $param = $this->request->param(); + return (new WeChatPayService(UserTerminalEnum::ANDROID))->notify($param); } diff --git a/app/common/logic/PayRequestLogic.php b/app/common/logic/PayRequestLogic.php new file mode 100644 index 000000000..b95f4b502 --- /dev/null +++ b/app/common/logic/PayRequestLogic.php @@ -0,0 +1,21 @@ +request('POST', env('url.pay_prefix'). '/api/wechat_pay_service_merchant_pay/appPrePay', [ + 'body' => $param + ]); + return json_decode($requestResponse->getContent(), true); + } catch (Exception $e) { + self::setError($e->getMessage()); + return false; + } + } +} \ No newline at end of file diff --git a/app/common/service/pay/WeChatPayService.php b/app/common/service/pay/WeChatPayService.php index e695208cc..511c134c0 100755 --- a/app/common/service/pay/WeChatPayService.php +++ b/app/common/service/pay/WeChatPayService.php @@ -362,35 +362,36 @@ class WeChatPayService extends BasePayService * @author 段誉 * @date 2023/2/28 14:20 */ - public function notify() + public function notify($param) { - $server = $this->app->getServer(); - // 支付通知 - $server->handlePaid(function (Message $message) { - $data = ['trade_state' => $message['trade_state'] ?? '', 'out_trade_no' => $message['out_trade_no'] ?? '', 'transaction_id' => $message['transaction_id'] ?? '', 'attach' => $message['attach'] ?? '']; - Log::info('wechat pay notify: ' . var_export($data, true)); - if ($message['trade_state'] === 'SUCCESS') { - $extra['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; - } - } - return true; - }); - - // 退款通知 - $server->handleRefunded(function (Message $message) { - return true; - }); - return $server->serve(); + Log::info(['支付回调', $param]); +// $server = $this->app->getServer(); +// // 支付通知 +// $server->handlePaid(function (Message $message) { +// $data = ['trade_state' => $message['trade_state'] ?? '', 'out_trade_no' => $message['out_trade_no'] ?? '', 'transaction_id' => $message['transaction_id'] ?? '', 'attach' => $message['attach'] ?? '']; +// Log::info('wechat pay notify: ' . var_export($data, true)); +// if ($message['trade_state'] === 'SUCCESS') { +// $extra['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; +// } +// } +// return true; +// }); +// +// // 退款通知 +// $server->handleRefunded(function (Message $message) { +// return true; +// }); +// return $server->serve(); } public function configForPayment($prepayId, $appId)