Kaynağa Gözat

update

master
DengBiao 1 yıl önce
ebeveyn
işleme
9aa9093119
3 değiştirilmiş dosya ile 167 ekleme ve 7 silme
  1. +12
    -0
      src/applet/app/controllers/AliCallBackController.php
  2. +79
    -7
      src/applet/app/controllers/CallBackController.php
  3. +76
    -0
      src/common/Service/Pay/AesUtilService.php

+ 12
- 0
src/applet/app/controllers/AliCallBackController.php Dosyayı Görüntüle

@@ -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"])) {


+ 79
- 7
src/applet/app/controllers/CallBackController.php Dosyayı Görüntüle

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

}

+ 76
- 0
src/common/Service/Pay/AesUtilService.php Dosyayı Görüntüle

@@ -0,0 +1,76 @@
<?php

namespace SRVX\Service\Pay;
use SRVX\Service\BaseService;

/**
* demo
* Class DemoService
* @package SRVX\Service
*/
class AesUtilService extends BaseService
{
/**
* AES key
*
* @var string
*/
private $aesKey;

const KEY_LENGTH_BYTE = 32;
const AUTH_TAG_LENGTH_BYTE = 16;

/**
* Constructor
* @throws \Exception
*/
public function __construct($aesKey = "")
{
$aesKey = !empty($aesKey) ? $aesKey : "fnuo123comzhioscnfnuooscom123zhi";
if (strlen($aesKey) != self::KEY_LENGTH_BYTE) {
throw new \Exception('无效的ApiV3Key,长度应为32个字节');
}
$this->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');
}

}

Yükleniyor…
İptal
Kaydet