From 9aa909311967b6b338101bfb923e274ab88515ae Mon Sep 17 00:00:00 2001 From: DengBiao <2319963317@qq.com> Date: Wed, 18 Oct 2023 11:10:33 +0800 Subject: [PATCH] update --- .../app/controllers/AliCallBackController.php | 12 +++ .../app/controllers/CallBackController.php | 86 +++++++++++++++++-- src/common/Service/Pay/AesUtilService.php | 76 ++++++++++++++++ 3 files changed, 167 insertions(+), 7 deletions(-) create mode 100644 src/common/Service/Pay/AesUtilService.php diff --git a/src/applet/app/controllers/AliCallBackController.php b/src/applet/app/controllers/AliCallBackController.php index e14c87c..497dd7e 100644 --- a/src/applet/app/controllers/AliCallBackController.php +++ b/src/applet/app/controllers/AliCallBackController.php @@ -86,6 +86,18 @@ class AliCallBackController extends \Phalcon\Mvc\Controller $this->logger(["params" => $params], 'alipay.planet.ecocampus.spi.trade.pay.detail', true); $biz_content = json_decode($params["biz_content"], true); $this->logger(["biz_content" => $biz_content], 'alipay.planet.ecocampus.spi.trade.pay.detail', true); + + $isHasSchool = SelfSupportForSchoolInfo::findFirst("school_code = '{$biz_content["buyer_info"]["school_code"]}'"); + if (empty($isHasSchool)) { + $response = [ + "code" => "40000", + "msg" => "Business Failed", + "sub_code" => "20000", + "sub_msg" => "not found school records", + ]; + break; + } + //获取用户身份信息 $userIdentityId = 0; if (isset($biz_content["buyer_info"])) { diff --git a/src/applet/app/controllers/CallBackController.php b/src/applet/app/controllers/CallBackController.php index 65a6281..6188a9e 100644 --- a/src/applet/app/controllers/CallBackController.php +++ b/src/applet/app/controllers/CallBackController.php @@ -3,10 +3,7 @@ namespace SRVX\Api\Controllers; 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\Traits\BasisFun; class CallBackController extends \Phalcon\Mvc\Controller @@ -165,7 +162,7 @@ class CallBackController extends \Phalcon\Mvc\Controller } /** - * 支付宝 - 公共异步回调 + * 微信 - 公共异步回调 */ public function wxpayAsyncNotifyCallBackAction() { @@ -173,9 +170,84 @@ class CallBackController extends \Phalcon\Mvc\Controller $this->logger($args, 'wxpayAsyncNotifyCallBack', true); if ($this->request->isPost()) { - $data = file_get_contents('php://input'); - $data = json_decode($data, true); - $this->logger($data, 'wxpayAsyncNotifyCallBack_post', true); + try { + $data = file_get_contents('php://input'); + $data = json_decode($data, true); + if ($data["event_type"] == "TRANSACTION.SUCCESS") { + + $ciphertext=(new \SRVX\Service\Pay\AesUtilService())->decryptToString($data['resource']['associated_data'],$data['resource']['nonce'],$data['resource']['ciphertext']); + //转数组 + $res = json_decode($ciphertext,true); + logger(json_encode([ + "msg" => "异步回调", + "data" => $data, + "res" => $res + ], 320), 'common_alipay_sync_notify', true); + + if(!empty($res['out_trade_no']) and isset($res['trade_state']) and $res['trade_state']=='SUCCESS') + { + //成功回调 + dd($res); + } + } + }catch (\Exception $e) { + logger(json_encode([ + "msg" => "异步回调异常", + "data" => $params ?? [], + "exception" => $e->getMessage() + ], 320), 'wxpay_sync_notify_exception', true); + //回調異常 + echo "fail"; + die(); + } + } + } + + /** + * 支付宝-行业云-云支付- 交易完成回调 + */ + public function cloudpayAliPayCallBackAction() + { + $args = $this->request->get(); + $this->logger($args, 'cloudpayAliPayCallBackAction', 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 = "CLOSE"; + } + $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); + } + echo "success"; + die(); } + } \ No newline at end of file diff --git a/src/common/Service/Pay/AesUtilService.php b/src/common/Service/Pay/AesUtilService.php new file mode 100644 index 0000000..d89626a --- /dev/null +++ b/src/common/Service/Pay/AesUtilService.php @@ -0,0 +1,76 @@ +aesKey = $aesKey; + } + + /** + * Decrypt AEAD_AES_256_GCM ciphertext + * + * @param string $associatedData AES GCM additional authentication data + * @param string $nonceStr AES GCM nonce + * @param string $ciphertext AES GCM cipher text + * + * @return string|bool Decrypted string on success or FALSE on failure + */ + public function decryptToString($associatedData, $nonceStr, $ciphertext) + { + $ciphertext = \base64_decode($ciphertext); + if (strlen($ciphertext) <= self::AUTH_TAG_LENGTH_BYTE) { + return false; + } + + // ext-sodium (default installed on >= PHP 7.2) + if (function_exists('\sodium_crypto_aead_aes256gcm_is_available') && + \sodium_crypto_aead_aes256gcm_is_available()) { + return \sodium_crypto_aead_aes256gcm_decrypt($ciphertext, $associatedData, $nonceStr, $this->aesKey); + } + + // ext-libsodium (need install libsodium-php 1.x via pecl) + if (function_exists('\Sodium\crypto_aead_aes256gcm_is_available') && + \Sodium\crypto_aead_aes256gcm_is_available()) { + return \Sodium\crypto_aead_aes256gcm_decrypt($ciphertext, $associatedData, $nonceStr, $this->aesKey); + } + + // openssl (PHP >= 7.1 support AEAD) + if (PHP_VERSION_ID >= 70100 && in_array('aes-256-gcm', \openssl_get_cipher_methods())) { + $ctext = substr($ciphertext, 0, -self::AUTH_TAG_LENGTH_BYTE); + $authTag = substr($ciphertext, -self::AUTH_TAG_LENGTH_BYTE); + + return \openssl_decrypt($ctext, 'aes-256-gcm', $this->aesKey, \OPENSSL_RAW_DATA, $nonceStr, + $authTag, $associatedData); + } + + throw new \RuntimeException('AEAD_AES_256_GCM需要PHP 7.1以上或者安装libsodium-php'); + } + +} \ No newline at end of file