@@ -42,8 +42,9 @@ class PayController extends ControllerBase | |||||
$out_trade_no = $args["out_trade_no"] ?? ""; | $out_trade_no = $args["out_trade_no"] ?? ""; | ||||
$subject = $args["subject"] ?? ""; | $subject = $args["subject"] ?? ""; | ||||
$app_auth_token = $args["app_auth_token"] ?? ""; | $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" => [ | $this->logger(["config" => $config, "args" => [ | ||||
"op_app_id" => $op_app_id, | "op_app_id" => $op_app_id, | ||||
@@ -35,54 +35,42 @@ class CallBackController extends \Phalcon\Mvc\Controller | |||||
{ | { | ||||
if ($this->request->isPost()) { | if ($this->request->isPost()) { | ||||
try { | try { | ||||
$verify_result = (new EasyAlipayService())->verifyNotify($_POST); | |||||
logger(json_encode([ | logger(json_encode([ | ||||
"msg" => "异步回调", | "msg" => "异步回调", | ||||
"data" => $_POST, | "data" => $_POST, | ||||
"res" => $verify_result | |||||
], 320), 'common_alipay_sync_notify', true); | ], 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([ | logger(json_encode([ | ||||
"msg" => "异步回调驗證失败", | |||||
"msg" => "异步回调失败-訂單未查到", | |||||
"data" => $_POST, | "data" => $_POST, | ||||
], 320), 'alipay_sync_notify_verify_fail', true); | |||||
], 320), 'common_alipay_sync_notify_not_find', true); | |||||
//验证失败 | //验证失败 | ||||
echo "fail"; | echo "fail"; | ||||
die(); | 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) { | } catch (\Exception $e) { | ||||
logger(json_encode([ | logger(json_encode([ | ||||
"msg" => "异步回调處理异常", | "msg" => "异步回调處理异常", | ||||
@@ -117,7 +117,7 @@ class AlipayService extends BaseService | |||||
* @param string $auth_token 用户授权令牌,同 access_token(用户访问令牌)。针对用户授权接口,获取用户相关数据时,用于标识用户授权关系。需使用 auth_code(用户授权码)换取此令牌 | * @param string $auth_token 用户授权令牌,同 access_token(用户访问令牌)。针对用户授权接口,获取用户相关数据时,用于标识用户授权关系。需使用 auth_code(用户授权码)换取此令牌 | ||||
* @param string $app_auth_token 应用授权(详见应用授权概述https://opendocs.alipay.com/isv/10467/xldcyq) | * @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["subject"] = $subject; | ||||
$params["out_trade_no"] = $out_trade_no; | $params["out_trade_no"] = $out_trade_no; | ||||
@@ -128,6 +128,9 @@ class AlipayService extends BaseService | |||||
$params["timeout_express"] = "10m"; | $params["timeout_express"] = "10m"; | ||||
$request = new \AlipayTradeCreateRequest(); | $request = new \AlipayTradeCreateRequest(); | ||||
if (!empty($notify_url)) { | |||||
$request->setNotifyUrl($notify_url); | |||||
} | |||||
$paramsJson = json_encode($params); | $paramsJson = json_encode($params); | ||||
$request->setBizContent($paramsJson); | $request->setBizContent($paramsJson); | ||||
$response = self::$aopClient->execute($request, null, $app_auth_token); | $response = self::$aopClient->execute($request, null, $app_auth_token); | ||||