From 7011bb23716213cc96c9fd5f74985ff701128e39 Mon Sep 17 00:00:00 2001 From: DengBiao <2319963317@qq.com> Date: Sat, 23 Sep 2023 17:17:53 +0800 Subject: [PATCH] update --- .../app/controllers/CallBackController.php | 134 ++++++++++++++---- .../CentralKitchenForSchoolPackageOrd.php | 129 +++++++++++++++++ 2 files changed, 236 insertions(+), 27 deletions(-) create mode 100644 src/common/Model/CentralKitchenForSchoolPackageOrd.php diff --git a/src/applet/app/controllers/CallBackController.php b/src/applet/app/controllers/CallBackController.php index 22be15c..47da3fc 100644 --- a/src/applet/app/controllers/CallBackController.php +++ b/src/applet/app/controllers/CallBackController.php @@ -14,15 +14,83 @@ class CallBackController extends \Phalcon\Mvc\Controller use BasisFun; + public function alipayGatewayAction() + { + $args = $this->request->get(); + } + + //加密方法 + function encrypt($input, $key, $iv) + { + + $data = @base64_encode(openssl_encrypt($input, 'AES-256-CBC', base64_decode($key), OPENSSL_RAW_DATA, $iv)); + return $data; + } + +//解密 + function decrypt($input, $key, $iv) + { + return openssl_decrypt(base64_decode($input), 'AES-256-CBC', base64_decode($key), OPENSSL_RAW_DATA, $iv); + } + + + protected function RSA2($data, $pikey) + { + $res = "-----BEGIN RSA PRIVATE KEY-----\n" . wordwrap($pikey, 64, "\n", true) . "\n-----END RSA PRIVATE KEY-----"; + // 请注意密钥 是不是有带 -----BEGIN RSA PRIVATE KEY----- -----END RSA PRIVATE KEY----- + $piKey = openssl_pkey_get_private($res); + + if ($piKey) { + $res = openssl_get_privatekey($res); + openssl_sign($data, $sign, $res, 'SHA256'); + $sign = base64_encode($sign); + openssl_free_key($piKey); + return $sign; + } + } + /** * 支付宝 - 公共网关回调 */ - public function cloudpayAliPayCallBackAction() + public function alipayCommonCallBackAction() { $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 = "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(); @@ -35,42 +103,54 @@ 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); - $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) { - //未查到訂單 + 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"); + + echo "success"; + die(); + } else { logger(json_encode([ - "msg" => "异步回调失败-訂單未查到", + "msg" => "异步回调驗證失败", "data" => $_POST, - ], 320), 'common_alipay_sync_notify_not_find', true); + ], 320), 'alipay_sync_notify_verify_fail', 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" => "异步回调處理异常", diff --git a/src/common/Model/CentralKitchenForSchoolPackageOrd.php b/src/common/Model/CentralKitchenForSchoolPackageOrd.php new file mode 100644 index 0000000..5004db6 --- /dev/null +++ b/src/common/Model/CentralKitchenForSchoolPackageOrd.php @@ -0,0 +1,129 @@ +setSource("central_kitchen_for_school_package_ord"); + } + + /** + * Allows to query a set of records that match the specified conditions + * + * @param mixed $parameters + * @return CentralKitchenForSchoolPackageOrd[]|CentralKitchenForSchoolPackageOrd|\Phalcon\Mvc\Model\ResultSetInterface + */ + public static function find($parameters = null): \Phalcon\Mvc\Model\ResultsetInterface + { + return parent::find($parameters); + } + + /** + * Allows to query the first record that match the specified conditions + * + * @param mixed $parameters + * @return CentralKitchenForSchoolPackageOrd|\Phalcon\Mvc\Model\ResultInterface|\Phalcon\Mvc\ModelInterface|null + */ + public static function findFirst($parameters = null): ?\Phalcon\Mvc\ModelInterface + { + return parent::findFirst($parameters); + } + +}