master
elf 11 months ago
parent 4c82631c41
commit e3db44c4c4

@ -11,6 +11,7 @@ use Sdk\Controller\Ipa365Controller;
use Base\Tool\Redis; use Base\Tool\Redis;
use Org\Kudian\Response as KDResponse; use Org\Kudian\Response as KDResponse;
use Org\Kudian\Log as KDLog; use Org\Kudian\Log as KDLog;
use Org\OuterPay\Log as OuterPayLog;
/** /**
* 支付回调控制器 * 支付回调控制器
@ -968,4 +969,42 @@ class NotifyController extends BaseController
} }
echo 'SUCCESS'; echo 'SUCCESS';
} }
/**
* 外部支付宝回调
*/
public function out_alipay_callback() {
$params = file_get_contents('php://input');
OuterPayLog::write('NOTIFY_INPUT:' . file_get_contents('php://input'));
$params = json_decode($params, true);
if ($params['trade_status'] != 'TRADE_SUCCESS' || $params['pay_status'] == 'TRADE_FINISHED') {
echo 'SUCCESS';
return;
}
$orderInfo['trade_no'] = $params['trade_no'];
$orderInfo['out_trade_no'] = $params['out_trade_no'];
$orderInfo['money'] = $params['total_amount'];
$payWhere = substr($params['out_trade_no'], 0, 2);
switch ($payWhere) {
case 'SP':
$result = $this->set_spend($orderInfo);
break;
case 'PF':
$result = $this->set_deposit($orderInfo);
break;
case 'AG':
$result = $this->set_agent($orderInfo);
break;
default:
exit('accident order data');
break;
}
echo 'SUCCESS';
}
} }

@ -15,7 +15,7 @@ use Sdk\Model\PayLimitConfModel;
use Sdk\Model\PayChannelInterntionModel; use Sdk\Model\PayChannelInterntionModel;
use Sdk\Model\PayChannelIntentionModel; use Sdk\Model\PayChannelIntentionModel;
use Org\Kudian\Api as KDApi; use Org\Kudian\Api as KDApi;
use Org\OuterPay\AlipayApi;
class PayH5Controller extends BaseController{ class PayH5Controller extends BaseController{
const ALI_PAY = 1; const ALI_PAY = 1;
@ -584,7 +584,44 @@ class PayH5Controller extends BaseController{
// redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>$ret[0]['respMess'], 'user_token' => $this->userToken)));exit; // redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>$ret[0]['respMess'], 'user_token' => $this->userToken)));exit;
} }
} elseif ($pay_info['channel'] == 11) { // 外部支付宝
$request['pay_way'] = 41;
$request['pay_status'] = 0;
$request['spend_ip'] = get_client_ip();
$request['merchant_id'] = $pay_info['id'];
$request['merchant_way'] = 1;
$request['main_id'] = $main_id;
$userInfo = get_user_entity($request['user_id']);
$request['game_name'] = $request['game_name'] ?: get_game_name($request["game_id"]);
$ordercheck = M("spend","tab_")->where(array('pay_order_number'=>$request["pay_order_number"]))->find();
if ($ordercheck) {
$returl = U('Spend/notice',array('user_id'=>$ordercheck['user_id'],'game_id'=>$ordercheck['game_id'],'msg'=>'订单已经存在,请刷新充值页面重新下单!'));
echo json_encode(['code'=>0,'msg'=>'订单已经存在,请刷新充值页面重新下单!','wap'=>1]);
exit;
}
$this->add_spend($request,1);
$notifyUrl = C('PAY_DOMAIN')."/callback.php/Notify/out_alipay_callback";
$backUrl = C('PAY_DOMAIN')."sdk.php/Spend/paycallback/orderno/{$request['pay_order_number']}/user_token/".$this->userToken."/paytype/weixinpay/game_id/{$game_id}";
$response = AlipayApi::pay($request, $userInfo, $notifyUrl, $backUrl);
if($response['code'] == '0000'){
// 存入pay_url 继续支付
M("spend", "tab_")->where([
'extend' => $request['extend'],
'game_id' => $request['game_id'],
'pay_order_number' => $request["pay_order_number"]
])->save([
'pay_url' => $response['data']['pay_url']
]);
$orderno = $request['pay_order_number'];
} else {
echo json_encode(['code'=>1001,'msg'=> "请求发起失败【{$response['message']}】,请选择其他支付方式或联系客服"]);exit;
// redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>$ret[0]['respMess'], 'user_token' => $this->userToken)));exit;
}
} else { // 支付宝第三方 } else { // 支付宝第三方
if( empty(C('goldpig.partner'))||empty(C('goldpig.wooolid'))){ if( empty(C('goldpig.partner'))||empty(C('goldpig.wooolid'))){
// $this->set_message(1009, "fail", "支付参数未配置"); // $this->set_message(1009, "fail", "支付参数未配置");

@ -0,0 +1,64 @@
<?php
namespace Org\OuterPay;
class AlipayApi
{
public static function pay($data, $userInfo, $notifyUrl, $returnUrl) {
$url = "";
$params = [];
$params['user_id'] = (int)$data["user_id"];
$params['user_account'] = $userInfo["account"];
$params['game_id'] = (int)$data["game_id"];
$params['game_name'] = $data['game_name'];
$params['server_id'] = $data["server_id"];
$params['server_name'] = $data["server_name"];
$params['role_id'] = $data["game_player_id"];
$params['role_name'] = $data["game_player_name"];
$params['promote_id'] = (int)$userInfo["promote_id"];
$params['promote_account'] = $userInfo["promote_account"];
$params['order_no'] = $data["pay_order_number"];
$params['pay_amount'] = (int)($data["price"] * 100);
$params['notify_url'] = $notifyUrl;
$params['return_url'] = $returnUrl;
$params['subject'] = '消费#' . $data["pay_order_number"] . "#";
return self::request($url, $params);
}
private static function request($url, $params): array
{
try {
$response = self::post($url, $params);
Log::write('REQUEST_RESPONSE: ' . $response);
return json_decode($response, true);
} catch (\Exception $e) {
Log::write('REQUEST_ERROR: ' . $e->getMessage());
return [
'code' => -999,
'message' => '网络错误',
];
}
}
private static function post($url, $params): string
{
Log::write('REQUEST_URL: ' . json_encode($url));
Log::write('REQUEST_DATA: ' . json_encode($params));
$curl = curl_init();
if (stripos($url, 'https://') !== false){
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
}
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POST, true);
$headers = ['Content-type: application/json'];
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($params));
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
}

@ -0,0 +1,12 @@
<?php
namespace Org\OuterPay;
use Think\Log as ThinkLog;
class Log
{
public static function write($message, $level = ThinkLog::INFO) {
$destination = C('LOG_PATH'). 'outer_pay/' . date('y_m_d').'.log';
ThinkLog::write($message, $level, '', $destination);
}
}
Loading…
Cancel
Save