diff --git a/Application/Callback/Controller/NotifyController.class.php b/Application/Callback/Controller/NotifyController.class.php index 3caae94..ccd87f7 100644 --- a/Application/Callback/Controller/NotifyController.class.php +++ b/Application/Callback/Controller/NotifyController.class.php @@ -11,6 +11,7 @@ use Sdk\Controller\Ipa365Controller; use Base\Tool\Redis; use Org\Kudian\Response as KDResponse; use Org\Kudian\Log as KDLog; +use Org\OuterPay\Log as OuterPayLog; /** * 支付回调控制器 @@ -968,4 +969,42 @@ class NotifyController extends BaseController } 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'; + } } \ No newline at end of file diff --git a/Application/Sdk/Controller/PayH5Controller.class.php b/Application/Sdk/Controller/PayH5Controller.class.php index 617e18e..de50dd5 100644 --- a/Application/Sdk/Controller/PayH5Controller.class.php +++ b/Application/Sdk/Controller/PayH5Controller.class.php @@ -15,7 +15,7 @@ use Sdk\Model\PayLimitConfModel; use Sdk\Model\PayChannelInterntionModel; use Sdk\Model\PayChannelIntentionModel; use Org\Kudian\Api as KDApi; - +use Org\OuterPay\AlipayApi; class PayH5Controller extends BaseController{ const ALI_PAY = 1; @@ -584,8 +584,45 @@ 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; } + } 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"]); - } else{ // 支付宝第三方 + $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 { // 支付宝第三方 if( empty(C('goldpig.partner'))||empty(C('goldpig.wooolid'))){ // $this->set_message(1009, "fail", "支付参数未配置"); //redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'支付参数未配置')));exit; diff --git a/ThinkPHP/Library/Org/OuterPay/AlipayApi.class.php b/ThinkPHP/Library/Org/OuterPay/AlipayApi.class.php new file mode 100644 index 0000000..4dd6936 --- /dev/null +++ b/ThinkPHP/Library/Org/OuterPay/AlipayApi.class.php @@ -0,0 +1,64 @@ +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; + } +} \ No newline at end of file diff --git a/ThinkPHP/Library/Org/OuterPay/Log.class.php b/ThinkPHP/Library/Org/OuterPay/Log.class.php new file mode 100644 index 0000000..1af71cc --- /dev/null +++ b/ThinkPHP/Library/Org/OuterPay/Log.class.php @@ -0,0 +1,12 @@ +