first commit

This commit is contained in:
2025-11-28 10:08:12 +08:00
commit 09a14bf0a3
1088 changed files with 145132 additions and 0 deletions
+330
View File
@@ -0,0 +1,330 @@
<?php
namespace Yeepay;
use Exception;
class YopClient
{
const VERSION = '3.1.14';
private static $serverRoot = "https://openapi.yeepay.com/yop-center";
private static $yosServerRoot = "https://yos.yeepay.com/yop-center";
private static $yopPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA6p0XWjscY+gsyqKRhw9MeLsEmhFdBRhT2emOck/F1Omw38ZWhJxh9kDfs5HzFJMrVozgU+SJFDONxs8UB0wMILKRmqfLcfClG9MyCNuJkkfm0HFQv1hRGdOvZPXj3Bckuwa7FrEXBRYUhK7vJ40afumspthmse6bs6mZxNn/mALZ2X07uznOrrc2rk41Y2HftduxZw6T4EmtWuN2x4CZ8gwSyPAW5ZzZJLQ6tZDojBK4GZTAGhnn3bg5bBsBlw2+FLkCQBuDsJVsFPiGh/b6K/+zGTvWyUcu+LUj2MejYQELDO3i2vQXVDk7lVi2/TcUYefvIcssnzsfCfjaorxsuwIDAQAB";
private $appKey;
private $secretKey;
private $downRequest;
public function __construct($appKey, $secretKey)
{
$this->appKey = $appKey;
$this->secretKey = $secretKey;
}
//发起GET请求
public function get($path, $params = null){
return $this->request('GET', $path, $params);
}
//发起POST请求
public function post($path, $params){
return $this->request('POST', $path, $params);
}
//发起上传请求
public function upload($path, $params){
return $this->request('POST', $path, $params, true);
}
//发起请求并解析返回结果
public function request($httpMethod, $path, $params = null, $file = false)
{
$requrl = ($file ? self::$yosServerRoot : self::$serverRoot) . $path;
if($httpMethod == 'GET' && $params){
$requrl .= '?' . http_build_query($params);
}
foreach($params as &$value){
if ($value instanceof \CURLFile || substr($value, 0, 1) == '@') continue;
$value = rawurlencode($value);
}
$headers = $this->getSignedHeaders($httpMethod, $path, $params);
if($httpMethod == 'POST'){
$response = $this->curl($requrl, $params, $headers);
}else{
$response = $this->curl($requrl, null, $headers);
}
if($this->downRequest) return $response;
$result = json_decode($response, true);
if(isset($result['result'])) {
return $result['result'];
}elseif(isset($result['subMessage'])){
throw new Exception('['.$result['subCode'].']'.$result['subMessage']);
}elseif(isset($result['message'])){
throw new Exception($result['message']);
}elseif(isset($result['error'])){
throw new Exception($result['error']['message']);
}else{
throw new Exception('返回数据解析失败');
}
}
//结果通知解密
public function notifyDecrypt($source)
{
//分解参数
$args = explode('$', $source);
if (count($args) != 4) {
throw new Exception('invalid response');
}
$encryptedRandomKeyToBase64 = $args[0];
$encryptedDataToBase64 = $args[1];
$symmetricEncryptAlg = $args[2];
$digestAlg = $args[3];
//用私钥对随机密钥进行解密
$randomKey = $this->rsaPrivateDecrypt($encryptedRandomKeyToBase64);
if (!$randomKey) {
throw new Exception('randomKey decrypt fail');
}
$encryptedData = openssl_decrypt(self::base64_urldecode($encryptedDataToBase64), "AES-128-ECB", $randomKey, OPENSSL_RAW_DATA);
if (!$encryptedData) {
throw new Exception('data decrypt fail');
}
//分解参数
$signToBase64 = substr(strrchr($encryptedData, '$'), 1);
$sourceData = substr($encryptedData, 0, strlen($encryptedData) - strlen($signToBase64) - 1);
if ($this->rsaPublicVerify($sourceData, $signToBase64, $digestAlg)) {
return json_decode($sourceData, true);
} else {
throw new Exception('verify sign fail');
}
}
//获取签名头部
private function getSignedHeaders($httpMethod, $path, $params)
{
$timestamp = gmdate('Y-m-d\TH:i:s\Z', time());;
$headers = array();
$headers['x-yop-appkey'] = $this->appKey;
$headers['x-yop-request-id'] = self::uuid();
$protocolVersion = "yop-auth-v2";
$expiredSeconds = "1800";
$authString = $protocolVersion . "/" . $this->appKey . "/" . $timestamp . "/" . $expiredSeconds;
$headersToSignSet = ['x-yop-request-id'];
// Formatting the query string with signing protocol.
$canonicalQueryString = $this->getCanonicalQueryString($params);
// Sorted the headers should be signed from the request.
$headersToSign = $this->getHeadersToSign($headers, $headersToSignSet);
// Formatting the headers from the request based on signing protocol.
$canonicalHeader = $this->getCanonicalHeaders($headersToSign);
$signedHeaders = "";
foreach ($headersToSign as $key => $value) {
$signedHeaders .= strlen($signedHeaders) == 0 ? "" : ";";
$signedHeaders .= $key;
}
$signedHeaders = strtolower($signedHeaders);
$canonicalRequest = $authString . "\n" . $httpMethod . "\n" . $path . "\n" . $canonicalQueryString . "\n" . $canonicalHeader;
// Signing the canonical request using key with sha-256 algorithm.
$signToBase64 = $this->rsaPrivateSign($canonicalRequest);
$headers['Authorization'] = "YOP-RSA2048-SHA256 " . $protocolVersion . "/" . $this->appKey . "/" . $timestamp . "/" . $expiredSeconds . "/" . $signedHeaders . "/" . $signToBase64;
return $headers;
}
//获取规范查询字符串
private function getCanonicalQueryString($params)
{
if(empty($params)) return '';
ksort($params);
$str = '';
foreach ($params as $k => $v) {
if ($v instanceof \CURLFile || substr($v, 0, 1) == '@') continue;
$str .= $k . '=' . $v . '&';
}
$str = substr($str, 0, -1);
return $str;
}
//获取待签名标头
private function getHeadersToSign($headers, $headersToSign)
{
$ret = array();
foreach($headersToSign as &$header) {
$header = strtolower($header);
}
foreach ($headers as $key => $value) {
if (!empty($value)) {
if (in_array(strtolower($key), $headersToSign) && $key != "Authorization") {
$ret[$key] = $value;
}
}
}
ksort($ret);
return $ret;
}
//获取规范标头
private static function getCanonicalHeaders($headers)
{
if (empty($headers)) return '';
$str = '';
foreach ($headers as $key => $value) {
$key = strtolower($key);
$value = trim($value);
$str .= strtolower($key) . ':' . trim($value) . "\n";
}
$str = substr($str, 0, -1);
return $str;
}
//商户私钥签名
private function rsaPrivateSign($data, $digestAlg = 'SHA256')
{
$key = "-----BEGIN RSA PRIVATE KEY-----\n" .
wordwrap($this->secretKey, 64, "\n", true) .
"\n-----END RSA PRIVATE KEY-----";
$privatekey = openssl_pkey_get_private($key);
if(!$privatekey){
throw new Exception('签名失败,商户私钥错误');
}
openssl_sign($data, $sign, $privatekey, $digestAlg);
$signToBase64 = self::base64_urlencode($sign);
$signToBase64 .= '$SHA256';
return $signToBase64;
}
//平台公钥验签
private function rsaPublicVerify($data, $sign, $digestAlg = 'SHA256')
{
$key = "-----BEGIN PUBLIC KEY-----\n" .
wordwrap(self::$yopPublicKey, 64, "\n", true) .
"\n-----END PUBLIC KEY-----";
$publickey = openssl_pkey_get_public($key);
if (!$publickey) {
throw new \Exception("invalid public key");
}
$result = openssl_verify($data, self::base64_urldecode($sign), $publickey, $digestAlg);
return $result === 1;
}
//商户私钥解密
private function rsaPrivateDecrypt($data)
{
$key = "-----BEGIN RSA PRIVATE KEY-----\n" .
wordwrap($this->secretKey, 64, "\n", true) .
"\n-----END RSA PRIVATE KEY-----";
$privatekey = openssl_pkey_get_private($key);
if(!$privatekey){
throw new Exception('invalid private key');
}
openssl_private_decrypt(self::base64_urldecode($data), $decrypted, $privatekey);
return $decrypted;
}
private function curl($url, $postFields, $headers)
{
$uaString = "php/" . self::VERSION . "/" . PHP_OS . "/" . (array_key_exists('SERVER_SOFTWARE', $_SERVER) ? $_SERVER ['SERVER_SOFTWARE'] : "") . "/Zend Framework/" . zend_version() . "/" . PHP_VERSION . "/" . (array_key_exists('HTTP_ACCEPT_LANGUAGE', $_SERVER) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : "") . "/";
$headerArray = array();
foreach ($headers as $key => $value) {
$headerArray[] = $key . ": " . $value;
}
$headerArray[] = 'x-yop-sdk-langs: php';
$headerArray[] = 'x-yop-sdk-version: '.self::VERSION;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_FAILONERROR, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray);
curl_setopt($ch, CURLOPT_USERAGENT, $uaString);
if (is_array($postFields) && 0 < count($postFields)) {
$postMultipart = false;
foreach ($postFields as &$value) {
if ($value instanceof \CURLFile) {
$postMultipart = true;
} elseif(substr($value, 0, 1) == '@' && class_exists('CURLFile')) {
$postMultipart = true;
$file = substr($value, 1);
if(file_exists($file)){
$value = new \CURLFile($file);
}
}
}
curl_setopt($ch, CURLOPT_POST, true);
if($postMultipart){
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
}else{
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postFields));
}
}
$response = curl_exec($ch);
if (curl_errno($ch) > 0) {
$errmsg = curl_error($ch);
curl_close($ch);
throw new \Exception($errmsg, 0);
}
$responseHeaders = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
if (!empty($responseHeaders) && substr_compare($responseHeaders, "application/octet-stream", 0, 16) == 0) {
$this->downRequest = true;
}
curl_close($ch);
return $response;
}
private static function base64_urlencode($data, $use_padding = false)
{
$encoded = strtr(base64_encode($data), '+/', '-_');
return true === $use_padding ? $encoded : rtrim($encoded, '=');
}
private static function base64_urldecode($data)
{
return base64_decode(strtr($data, '-_', '+/'));
}
private static function uuid($namespace = '')
{
static $guid = '';
$uid = uniqid("", true);
$data = $_SERVER['REQUEST_TIME'];
$hash = hash('ripemd128', $uid . $data);
$guid = $namespace .
substr($uid, 0, 14) .
substr($uid, 15, 24) .
substr($hash, 0, 10) .
'';
return $guid;
}
}
+468
View File
@@ -0,0 +1,468 @@
<?php
class yeepay_plugin
{
static public $info = [
'name' => 'yeepay', //支付插件英文名称,需和目录名称一致,不能有重复
'showname' => '易宝支付', //支付插件显示名称
'author' => '易宝支付', //支付插件作者
'link' => 'https://www.yeepay.com/', //支付插件作者链接
'types' => ['alipay','wxpay','bank'], //支付插件支持的支付方式,可选的有alipay,qqpay,wxpay,bank
'inputs' => [ //支付插件要求传入的参数以及参数显示名称,可选的有appid,appkey,appsecret,appurl,appmchid
'appkey' => [
'name' => '应用标识',
'type' => 'input',
'note' => '',
],
'appsecret' => [
'name' => '商户私钥',
'type' => 'textarea',
'note' => '',
],
'appid' => [
'name' => '发起方商户编号',
'type' => 'input',
'note' => '标准商户则填写标准商户商编;平台商入驻商户,则填写平台商商编',
],
'appmchid' => [
'name' => '收款商户编号',
'type' => 'input',
'note' => '留空则与发起方商户编号一致',
],
],
'select' => null,
'note' => '密钥需要选RSA格式的', //支付密钥填写说明
'bindwxmp' => false, //是否支持绑定微信公众号
'bindwxa' => false, //是否支持绑定微信小程序
];
static public function submit(){
global $siteurl, $channel, $order, $sitename;
if($order['typename']=='alipay'){
return ['type'=>'jump','url'=>'/pay/alipay/'.TRADE_NO.'/'];
}elseif($order['typename']=='wxpay'){
if(checkwechat() && $channel['appwxmp']>0){
return ['type'=>'jump','url'=>'/pay/wxjspay/'.TRADE_NO.'/'];
}elseif(checkmobile()){
return ['type'=>'jump','url'=>'/pay/wxwappay/'.TRADE_NO.'/'];
}else{
return ['type'=>'jump','url'=>'/pay/wxpay/'.TRADE_NO.'/'];
}
}elseif($order['typename']=='bank'){
return ['type'=>'jump','url'=>'/pay/bank/'.TRADE_NO.'/'];
}
}
static public function mapi(){
global $siteurl, $channel, $order, $conf, $device, $mdevice, $method;
if($method == 'applet'){
return self::wxapppay();
}
elseif($method == 'app'){
if($order['typename']=='alipay'){
return self::aliapppay();
}else{
return self::wxapppay();
}
}
elseif($order['typename']=='alipay'){
return self::alipay();
}elseif($order['typename']=='wxpay'){
if($mdevice=='wechat' && $channel['appwxmp']>0){
return ['type'=>'jump','url'=>$siteurl.'pay/wxjspay/'.TRADE_NO.'/'];
}elseif($device=='mobile'){
return self::wxwappay();
}else{
return self::wxpay();
}
}elseif($order['typename']=='bank'){
return self::bank();
}
}
//聚合支付托管下单
static private function tutelage_pay($payWay, $payType, $return_type = false){
global $siteurl, $channel, $order, $ordername, $conf, $clientip;
require(PAY_ROOT.'inc/YopClient.php');
if($payType == 'ALIPAY'){
$scene = 'OFFLINE';
}else{
$scene = 'ONLINE';
}
$params = [
'parentMerchantNo' => $channel['appid'],
'merchantNo' => empty($channel['appmchid'])?$channel['appid']:$channel['appmchid'],
'orderId' => TRADE_NO,
'orderAmount' => $order['realmoney'],
'goodsName' => $ordername,
'notifyUrl' => $conf['localurl'] . 'pay/notify/' . TRADE_NO . '/',
'payWay' => $payWay,
'channel' => $payType,
'scene' => $scene,
'userIp' => $clientip,
'redirectUrl' => $siteurl.'pay/return/'.TRADE_NO.'/',
];
if($order['profits']){
self::handleProfits($params);
}
$client = new \Yeepay\YopClient($channel['appkey'], $channel['appsecret']);
return \lib\Payment::lockPayData(TRADE_NO, function() use($client, $params, $return_type) {
$result = $client->post('/rest/v1.0/aggpay/tutelage/pre-pay', $params);
if($result['code'] == '00000'){
return $return_type ? ['appId'=>$result['appId'],'miniProgramPath'=>$result['miniProgramPath'],'miniProgramOrgId'=>$result['miniProgramOrgId']] : $result['prePayTn'];
}else{
throw new Exception('['.$result['code'].']'.$result['message']);
}
});
}
//聚合支付统一下单
static private function pre_pay($payWay, $payType, $appId = null, $userId = null){
global $siteurl, $channel, $order, $ordername, $conf, $clientip;
require(PAY_ROOT.'inc/YopClient.php');
$params = [
'parentMerchantNo' => $channel['appid'],
'merchantNo' => empty($channel['appmchid'])?$channel['appid']:$channel['appmchid'],
'orderId' => TRADE_NO,
'orderAmount' => $order['realmoney'],
'goodsName' => $ordername,
'notifyUrl' => $conf['localurl'] . 'pay/notify/' . TRADE_NO . '/',
'redirectUrl' => $siteurl.'pay/return/'.TRADE_NO.'/',
'payWay' => $payWay,
'channel' => $payType,
'scene' => 'ONLINE',
'userIp' => $clientip,
];
if($appId && $userId){
$params += [
'appId' => $appId,
'userId' => $userId
];
}
if($order['profits']){
self::handleProfits($params);
}
$client = new \Yeepay\YopClient($channel['appkey'], $channel['appsecret']);
return \lib\Payment::lockPayData(TRADE_NO, function() use($client, $params) {
$result = $client->post('/rest/v1.0/aggpay/pre-pay', $params);
if($result['code'] == '00000'){
return $result['prePayTn'];
}else{
throw new Exception('['.$result['code'].']'.$result['message']);
}
});
}
static private function handleProfits(&$params){
global $order, $conf;
$psreceiver = \lib\ProfitSharing\CommUtil::getReceiver($order['profits']);
if($psreceiver){
$psmoney = round(floor($order['realmoney'] * $psreceiver['rate']) / 100, 2);
$divideDetail = [[
'ledgerNo' => $psreceiver['account'],
'amount' => $psmoney,
'ledgerType' => 'MERCHANT2MERCHANT',
]];
$params['fundProcessType'] = 'REAL_TIME_DIVIDE';
$params['divideDetail'] = json_encode($divideDetail);
$params['divideNotifyUrl'] = $conf['localurl'] . 'pay/dividenotify/' . TRADE_NO . '/';
}
}
//支付宝扫码支付
static public function alipay(){
try{
$code_url = self::pre_pay('USER_SCAN', 'ALIPAY');
}catch(Exception $ex){
return ['type'=>'error','msg'=>'支付宝支付下单失败!'.$ex->getMessage()];
}
return ['type'=>'qrcode','page'=>'alipay_qrcode','url'=>$code_url];
}
//微信扫码支付
static public function wxpay(){
global $siteurl;
$code_url = $siteurl.'pay/wxwappay/'.TRADE_NO.'/';
/*try{
$code_url = self::pre_pay('USER_SCAN', 'WECHAT');
}catch(Exception $ex){
return ['type'=>'error','msg'=>'微信支付下单失败!'.$ex->getMessage()];
}*/
if (checkmobile()) {
return ['type'=>'qrcode','page'=>'wxpay_wap','url'=>$code_url];
} else {
return ['type'=>'qrcode','page'=>'wxpay_qrcode','url'=>$code_url];
}
}
//微信公众号支付
static public function wxjspay(){
global $siteurl, $channel, $order, $ordername, $conf, $clientip;
//①、获取用户openid
$wxinfo = \lib\Channel::getWeixin($channel['appwxmp']);
if(!$wxinfo) return ['type'=>'error','msg'=>'支付通道绑定的微信公众号不存在'];
try{
$tools = new \WeChatPay\JsApiTool($wxinfo['appid'], $wxinfo['appsecret']);
$openid = $tools->GetOpenid();
}catch(Exception $e){
return ['type'=>'error','msg'=>$e->getMessage()];
}
$blocks = checkBlockUser($openid, TRADE_NO);
if($blocks) return $blocks;
//②、统一下单
try{
$payinfo = self::pre_pay('WECHAT_OFFIACCOUNT', 'WECHAT', $wxinfo['appid'], $openid);
}catch(Exception $ex){
return ['type'=>'error','msg'=>'微信支付下单失败!'.$ex->getMessage()];
}
if($_GET['d']==1){
$redirect_url='data.backurl';
}else{
$redirect_url='\'/pay/ok/'.TRADE_NO.'/\'';
}
return ['type'=>'page','page'=>'wxpay_jspay','data'=>['jsApiParameters'=>$payinfo, 'redirect_url'=>$redirect_url]];
}
//微信小程序支付
static public function wxminipay(){
global $siteurl, $channel, $order, $ordername, $conf, $clientip;
$code = isset($_GET['code'])?trim($_GET['code']):exit('{"code":-1,"msg":"code不能为空"}');
//①、获取用户openid
$wxinfo = \lib\Channel::getWeixin($channel['appwxa']);
if(!$wxinfo)exit('{"code":-1,"msg":"支付通道绑定的微信小程序不存在"}');
try{
$tools = new \WeChatPay\JsApiTool($wxinfo['appid'], $wxinfo['appsecret']);
$openid = $tools->AppGetOpenid($code);
}catch(Exception $e){
exit('{"code":-1,"msg":"'.$e->getMessage().'"}');
}
$blocks = checkBlockUser($openid, TRADE_NO);
if($blocks)exit('{"code":-1,"msg":"'.$blocks['msg'].'"}');
//②、统一下单
try{
$payinfo = self::pre_pay('MINI_PROGRAM', 'WECHAT', $wxinfo['appid'], $openid);
}catch(Exception $ex){
exit('{"code":-1,"msg":"'.$ex->getMessage().'"}');
}
exit(json_encode(['code'=>0, 'data'=>json_decode($payinfo, true)]));
}
//微信手机支付
static public function wxwappay(){
try{
$jump_url = self::tutelage_pay('H5_PAY', 'WECHAT');
}catch(Exception $ex){
return ['type'=>'error','msg'=>'微信支付下单失败!'.$ex->getMessage()];
}
if(checkwechat()){
return ['type'=>'jump','url'=>$jump_url];
}else{
return ['type'=>'qrcode','page'=>'wxpay_h5','url'=>$jump_url];
}
}
//支付宝APP支付
static public function aliapppay(){
try{
$code_url = self::tutelage_pay('SDK_PAY', 'ALIPAY');
}catch(Exception $e){
return ['type'=>'error','msg'=>$e->getMessage()];
}
return ['type'=>'scheme','page'=>'alipay_qrcode','url'=>$code_url];
}
//微信APP支付
static public function wxapppay(){
try{
$result = self::tutelage_pay('SDK_PAY', 'WECHAT');
}catch(Exception $e){
return ['type'=>'error','msg'=>$e->getMessage()];
}
return ['type'=>'wxapp','data'=>['appId'=>$result['appId'], 'miniProgramId'=>$result['miniProgramOrgId'], 'path'=>$result['miniProgramPath']]];
}
//云闪付扫码支付
static public function bank(){
try{
$code_url = self::pre_pay('USER_SCAN', 'UNIONPAY');
}catch(Exception $ex){
return ['type'=>'error','msg'=>'云闪付下单失败!'.$ex->getMessage()];
}
return ['type'=>'qrcode','page'=>'bank_qrcode','url'=>$code_url];
}
//异步回调
static public function notify(){
global $channel, $order;
if(!$_POST['response']) return ['type'=>'html','data'=>'no data'];
require(PAY_ROOT.'inc/YopClient.php');
$client = new \Yeepay\YopClient($channel['appkey'], $channel['appsecret']);
try{
$data = $client->notifyDecrypt($_POST['response']);
}catch(Exception $e){
return ['type'=>'html','data'=>$e->getMessage()];
}
if($data) {
$out_trade_no = $data['orderId'];
$api_trade_no = $data['uniqueOrderNo'];
$total_amount = $data['orderAmount'];
$payerInfo = json_decode($data['payerInfo'], true);
$buyer = $payerInfo['userID'];
$bill_trade_no = $data['channelTrxId'];
if ($data['status'] == 'SUCCESS') {
if($out_trade_no == TRADE_NO && round($total_amount,2)==round($order['realmoney'],2)){
processNotify($order, $api_trade_no, $buyer, $bill_trade_no);
}
}
return ['type'=>'html','data'=>'SUCCESS'];
}
else {
//验证失败
return ['type'=>'html','data'=>'FAIL'];
}
}
//支付返回页面
static public function return(){
return ['type'=>'page','page'=>'return'];
}
//退款
static public function refund($order){
global $channel, $clientip;
if(empty($order))exit();
require(PAY_ROOT.'inc/YopClient.php');
$params = [
'parentMerchantNo' => $channel['appid'],
'merchantNo' => empty($channel['appmchid'])?$channel['appid']:$channel['appmchid'],
'orderId' => $order['trade_no'],
'refundRequestId' => $order['refund_no'] ?? $order['trade_no'],
'refundAmount' => $order['refundmoney']
];
$client = new \Yeepay\YopClient($channel['appkey'], $channel['appsecret']);
$result = $client->post('/rest/v1.0/trade/refund', $params);
if($result['code'] == 'OPR00000'){
return ['code'=>0, 'trade_no'=>$result['uniqueRefundNo'], 'refund_fee'=>$result['refundAmount']];
}else{
return ['code'=>-1, 'msg'=>'['.$result['code'].']'.$result['message']];
}
}
//异步回调
static public function applynotify(){
global $channel;
if(!$_POST['response']) return ['type'=>'html','data'=>'no data'];
require(PAY_ROOT.'inc/YopClient.php');
$client = new \Yeepay\YopClient($channel['appkey'], $channel['appsecret']);
try{
$data = $client->notifyDecrypt($_POST['response']);
}catch(Exception $e){
return ['type'=>'html','data'=>$e->getMessage()];
}
if($data) {
$model = \lib\Applyments\CommUtil::getModel2($channel);
if($model) $model->notify($data);
return ['type'=>'html','data'=>'SUCCESS'];
}
else {
//验证失败
return ['type'=>'html','data'=>'FAIL'];
}
}
//投诉通知
static public function complainnotify(){
global $channel;
if(!$_POST['response']) return ['type'=>'html','data'=>'no data'];
require(PAY_ROOT.'inc/YopClient.php');
$client = new \Yeepay\YopClient($channel['appkey'], $channel['appsecret']);
try{
$data = $client->notifyDecrypt($_POST['response']);
}catch(Exception $e){
return ['type'=>'html','data'=>$e->getMessage()];
}
if($data) {
$model = \lib\Complain\CommUtil::getModel($channel);
if($model) $model->refreshNewInfo($data['complaintNo'], $data['actionType']);
return ['type'=>'html','data'=>'SUCCESS'];
}
else {
//验证失败
return ['type'=>'html','data'=>'FAIL'];
}
}
//分账回调
static public function dividenotify(){
global $channel, $DB;
if(!$_POST['response']) return ['type'=>'html','data'=>'no data'];
require(PAY_ROOT.'inc/YopClient.php');
$client = new \Yeepay\YopClient($channel['appkey'], $channel['appsecret']);
try{
$data = $client->notifyDecrypt($_POST['response']);
}catch(Exception $e){
return ['type'=>'html','data'=>$e->getMessage()];
}
if($data) {
$divide_trade_no = $data['divideRequestId'];
$out_trade_no = $data['orderId'];
$status = $data['divideStatus'];
$psorder = $DB->find('psorder', '*', ['trade_no'=>$out_trade_no]);
if($psorder){
if($status == 'SUCCESS'){
$DB->update('psorder', ['status'=>2,'settle_no'=>$divide_trade_no], ['id'=>$psorder['id']]);
}elseif($status == 'FAIL'){
$DB->update('psorder', ['status'=>3,'result'=>$data['failReason']], ['id'=>$psorder['id']]);
}
}
return ['type'=>'html','data'=>'SUCCESS'];
}
else {
//验证失败
return ['type'=>'html','data'=>'FAIL'];
}
}
}