From 708b920d3353b92be14e0a4c6c9bb97c12e28cfa Mon Sep 17 00:00:00 2001 From: DengBiao <2319963317@qq.com> Date: Thu, 21 Sep 2023 14:19:05 +0800 Subject: [PATCH] update --- .../app/controllers/Alipay/PayController.php | 3 +- .../app/controllers/CallBackController.php | 62 ++++++++----------- src/common/Service/Pay/AlipayService.php | 5 +- 3 files changed, 31 insertions(+), 39 deletions(-) diff --git a/src/applet/app/controllers/Alipay/PayController.php b/src/applet/app/controllers/Alipay/PayController.php index a6e9705..1c4ca5d 100644 --- a/src/applet/app/controllers/Alipay/PayController.php +++ b/src/applet/app/controllers/Alipay/PayController.php @@ -42,8 +42,9 @@ class PayController extends ControllerBase $out_trade_no = $args["out_trade_no"] ?? ""; $subject = $args["subject"] ?? ""; $app_auth_token = $args["app_auth_token"] ?? ""; + $notify_url = $args["notify_url"] ?? ""; - $result = (new AlipayService($config))->alipayTradeCreateRequest($op_app_id, $subject, $out_trade_no, $total_amount, $buyer_id, $app_auth_token); + $result = (new AlipayService($config))->alipayTradeCreateRequest($op_app_id, $subject, $out_trade_no, $total_amount, $buyer_id, $app_auth_token, $notify_url); $this->logger(["config" => $config, "args" => [ "op_app_id" => $op_app_id, diff --git a/src/applet/app/controllers/CallBackController.php b/src/applet/app/controllers/CallBackController.php index 8aef523..22be15c 100644 --- a/src/applet/app/controllers/CallBackController.php +++ b/src/applet/app/controllers/CallBackController.php @@ -35,54 +35,42 @@ class CallBackController extends \Phalcon\Mvc\Controller { if ($this->request->isPost()) { try { - $verify_result = (new EasyAlipayService())->verifyNotify($_POST); logger(json_encode([ "msg" => "异步回调", "data" => $_POST, - "res" => $verify_result ], 320), 'common_alipay_sync_notify', true); - if ($verify_result) {//验证成功 - $self_order_sn = $_POST['out_trade_no']; //商家业务订单号 - $trade_no = $_POST['trade_no']; //支付宝交易号 - $trade_status = $_POST['trade_status']; //交易状态 + $self_order_sn = $_POST['out_trade_no']; //商家业务订单号 + $trade_no = $_POST['trade_no']; //支付宝交易号 + $trade_status = $_POST['trade_status']; //交易状态 - //判断该笔订单是否在 - $model = UserMerchantOrder::findFirst("self_trade_no = '{$self_order_sn}'"); - if (!$model) { - //未查到訂單 - logger(json_encode([ - "msg" => "异步回调失败-訂單未查到", - "data" => $_POST, - ], 320), 'common_alipay_sync_notify_not_find', true); - //验证失败 - echo "fail"; - die(); - } - //商户网站中已经做过处理 - if ($model->status != IPay::PAY_STATE_FOR_WAIT) { - logger(json_encode([ - "msg" => "异步回调已处理", - "data" => $_POST, - ], 320), 'alipay_sync_notify_already', true); - echo "success"; - die(); - } - - $model->return_data = json_encode($_POST); - $model->trade_no = $trade_no; - $model->updated_at = date("Y-m-d H:i:s"); - - echo "success"; - die(); - } else { + //判断该笔订单是否在 + $model = UserMerchantOrder::findFirst("self_trade_no = '{$self_order_sn}'"); + if (!$model) { + //未查到訂單 logger(json_encode([ - "msg" => "异步回调驗證失败", + "msg" => "异步回调失败-訂單未查到", "data" => $_POST, - ], 320), 'alipay_sync_notify_verify_fail', true); + ], 320), 'common_alipay_sync_notify_not_find', true); //验证失败 echo "fail"; die(); } + //商户网站中已经做过处理 + if ($model->status != IPay::PAY_STATE_FOR_WAIT) { + logger(json_encode([ + "msg" => "异步回调已处理", + "data" => $_POST, + ], 320), 'alipay_sync_notify_already', true); + echo "success"; + die(); + } + + $model->return_data = json_encode($_POST); + $model->trade_no = $trade_no; + $model->updated_at = date("Y-m-d H:i:s"); + + echo "success"; + die(); } catch (\Exception $e) { logger(json_encode([ "msg" => "异步回调處理异常", diff --git a/src/common/Service/Pay/AlipayService.php b/src/common/Service/Pay/AlipayService.php index 62305df..e432965 100644 --- a/src/common/Service/Pay/AlipayService.php +++ b/src/common/Service/Pay/AlipayService.php @@ -117,7 +117,7 @@ class AlipayService extends BaseService * @param string $auth_token 用户授权令牌,同 access_token(用户访问令牌)。针对用户授权接口,获取用户相关数据时,用于标识用户授权关系。需使用 auth_code(用户授权码)换取此令牌 * @param string $app_auth_token 应用授权(详见应用授权概述https://opendocs.alipay.com/isv/10467/xldcyq) */ - public function alipayTradeCreateRequest($op_app_id, $subject, $out_trade_no, $total_amount, $buyer_id, $app_auth_token) + public function alipayTradeCreateRequest($op_app_id, $subject, $out_trade_no, $total_amount, $buyer_id, $app_auth_token, $notify_url = "") { $params["subject"] = $subject; $params["out_trade_no"] = $out_trade_no; @@ -128,6 +128,9 @@ class AlipayService extends BaseService $params["timeout_express"] = "10m"; $request = new \AlipayTradeCreateRequest(); + if (!empty($notify_url)) { + $request->setNotifyUrl($notify_url); + } $paramsJson = json_encode($params); $request->setBizContent($paramsJson); $response = self::$aopClient->execute($request, null, $app_auth_token);