|
|
@@ -1,572 +0,0 @@ |
|
|
|
<?php |
|
|
|
|
|
|
|
namespace SRVX\Api\Controllers; |
|
|
|
|
|
|
|
use App\constants\Pay as IPay; |
|
|
|
use App\constants\Common as ICommon; |
|
|
|
use SRVX\Model\MerchantAlipayAuthorize; |
|
|
|
use SRVX\Model\OwnOrder; |
|
|
|
use SRVX\Model\UserMerchantOrder; |
|
|
|
use SRVX\Msg; |
|
|
|
use SRVX\Service\Pay\AlipayService; |
|
|
|
use SRVX\Service\Pay\EasyAlipayService; |
|
|
|
use SRVX\Service\Pay\PayService; |
|
|
|
use SRVX\Service\Pay\Wx\EcommercePayService; |
|
|
|
use SRVX\Service\Pay\Wx\PayService as WxPayService; |
|
|
|
use SRVX\Traits\BasisFun; |
|
|
|
|
|
|
|
class CallBackCashBookController extends \Phalcon\Mvc\Controller |
|
|
|
{ |
|
|
|
|
|
|
|
use BasisFun; |
|
|
|
|
|
|
|
public function alipayGatewayAction() |
|
|
|
{ |
|
|
|
$args = $this->request->get(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Todo::支付宝 - 授权回调 |
|
|
|
*/ |
|
|
|
public function alipayAuthorizeCallBackAction() |
|
|
|
{ |
|
|
|
$args = $this->request->get(); |
|
|
|
$this->logger($args, 'alipay_authorize_callBack_action', true); |
|
|
|
if (empty($args['app_id']) || empty($args['app_auth_code']) || empty($args["state"])) { |
|
|
|
dd(['msg' => '缺少参数', 'success' => -1]); |
|
|
|
} |
|
|
|
$result = (new AlipayService())->alipayOpenAuthTokenAppRequest($args['app_auth_code']); |
|
|
|
if ($result["status"] != true) { |
|
|
|
dd((['msg' => '授权失败', 'success' => -2, "result" => $result])); |
|
|
|
} |
|
|
|
$app_id = explode("=", base64_decode($args["state"]))[1]; |
|
|
|
$merchant_sn = explode("=", base64_decode($args["state"]))[0]; |
|
|
|
$uid = explode("_", $merchant_sn)[0]; |
|
|
|
$model = MerchantAlipayAuthorize::findFirst("uid = '{$uid}' AND app_id = '{$app_id}' AND merchant_sn = '{$merchant_sn}'"); |
|
|
|
$model = empty($model) ? new MerchantAlipayAuthorize() : $model; |
|
|
|
$model->uid = $uid; |
|
|
|
$model->app_id = $app_id; |
|
|
|
$model->merchant_sn = $merchant_sn; |
|
|
|
$model->app_auth_token = $result["data"]["tokens"][0]["app_auth_token"]; |
|
|
|
$model->app_refresh_token = $result["data"]["tokens"][0]["app_refresh_token"]; |
|
|
|
$model->ali_app_id = $args['app_id']; |
|
|
|
$model->ali_auth_app_id = $result['data']["tokens"][0]["auth_app_id"]; |
|
|
|
$model->ali_user_id = $result["data"]["tokens"][0]["user_id"]; |
|
|
|
$model->created_at = date("Y-m-d H:i:s"); |
|
|
|
$model->updated_at = date("Y-m-d H:i:s"); |
|
|
|
$model->state = ICommon::MERCHANT_STATE_USE; |
|
|
|
$model->save(); |
|
|
|
dd((['msg' => '授权成功!', 'success' => 0])); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 本系统自身支付回调 - 同步 |
|
|
|
*/ |
|
|
|
public function alipayOwnSyncReturnAction() |
|
|
|
{ |
|
|
|
dump($_GET); |
|
|
|
$args = $this->request->get(); |
|
|
|
logger(json_encode([ |
|
|
|
"msg" => "同步回调", |
|
|
|
"data" => $args, |
|
|
|
], 320), 'alipay_sync_return', true); |
|
|
|
dd($args); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 本系统自身支付回调 - 异步 |
|
|
|
*/ |
|
|
|
public function alipayOwnSyncNotifyAction() |
|
|
|
{ |
|
|
|
if ($this->request->isPost()) { |
|
|
|
try { |
|
|
|
$verify_result = (new EasyAlipayService())->verifyNotify($_POST); |
|
|
|
logger(json_encode([ |
|
|
|
"msg" => "异步回调", |
|
|
|
"data" => $_POST, |
|
|
|
"res" => $verify_result |
|
|
|
], 320), 'alipay_sync_notify', true); |
|
|
|
if ($verify_result) {//验证成功 |
|
|
|
$out_trade_no = $_POST['out_trade_no']; |
|
|
|
//支付宝交易号 |
|
|
|
$trade_no = $_POST['trade_no']; |
|
|
|
//交易状态 |
|
|
|
$trade_status = $_POST['trade_status']; |
|
|
|
|
|
|
|
//判断该笔订单是否在 |
|
|
|
$model = OwnOrder::findFirst("out_trade_no = '{$out_trade_no}'"); |
|
|
|
if (!$model) { |
|
|
|
//未查到訂單 |
|
|
|
logger(json_encode([ |
|
|
|
"msg" => "异步回调失败-訂單未查到", |
|
|
|
"data" => $_POST, |
|
|
|
], 320), 'alipay_sync_notify_not_find', true); |
|
|
|
//验证失败 |
|
|
|
echo "fail"; |
|
|
|
die(); |
|
|
|
} |
|
|
|
$model->return_data = json_encode($_POST); |
|
|
|
$model->trade_no = $trade_no; |
|
|
|
$model->updated_at = date("Y-m-d H:i:s"); |
|
|
|
|
|
|
|
if ($trade_status == 'TRADE_FINISHED' || $trade_status == 'TRADE_SUCCESS') { |
|
|
|
//商户网站中已经做过处理 |
|
|
|
if ($model->status == IPay::PAY_STATE_FOR_ALREADY) { |
|
|
|
logger(json_encode([ |
|
|
|
"msg" => "异步回调成功", |
|
|
|
"data" => $_POST, |
|
|
|
], 320), 'alipay_sync_notify_already', true); |
|
|
|
echo "success"; |
|
|
|
die(); |
|
|
|
} |
|
|
|
$model->status = IPay::PAY_STATE_FOR_ALREADY; |
|
|
|
if ($model->save() == false) { |
|
|
|
logger(json_encode([ |
|
|
|
"msg" => "异步回调-支付成功-更新訂單失敗", |
|
|
|
"data" => $_POST, |
|
|
|
], 320), 'alipay_sync_notify_success_update_fail', true); |
|
|
|
echo "fail"; |
|
|
|
die(); |
|
|
|
} |
|
|
|
logger(json_encode([ |
|
|
|
"msg" => "异步回调支付成功", |
|
|
|
"data" => $_POST, |
|
|
|
], 320), 'alipay_sync_notify_success', true); |
|
|
|
} else { |
|
|
|
$model->status = IPay::PAY_STATE_FOR_FAIL; |
|
|
|
if ($model->save() == false) { |
|
|
|
logger(json_encode([ |
|
|
|
"msg" => "异步回调-支付失敗-更新訂單失敗", |
|
|
|
"data" => $_POST, |
|
|
|
], 320), 'alipay_sync_notify_fail_update_fail', true); |
|
|
|
echo "fail"; |
|
|
|
die(); |
|
|
|
} |
|
|
|
logger(json_encode([ |
|
|
|
"msg" => "异步回调支付失敗", |
|
|
|
"data" => $_POST, |
|
|
|
], 320), 'alipay_sync_notify_fail', true); |
|
|
|
} |
|
|
|
echo "success"; |
|
|
|
die(); |
|
|
|
} else { |
|
|
|
logger(json_encode([ |
|
|
|
"msg" => "异步回调驗證失败", |
|
|
|
"data" => $_POST, |
|
|
|
], 320), 'alipay_sync_notify_verify_fail', true); |
|
|
|
//验证失败 |
|
|
|
echo "fail"; |
|
|
|
die(); |
|
|
|
} |
|
|
|
} catch (\Exception $e) { |
|
|
|
logger(json_encode([ |
|
|
|
"msg" => "异步回调處理异常", |
|
|
|
"data" => $params ?? [], |
|
|
|
"exception" => $e->getMessage() |
|
|
|
], 320), 'alipay_sync_notify_exception', true); |
|
|
|
//回調異常 |
|
|
|
echo "fail"; |
|
|
|
die(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 支付宝 - 公共网关回调 |
|
|
|
*/ |
|
|
|
public function alipayCommonCallBackAction() |
|
|
|
{ |
|
|
|
// 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']; |
|
|
|
// //判断该笔订单是否在 |
|
|
|
// $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(); |
|
|
|
// } |
|
|
|
// $model->return_data = json_encode($_POST); |
|
|
|
// $model->trade_no = $trade_no; |
|
|
|
// $model->updated_at = date("Y-m-d H:i:s"); |
|
|
|
// |
|
|
|
// #TODO::回調第三方平台的 notify_url |
|
|
|
// $passback_params = json_decode(urldecode($_POST["passback_params"]), true); |
|
|
|
// $notify_url = $passback_params["notify_url"]; |
|
|
|
// $out_trade_no = $passback_params["out_trade_no"]; |
|
|
|
// $ext_info = $passback_params["ext_info"] ?? []; |
|
|
|
// $isOk = (new GetPlatformCertificateService())->commonCurlNotifyUrl($notify_url, ["out_trade_no" => $out_trade_no, |
|
|
|
// "trade_no" => $trade_no, |
|
|
|
// "pay_trade_no" => $self_order_sn, |
|
|
|
// "trade_status" => $trade_status, |
|
|
|
// "ext_info" => $ext_info |
|
|
|
// ]); |
|
|
|
// if ($isOk) { |
|
|
|
// if ($trade_status == 'TRADE_FINISHED' || $trade_status == 'TRADE_SUCCESS') { |
|
|
|
// //商户网站中已经做过处理 |
|
|
|
// if ($model->status == IPay::PAY_STATE_FOR_ALREADY) { |
|
|
|
// logger(json_encode([ |
|
|
|
// "msg" => "异步回调成功", |
|
|
|
// "data" => $_POST, |
|
|
|
// ], 320), 'alipay_sync_notify_already', true); |
|
|
|
// echo "success"; |
|
|
|
// die(); |
|
|
|
// } |
|
|
|
// $model->status = IPay::PAY_STATE_FOR_ALREADY; |
|
|
|
// if ($model->save() == false) { |
|
|
|
// logger(json_encode([ |
|
|
|
// "msg" => "异步回调-支付成功-更新訂單失敗", |
|
|
|
// "data" => $_POST, |
|
|
|
// ], 320), 'alipay_sync_notify_success_update_fail', true); |
|
|
|
// echo "fail"; |
|
|
|
// die(); |
|
|
|
// } |
|
|
|
// logger(json_encode([ |
|
|
|
// "msg" => "异步回调支付成功", |
|
|
|
// "data" => $_POST, |
|
|
|
// ], 320), 'alipay_sync_notify_success', true); |
|
|
|
// } else { |
|
|
|
// $model->status = IPay::PAY_STATE_FOR_FAIL; |
|
|
|
// if ($model->save() == false) { |
|
|
|
// logger(json_encode([ |
|
|
|
// "msg" => "异步回调-支付失敗-更新訂單失敗", |
|
|
|
// "data" => $_POST, |
|
|
|
// ], 320), 'alipay_sync_notify_fail_update_fail', true); |
|
|
|
// echo "fail"; |
|
|
|
// die(); |
|
|
|
// } |
|
|
|
// logger(json_encode([ |
|
|
|
// "msg" => "异步回调支付失敗", |
|
|
|
// "data" => $_POST, |
|
|
|
// ], 320), 'alipay_sync_notify_fail', true); |
|
|
|
// } |
|
|
|
// echo "success"; |
|
|
|
// die(); |
|
|
|
// } else { |
|
|
|
// logger(json_encode([ |
|
|
|
// "msg" => "异步回调 - 回調第三方平台失敗", |
|
|
|
// "data" => $_POST, |
|
|
|
// "isOk" => false |
|
|
|
// ], 320), 'alipay_sync_notify_fail', true); |
|
|
|
// echo "fail"; |
|
|
|
// die(); |
|
|
|
// } |
|
|
|
// } else { |
|
|
|
// logger(json_encode([ |
|
|
|
// "msg" => "异步回调驗證失败", |
|
|
|
// "data" => $_POST, |
|
|
|
// ], 320), 'alipay_sync_notify_verify_fail', true); |
|
|
|
// //验证失败 |
|
|
|
// echo "fail"; |
|
|
|
// die(); |
|
|
|
// } |
|
|
|
// } catch (\Exception $e) { |
|
|
|
// logger(json_encode([ |
|
|
|
// "msg" => "异步回调處理异常", |
|
|
|
// "data" => $params ?? [], |
|
|
|
// "exception" => $e->getMessage() |
|
|
|
// ], 320), 'alipay_sync_notify_exception', true); |
|
|
|
// //回調異常 |
|
|
|
// echo "fail"; |
|
|
|
// die(); |
|
|
|
// } |
|
|
|
// } |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 支付宝 - 公共异步回调 |
|
|
|
*/ |
|
|
|
public function alipayAsyncNotifyCallBackAction() |
|
|
|
{ |
|
|
|
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']; |
|
|
|
//判断该笔订单是否在 |
|
|
|
$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"); |
|
|
|
|
|
|
|
#TODO::回調第三方平台的 notify_url |
|
|
|
$passback_params = json_decode(urldecode($_POST["passback_params"]), true); |
|
|
|
$notify_url = $passback_params["notify_url"]; |
|
|
|
$out_trade_no = $passback_params["out_trade_no"]; |
|
|
|
$ext_info = $passback_params["ext_info"] ?? []; |
|
|
|
$isOk = (new PayService())->commonCurlNotifyUrl($notify_url, ["out_trade_no" => $out_trade_no, |
|
|
|
"trade_no" => $trade_no, |
|
|
|
"pay_trade_no" => $self_order_sn, |
|
|
|
"trade_status" => $trade_status, |
|
|
|
"ext_info" => $ext_info |
|
|
|
]); |
|
|
|
if ($isOk) { |
|
|
|
if ($trade_status == 'TRADE_FINISHED' || $trade_status == 'TRADE_SUCCESS') { |
|
|
|
$model->status = IPay::PAY_STATE_FOR_ALREADY; |
|
|
|
if ($model->save() == false) { |
|
|
|
logger(json_encode([ |
|
|
|
"msg" => "异步回调-支付成功-更新訂單失敗", |
|
|
|
"data" => $_POST, |
|
|
|
], 320), 'alipay_sync_notify_success_update_fail', true); |
|
|
|
echo "fail"; |
|
|
|
die(); |
|
|
|
} |
|
|
|
logger(json_encode([ |
|
|
|
"msg" => "异步回调支付成功", |
|
|
|
"data" => $_POST, |
|
|
|
], 320), 'alipay_sync_notify_success', true); |
|
|
|
} else { |
|
|
|
$model->status = IPay::PAY_STATE_FOR_FAIL; |
|
|
|
if ($model->save() == false) { |
|
|
|
logger(json_encode([ |
|
|
|
"msg" => "异步回调-支付失敗-更新訂單失敗", |
|
|
|
"data" => $_POST, |
|
|
|
], 320), 'alipay_sync_notify_fail_update_fail', true); |
|
|
|
echo "fail"; |
|
|
|
die(); |
|
|
|
} |
|
|
|
logger(json_encode([ |
|
|
|
"msg" => "异步回调支付失敗", |
|
|
|
"data" => $_POST, |
|
|
|
], 320), 'alipay_sync_notify_fail', true); |
|
|
|
} |
|
|
|
echo "success"; |
|
|
|
die(); |
|
|
|
} else { |
|
|
|
logger(json_encode([ |
|
|
|
"msg" => "异步回调 - 回調第三方平台失敗", |
|
|
|
"data" => $_POST, |
|
|
|
"isOk" => false |
|
|
|
], 320), 'alipay_sync_notify_fail', true); |
|
|
|
echo "fail"; |
|
|
|
die(); |
|
|
|
} |
|
|
|
} else { |
|
|
|
logger(json_encode([ |
|
|
|
"msg" => "异步回调驗證失败", |
|
|
|
"data" => $_POST, |
|
|
|
], 320), 'alipay_sync_notify_verify_fail', true); |
|
|
|
//验证失败 |
|
|
|
echo "fail"; |
|
|
|
die(); |
|
|
|
} |
|
|
|
} catch (\Exception $e) { |
|
|
|
logger(json_encode([ |
|
|
|
"msg" => "异步回调處理异常", |
|
|
|
"data" => $params ?? [], |
|
|
|
"exception" => $e->getMessage() |
|
|
|
], 320), 'alipay_sync_notify_exception', true); |
|
|
|
//回調異常 |
|
|
|
echo "fail"; |
|
|
|
die(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 微信 - 公共异步回调 |
|
|
|
*/ |
|
|
|
public function wxPayAsyncNotifyCallBackAction() |
|
|
|
{ |
|
|
|
try { |
|
|
|
//获取接口数据,若是$_REQUEST拿不到数据,则使用file_get_contents函数获取 |
|
|
|
$post = file_get_contents("php://input"); |
|
|
|
if ($post == null) { |
|
|
|
$post = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : ''; |
|
|
|
} |
|
|
|
$inWechatpaySignature = $_SERVER["HTTP_WECHATPAY_SIGNATURE"] ?? ""; |
|
|
|
$inWechatpayTimestamp = $_SERVER["HTTP_WECHATPAY_TIMESTAMP"] ?? ""; |
|
|
|
$inWechatpaySerial = $_SERVER["HTTP_WECHATPAY_SERIAL"] ?? ""; //暫時未用到 |
|
|
|
$inWechatpayNonce = $_SERVER["HTTP_WECHATPAY_NONCE"] ?? ""; |
|
|
|
$this->logger([ |
|
|
|
"inWechatpaySignature" => $inWechatpaySignature, |
|
|
|
"inWechatpayTimestamp" => $inWechatpayTimestamp, |
|
|
|
"inWechatpaySerial" => $inWechatpaySerial, |
|
|
|
"inWechatpayNonce" => $inWechatpayNonce, |
|
|
|
], 'wx_pay_async_notify_call_back', true); |
|
|
|
|
|
|
|
if (empty($post) || $post == null || $post == '') { |
|
|
|
$this->wxApi(Msg::WxErr); |
|
|
|
} |
|
|
|
|
|
|
|
$this->logger($post, 'wx_pay_async_notify_call_back', true); |
|
|
|
$data = (new EcommercePayService())->decryptToString($inWechatpayTimestamp, $inWechatpayNonce, $inWechatpaySignature, $post); |
|
|
|
$this->logger($data, 'wx_pay_async_notify_call_back', true); |
|
|
|
if (!empty($data)) { |
|
|
|
#TODO::以下為驗簽成功邏輯處理 |
|
|
|
/** 解析出来的数组 |
|
|
|
*Array |
|
|
|
* { |
|
|
|
* "sp_mchid":"1611682472", |
|
|
|
* "sub_mchid":"1618679040", |
|
|
|
* "sp_appid":"wx02391df091871eb7", |
|
|
|
* "sub_appid":"wx5ea1176d277eb1a9", |
|
|
|
* "out_trade_no":"949112453c0ab718164148217297094", |
|
|
|
* "transaction_id":"4200001369202201069176784818", |
|
|
|
* "trade_type":"JSAPI", |
|
|
|
* "trade_state":"SUCCESS", |
|
|
|
* "trade_state_desc":"支付成功", |
|
|
|
* "bank_type":"OTHERS", |
|
|
|
* "attach":"api.zhiyingos.com/api/v1/o2oc/customer/pay/callback", |
|
|
|
* "success_time":"2022-01-06T23:16:17+08:00", |
|
|
|
* "payer":{ |
|
|
|
* "sp_openid":"ocGgU6FplTZ87emz-JH2prRo6d7M", |
|
|
|
* "sub_openid":"oy8kY5fNACAivrxQbij4g1z6vQGQ" |
|
|
|
* }, |
|
|
|
* "amount":{ |
|
|
|
* "total":100, |
|
|
|
* "payer_total":100, |
|
|
|
* "currency":"CNY", |
|
|
|
* "payer_currency":"CNY" |
|
|
|
* } |
|
|
|
* } |
|
|
|
**/ |
|
|
|
//支付聯盟订单号 |
|
|
|
$self_order_sn = isset($data['out_trade_no']) && !empty($data['out_trade_no']) ? $data['out_trade_no'] : 0; |
|
|
|
//微信支付交易號 |
|
|
|
$trade_no = $data["transaction_id"]; |
|
|
|
//交易狀態 |
|
|
|
$trade_status = $data['trade_state'] == "SUCCESS" || $data['trade_state'] == "FINISHED" ? "TRADE_SUCCESS" : "TRADE_FAIL"; |
|
|
|
|
|
|
|
//判断该笔订单是否在 |
|
|
|
$model = UserMerchantOrder::findFirst("self_trade_no = '{$self_order_sn}'"); |
|
|
|
if (!$model) { |
|
|
|
//未查到訂單 |
|
|
|
logger(json_encode([ |
|
|
|
"msg" => "异步回调失败-訂單未查到", |
|
|
|
"data" => $_POST, |
|
|
|
], 320), 'common_wx_sync_notify_not_find', true); |
|
|
|
//验证失败 |
|
|
|
$this->wxApi(Msg::WxErr); |
|
|
|
} |
|
|
|
//商户网站中已经做过处理 |
|
|
|
if ($model->status != IPay::PAY_STATE_FOR_WAIT) { |
|
|
|
logger(json_encode([ |
|
|
|
"msg" => "异步回调已处理", |
|
|
|
"data" => $_POST, |
|
|
|
], 320), 'wxpay_sync_notify_already', true); |
|
|
|
$this->wxApi(Msg::WxSuc); |
|
|
|
} |
|
|
|
|
|
|
|
$model->return_data = json_encode($data); |
|
|
|
$model->trade_no = $trade_no; |
|
|
|
$model->updated_at = date("Y-m-d H:i:s"); |
|
|
|
|
|
|
|
#TODO::回調第三方平台的 notify_url |
|
|
|
$notify_url = $data["attach"]; |
|
|
|
$out_trade_no = $model->out_trade_no; |
|
|
|
$ext_info = json_decode($model->ext, true) ?? []; |
|
|
|
$isOk = (new PayService())->commonCurlNotifyUrl($notify_url, ["out_trade_no" => $out_trade_no, |
|
|
|
"trade_no" => $trade_no, |
|
|
|
"pay_trade_no" => $self_order_sn, |
|
|
|
"trade_status" => $trade_status, |
|
|
|
"ext_info" => $ext_info |
|
|
|
]); |
|
|
|
if ($isOk) { |
|
|
|
if ($trade_status == 'FINISHED' || $trade_status == 'TRADE_SUCCESS') { |
|
|
|
$model->status = IPay::PAY_STATE_FOR_ALREADY; |
|
|
|
if ($model->save() == false) { |
|
|
|
logger(json_encode([ |
|
|
|
"msg" => "异步回调-支付成功-更新訂單失敗", |
|
|
|
"data" => $_POST, |
|
|
|
], 320), 'wxpay_sync_notify_success_update_fail', true); |
|
|
|
$this->wxApi(Msg::WxErr); |
|
|
|
} |
|
|
|
logger(json_encode([ |
|
|
|
"msg" => "异步回调支付成功", |
|
|
|
"data" => $_POST, |
|
|
|
], 320), 'wxpay_sync_notify_success', true); |
|
|
|
} else { |
|
|
|
$model->status = IPay::PAY_STATE_FOR_FAIL; |
|
|
|
if ($model->save() == false) { |
|
|
|
logger(json_encode([ |
|
|
|
"msg" => "异步回调-支付失敗-更新訂單失敗", |
|
|
|
"data" => $_POST, |
|
|
|
], 320), 'wxpay_sync_notify_fail_update_fail', true); |
|
|
|
$this->wxApi(Msg::WxErr); |
|
|
|
} |
|
|
|
logger(json_encode([ |
|
|
|
"msg" => "异步回调支付失敗", |
|
|
|
"data" => $_POST, |
|
|
|
], 320), 'wxpay_sync_notify_fail', true); |
|
|
|
} |
|
|
|
$this->wxApi(Msg::WxSuc); |
|
|
|
} else { |
|
|
|
logger(json_encode([ |
|
|
|
"msg" => "异步回调 - 回調第三方平台失敗", |
|
|
|
"url" => $notify_url, |
|
|
|
"data" => ["out_trade_no" => $out_trade_no, |
|
|
|
"trade_no" => $trade_no, |
|
|
|
"pay_trade_no" => $self_order_sn, |
|
|
|
"trade_status" => $trade_status, |
|
|
|
"ext_info" => $ext_info |
|
|
|
], |
|
|
|
"isOk" => false |
|
|
|
], 320), 'wxpay_sync_notify_fail', true); |
|
|
|
$this->wxApi(Msg::WxErr); |
|
|
|
} |
|
|
|
} else { |
|
|
|
logger(json_encode([ |
|
|
|
"msg" => "异步回调驗證失败", |
|
|
|
"data" => $_POST, |
|
|
|
], 320), 'wxpay_sync_notify_verify_fail', true); |
|
|
|
//验证失败 |
|
|
|
$this->wxApi(Msg::WxErr); |
|
|
|
} |
|
|
|
} catch (\Exception $e) { |
|
|
|
logger(json_encode([ |
|
|
|
"msg" => "异步回调處理异常", |
|
|
|
"data" => $params ?? [], |
|
|
|
"exception" => $e->getMessage() |
|
|
|
], 320), 'wxpay_sync_notify_exception', true); |
|
|
|
//回調異常 |
|
|
|
echo "fail"; |
|
|
|
die(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |