Selaa lähdekoodia

update

master
DengBiao 1 vuosi sitten
vanhempi
commit
6e47e104f3
2 muutettua tiedostoa jossa 43 lisäystä ja 198 poistoa
  1. +37
    -198
      src/applet/app/controllers/CallBackController.php
  2. +6
    -0
      src/common/Model/SelfSupportForUserFaceInfo.php

+ 37
- 198
src/applet/app/controllers/CallBackController.php Näytä tiedosto

@@ -2,14 +2,11 @@

namespace SRVX\Api\Controllers;

use App\constants\Pay as IPay;
use SRVX\Model\MerchantAlipayAuthorize;
use SRVX\Model\OwnOrder;
use SRVX\Model\UserMerchantOrder;
use SRVX\Model\SelfSupportForUserFaceInfo;
use SRVX\Msg;
use SRVX\Service\AliBPass\demo\AliEcoService;
use SRVX\Service\Pay\EasyAlipayService;
use SRVX\Service\Pay\PayService;
use SRVX\Service\Pay\Wx\PayService as WxPayService;
use SRVX\Traits\BasisFun;

class CallBackController extends \Phalcon\Mvc\Controller
@@ -60,39 +57,43 @@ class CallBackController extends \Phalcon\Mvc\Controller
$args = $this->request->get();
$this->logger($args, 'alipayCommonCallBack', true);
if ($this->request->isPost()) {
switch ($_POST["msg_method"] ?? ""){
case "alipay.commerce.educate.service.status.changed" :
$biz_content = json_decode($_POST["biz_content"], true);
$selfSupportForSchoolInfo = SelfSupportForUserFaceInfo::findFirst("user_id = '{$biz_content["user_id"]}' and school_std_code = '{$biz_content["school_std_code"]}'");
if (!empty($selfSupportForSchoolInfo)) {
if ($biz_content["service_name"] == "SCHOOL_FACE_PASS_OPEN") {
//一脸通行开通
$selfSupportForSchoolInfo->school_face_pass_status = "OPEN";
}
if ($biz_content["service_name"] == "SCHOOL_FACE_PASS_CLOSE") {
//一脸通行关闭
$selfSupportForSchoolInfo->school_face_pass_status = "CLOSE";
}
if ($biz_content["service_name"] == "SCHOOL_FACE_PAYMENT_OPEN") {
//校园刷脸支付开通
$selfSupportForSchoolInfo->school_face_payment_status = "OPEN";
}
if ($biz_content["service_name"] == "SCHOOL_FACE_PAYMENT_CLOSE") {
//校园刷脸支付关闭
$selfSupportForSchoolInfo->school_face_payment_status = "OPEN";
}
$selfSupportForSchoolInfo->save();
//TODO::通知行业云 alipay.planet.ecocampus.api.roster.signUpInfo(签约信息同步)
// (new AliEcoService())->alipayPlanetEcocampusApiRosterSignUpInfo(
// $selfSupportForSchoolInfo->user_id, $selfSupportForSchoolInfo->parent_user_id,
// $selfSupportForSchoolInfo->parent_logon_id, $selfSupportForSchoolInfo->user_identity_id,
// $selfSupportForSchoolInfo->user_identity_id, $selfSupportForSchoolInfo->school_code,
// $args["school_name"], $args["face_open_status"], $args["scan_face_pay_status"]
// );
}
break;
}
$this->logger($_POST, 'alipayCommonCallBack_post', true);
}

//获取支付宝行业云公钥
$alipayrsaPublicKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuWFuSpwY/2llLhy5Hxkqcc0qQFQOvemkYOI4S43L4qArX4x+DQN1RFuvfGuwOLScBKaoDYHsu9PSoTtcIj4obhhexbWHfelcsouV7Pj4YChrOkOLHAMLDQhGRXaZyXQAJdk2DoBkJ0vBDD/b1gZT8QznPopvuT4Y0rx/a2vK+5B/XV0wUuP2PnpWoPxNSwr7neFWvUdkC7yJJg4zJ1INLYy9TgHH3LKYrsEDbQzPJyMPFhD0zDb36b62q3tQYc1w8JknS6XeXMkX1Tu4zZbAxyIiv3J1FK8y7dtoRi9gLgo0uLsXWDn5AwAlzqfOERgLMWD2r6FE8tOXVbMha6IImQIDAQAB';
//支付宝提供的密钥
$secretKey = "HOrPS0V4BthAPfgSdbHWwy0TwPnC8TQAQZIOjc8vOzI=";
//配置应用公私钥 中生成的私钥
$privateKey = 'MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCSGJ9ob4kmGy6y4YeynjKJc/LSg02EXjLErPZSfVrAOy69FTRfBDbazlxpfl6YCAxDdT5ZcspB5kS2XYOY4dmqqPmF4VywmcjmZM8IxZFl1p7YC8BOlP6JrzDPwVl3hn4z3Em1byj8ANLY/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oQKBgQCocPd7An8qTDIBZMOC4oT29+TYvUO+yMkAHLmx1h4QkLCkWegB4g5QkKkAGPWp3hshAj/KA0cXthFXVUG/SGZ2K6eB+nbon1N+9cDETdM4QXzN5gE/mUlupIxqRU1ouI27YYPbJSQNTrC7OkwNzfnpe/gshEj/gr5eHHvd4UrvMQKBgD2Toow7sfpV0R9rhO8aJ9njlbH15LqUK/AotK3E7zr73Uv5j/BIKS4dVC7T56L2khEUbM/y8+Rig6CdyFf3A4i4GKfbp56Sap/Haa9OP6jfep6VW7Aa1AJxPvIPgPZ2U+EuRxrwrP1EBcL5z6Cern9c9Zzs8BPUacU+Q5e8c87W';
$publicKey = "xxxxxxx";
$iv = "";

$response = [
"code" => "10000",
"msg" => "Success",
"face_group_key" => "K12_2088323332233424",
];

// 3、业务处理结果加签,业务返回结果需要进行排序
ksort($response);//数组排序
$contentToSign = json_encode($response);//数组转json
$responseSecretText = $this->encrypt($contentToSign, $secretKey, $iv);//加密方法,只有当前调用的业务接口需要加解密时才需要

//用 接入准备 > 3.配置应用公私钥 中生成的私钥,对第4步的加密字符串进行加签,放到 sign 参数里。
$sign1 = $this->RSA2($responseSecretText, $privateKey);//加签
$result = [
"sign" => $sign1,
"response" => $responseSecretText
];

exit(json_encode(
$result
));
}
echo "success";
die();
}

/**
@@ -162,166 +163,4 @@ class CallBackController extends \Phalcon\Mvc\Controller
}
}
}

/**
* 微信 - 公共异步回调
*/
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 WxPayService())->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();
}
}
}

+ 6
- 0
src/common/Model/SelfSupportForUserFaceInfo.php Näytä tiedosto

@@ -60,6 +60,12 @@ class SelfSupportForUserFaceInfo extends BasicModel
*/
public $school_face_payment_status;

/**
*
* @var string
*/
public $concentrate_school_face_pass_status;

/**
*
* @var string


Ladataan…
Peruuta
Tallenna