DengBiao před 1 rokem
rodič
revize
708b920d33
3 změnil soubory, kde provedl 31 přidání a 39 odebrání
  1. +2
    -1
      src/applet/app/controllers/Alipay/PayController.php
  2. +25
    -37
      src/applet/app/controllers/CallBackController.php
  3. +4
    -1
      src/common/Service/Pay/AlipayService.php

+ 2
- 1
src/applet/app/controllers/Alipay/PayController.php Zobrazit soubor

@@ -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,


+ 25
- 37
src/applet/app/controllers/CallBackController.php Zobrazit soubor

@@ -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" => "异步回调處理异常",


+ 4
- 1
src/common/Service/Pay/AlipayService.php Zobrazit soubor

@@ -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);


Načítá se…
Zrušit
Uložit