|
|
<?php
|
|
|
namespace Sdk\Controller;
|
|
|
use Think\Controller;
|
|
|
use Common\Api\GameApi;
|
|
|
use Org\SwiftpassSDK\Swiftpass;
|
|
|
use Org\WeixinSDK\Weixin;
|
|
|
use Org\JtpaySDK\Jtpay;
|
|
|
use Org\GoldPig\GoldPig;
|
|
|
use Org\SqpaySDK\Sqpay;
|
|
|
use Org\HeepaySDK\Heepay;
|
|
|
use Qiniu\json_decode;
|
|
|
use Think\Log;
|
|
|
|
|
|
|
|
|
class AppleController extends BaseController{
|
|
|
|
|
|
/**
|
|
|
*ios移动支付
|
|
|
*/
|
|
|
public function applePay(){
|
|
|
// C(api('Config/lists'));
|
|
|
#获取SDK上POST方式传过来的数据 然后base64解密 然后将json字符串转化成数组
|
|
|
$request = json_decode(base64_decode(file_get_contents("php://input")),true);
|
|
|
if(!is_numeric($request['price'])) {
|
|
|
$this->set_message(0,"fail","金额必须是数字");
|
|
|
}
|
|
|
if($request['price']*1<0) {
|
|
|
$this->set_message(0,"fail","金额不正确");
|
|
|
}
|
|
|
if(C('UC_SET')==1){
|
|
|
if(!is_array(find_uc_account($request['account']))){
|
|
|
$this->set_message(0,"fail","Uc用户暂不支持");
|
|
|
}
|
|
|
}
|
|
|
// 支付验证 是否让支付
|
|
|
$payCheck = pay_check($request['user_id']);
|
|
|
if (!$payCheck['code']) {
|
|
|
$this->set_message(1088, "fail", $payCheck['msg']);
|
|
|
}
|
|
|
$extend_data = M('spend','tab_')->where(array('extend'=>$request['extend'],'game_id'=>$request['game_id'],'pay_status'=>1))->find();
|
|
|
if($extend_data){
|
|
|
$this->set_message(1089,"fail","订单号重复,请关闭支付页面重新支付");
|
|
|
}
|
|
|
file_put_contents("./Application/Sdk/Scheme/".$request['game_id'].".txt",$request['scheme']);
|
|
|
if(pay_set_status('alipay')==1){
|
|
|
$prefix = $request['code'] == 1 ? "SP_" : "PF_";
|
|
|
$out_trade_no = $prefix.date('Ymd').date('His').sp_random_string(4);
|
|
|
$request['pay_order_number'] = $out_trade_no;
|
|
|
$request['pay_status'] = 0;
|
|
|
$request['pay_way'] = 7;
|
|
|
$request['spend_ip'] = get_client_ip();
|
|
|
if(get_game_appstatus2($request['game_id'])){
|
|
|
file_put_contents("./Application/Sdk/OrderNo/".$request['user_id']."-".$request['game_id'].".txt",think_encrypt(json_encode($request)));
|
|
|
echo base64_encode(json_encode(array('status'=>200,'out_trade_no'=>$out_trade_no,'url'=>"http://".$_SERVER['HTTP_HOST'].'/sdk.php/Spend/pay_way/user_id/'.$request['user_id'].'/game_id/'.$request['game_id'].'/type/1')));exit;
|
|
|
}else{
|
|
|
#获取订单信息
|
|
|
if($request['code'] == 1 ){
|
|
|
#TODO添加消费记录
|
|
|
$this->add_spend($request);
|
|
|
}else{
|
|
|
#TODO添加平台币充值记录
|
|
|
$this->add_deposit($request);
|
|
|
}
|
|
|
$data = array("status"=>200,"out_trade_no"=>$out_trade_no,'url'=>'');
|
|
|
echo base64_encode(json_encode($data));
|
|
|
}
|
|
|
}else{
|
|
|
#获取订单信息
|
|
|
$prefix = $request['code'] == 1 ? "SP_" : "PF_";
|
|
|
$out_trade_no = $prefix.date('Ymd').date('His').sp_random_string(4);
|
|
|
$data = array("status"=>200,"out_trade_no"=>$out_trade_no);
|
|
|
$request['pay_order_number'] = $out_trade_no;
|
|
|
$request['pay_status'] = 0;
|
|
|
$request['pay_way'] = 7;
|
|
|
$request['title'] = $request['productId'];
|
|
|
$request['spend_ip'] = get_client_ip();
|
|
|
if($request['code'] == 1 ){
|
|
|
#TODO添加消费记录
|
|
|
$this->add_spend($request);
|
|
|
}else{
|
|
|
#TODO添加平台币充值记录
|
|
|
$this->add_deposit($request);
|
|
|
}
|
|
|
echo base64_encode(json_encode($data));
|
|
|
}
|
|
|
}
|
|
|
/**
|
|
|
*支付宝移动支付
|
|
|
*/
|
|
|
public function apple_alipay_pay($user_id,$game_id){
|
|
|
#获取SDK上POST方式传过来的数据 然后base64解密 然后将json字符串转化成数组
|
|
|
//echo json_encode(['code'=>0,'msg'=> $user_id."game:".$game_id]);exit;
|
|
|
$request = $this->get_sdk_request($game_id, $user_id);
|
|
|
$request['pay_status'] = 0;
|
|
|
$request['pay_way'] = C("PAY_WAY.ALIPAY");
|
|
|
$request['spend_ip'] = get_client_ip();
|
|
|
|
|
|
/* $file=file_get_contents("./Application/Sdk/OrderNo/".$user_id."-".$game_id.".txt");
|
|
|
$request = json_decode(think_decrypt($file),true); */
|
|
|
C(api('Config/lists'));
|
|
|
/*
|
|
|
$request['user_id'] = 1;
|
|
|
$request['game_id'] = 1;
|
|
|
$request['price'] = 1.01;
|
|
|
$request['extend'] = 21111184;
|
|
|
$request['pay_order_number'] = 21111183;
|
|
|
$request['sdk_version'] = 2;
|
|
|
$request['code'] =1;
|
|
|
*/
|
|
|
if (empty($request)) {
|
|
|
echo json_encode(['code'=>0,'msg'=>'登录数据不能为空']);exit;
|
|
|
}
|
|
|
|
|
|
// 支付验证 是否让支付
|
|
|
$payCheck = pay_check($request['user_id']);
|
|
|
if (!$payCheck['code']) {
|
|
|
echo json_encode(['code'=>0,'msg'=> $payCheck['msg']]);exit;
|
|
|
}
|
|
|
|
|
|
$game = M('Game','tab_')->where(['id'=>$request['game_id']])->field('pay_status')->find();
|
|
|
if($game['pay_status'] == 0){
|
|
|
echo json_encode(['code'=>0,'msg'=>'该游戏暂时无法充值,请联系客服!']);exit;
|
|
|
}
|
|
|
if($request['price']*1<=0){
|
|
|
echo json_encode(['code'=>0,'msg'=>'充值金额有误']);exit;
|
|
|
}
|
|
|
$extend_data = M('spend','tab_')->where(array('extend'=>$request['extend'],'game_id'=>$request['game_id']/* ,'pay_status'=>1 */))->find();
|
|
|
if($extend_data){
|
|
|
echo json_encode(['code'=>0,'msg'=>'订单号重复,请关闭支付页面重新支付']);exit;
|
|
|
}
|
|
|
|
|
|
// $this->other_price($request);
|
|
|
|
|
|
if(get_zfb_type()==0 || $request['api_ver'] < 2){ // 支付宝官方
|
|
|
if(C('alipay.way')==1/* || ($request['is_create_ordernumer']==1 && C('alipay.way')==0) */){ /* wap */
|
|
|
|
|
|
$game_set_data = get_game_set_info($request['game_id']);
|
|
|
$request['apitype'] = "alipay";
|
|
|
$request['config'] = "alipay";
|
|
|
$request['signtype']= "MD5";
|
|
|
$request['server'] = "alipay.wap.create.direct.pay.by.user";
|
|
|
$request['payway'] = 1;
|
|
|
$request['title']=$request['price'];
|
|
|
$request['body']=$request['price'];
|
|
|
//$request['callback'] = 'http://'.$_SERVER['HTTP_HOST']. "/sdk.php/Spend/pay_success/orderno/".$request['pay_order_number'].'/game_id/'.$request['game_id'];
|
|
|
//$request['notifyurl'] = 'http://'.$_SERVER['HTTP_HOST']. "/callback.php/Notify/notify/apitype/alipay/method/notify";
|
|
|
$pay_url=$this->pay($request);
|
|
|
//echo $pay_url['url'];die;
|
|
|
//redirect($pay_url['url']);
|
|
|
echo json_encode(['code'=>200,'msg'=>'','data'=>['url'=>$pay_url['url'],'wap'=>1]]);exit;
|
|
|
} else {/* app */
|
|
|
$game_set_data = get_game_set_info($request['game_id']);
|
|
|
$request['apitype'] = "alipay";
|
|
|
$request['config'] = "alipay";
|
|
|
$request['signtype'] = "MD5";
|
|
|
$request['server'] = "mobile.securitypay.pay";
|
|
|
$request['payway'] = 1;
|
|
|
file_put_contents(dirname(__FILE__) .'/alipay.txt',json_encode($request));
|
|
|
$data = $this->alipay_app_pay($request);
|
|
|
$md5_sign = $this->encrypt_md5(base64_encode($data['arg']), $game_set_data["access_key"]);
|
|
|
$data = array("orderInfo" => base64_encode($data['arg']), "out_trade_no" => $data['out_trade_no'], "order_sign" => $data['sign'], "md5_sign" => $md5_sign, "code" => 1);
|
|
|
|
|
|
echo json_encode(['code'=>200,'msg'=>'','data'=>['url'=>json_encode($data),'wap'=>0]]);exit;
|
|
|
}
|
|
|
|
|
|
}elseif(get_zfb_type() == 2) { // 双乾
|
|
|
|
|
|
$request['pay_way'] = C('PAY_WAY.SQ_ALIPAY');
|
|
|
$request['pay_status'] = 0;
|
|
|
$request['spend_ip'] = get_client_ip();
|
|
|
|
|
|
if($request['code']==1){
|
|
|
$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, 0);
|
|
|
}else{
|
|
|
$this->add_deposit($request, 1);
|
|
|
}
|
|
|
$sqpay=new Sqpay();
|
|
|
$returl = C('PAY_DOMAIN'). "/sdk.php/Spend/pay_success/orderno/".$request['pay_order_number'].'/game_id/'.$request['game_id'];
|
|
|
$data['secret'] = C("sqpay.key");
|
|
|
$data['merno'] = C("sqpay.partner");
|
|
|
$data['amount'] = $request['price'];
|
|
|
$data['order_no'] = $request['pay_order_number'];
|
|
|
$data['paymenttype'] = "ZFBZF";
|
|
|
$data['MerRemark'] = "mark";
|
|
|
$data['subject'] = "消费-".$request["pay_order_number"];
|
|
|
$data['notifyurl'] = C('PAY_DOMAIN')."/callback.php/Notify/sq_callback";//通知
|
|
|
$data['returnurl'] = $returl;
|
|
|
$data['mchAppId'] = "hexidongkeji.top";
|
|
|
$data['mchAppName'] = "mchAppName";
|
|
|
$data['deviceInfo'] = "AND_WAP";
|
|
|
$data['clientIp'] = get_client_ip();
|
|
|
|
|
|
$ret = $sqpay->sq_pay($data);
|
|
|
$ret = json_decode($ret, true);
|
|
|
$json_data['url']=$ret[0]['payURL'];
|
|
|
if($ret[0]['respCode'] == '000000'){
|
|
|
echo json_encode(['code'=>200,'msg'=>'','data'=>['url'=>$json_data['url'],'wap'=>1]]);
|
|
|
exit;
|
|
|
} else {
|
|
|
echo json_encode(['code'=>0,'msg'=>$ret[0]['respMess'],'wap'=>1]);
|
|
|
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;
|
|
|
echo json_encode(['code'=>1009,'msg'=>'支付参数未配置']);exit;
|
|
|
}
|
|
|
|
|
|
if($request['price']*1<1){
|
|
|
//redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'单笔充值金额必须大于1元')));exit;
|
|
|
echo json_encode(['code'=>1009,'msg'=>'单笔充值金额必须大于1元']);exit;
|
|
|
}
|
|
|
|
|
|
$table = $request['code'] == 1 ? "spend" : "deposit";
|
|
|
$prefix = $request['code'] == 1 ? "SP_" : "PF_";
|
|
|
// $request['pay_order_number'] =$// $prefix . date('Ymd') . date('His') . sp_random_string(4);
|
|
|
$request['pay_way'] = 8;
|
|
|
$request['pay_status'] = 0;
|
|
|
$request['spend_ip'] = get_client_ip();
|
|
|
//折扣
|
|
|
$user = get_user_entity($request['user_id']);
|
|
|
$discount = $this->get_discount($request['game_id'],$user['promote_id'],$request['user_id']);
|
|
|
$discount = $discount['discount'];
|
|
|
$pay_amount = $discount * $request['price'] / 10;
|
|
|
|
|
|
if($request['code']==1){
|
|
|
$this->add_spend($request,1);
|
|
|
}else{
|
|
|
$this->add_deposit($request, 1);
|
|
|
}
|
|
|
|
|
|
$goldpig=new GoldPig();
|
|
|
$pay_url = $goldpig->GoldPig($user['account'],$pay_amount,26,$request['pay_order_number']);
|
|
|
if($pay_url['status']==0){
|
|
|
//redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>$pay_url['info'])));
|
|
|
echo json_encode(['code'=>0,'msg'=>'','data'=>['url'=>$pay_url['info'],'wap'=>1]]);exit;
|
|
|
}else{
|
|
|
//redirect($pay_url['msg']);
|
|
|
echo json_encode(['code'=>200,'msg'=>'','data'=>['url'=>$pay_url['msg'],'wap'=>1]]);exit;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private function alipay_app_pay($param = array())
|
|
|
{
|
|
|
$table = $param['code'] == 1 ? "spend" : "deposit";
|
|
|
$prefix = $param['code'] == 1 ? "SP_" : "PF_";
|
|
|
$out_trade_no = $prefix . date('Ymd') . date('His') . sp_random_string(4);
|
|
|
$user = get_user_entity($param['user_id']);
|
|
|
switch ($param['apitype']) {
|
|
|
case 'swiftpass':
|
|
|
$pay = new \Think\Pay($param['apitype'], $param['config']);
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
$pay = new \Think\Pay($param['apitype'], C($param['config']));
|
|
|
break;
|
|
|
}
|
|
|
$discount = $this->get_discount($param['game_id'], $user['promote_id'], $param['user_id']);
|
|
|
$discount = $discount['discount'];
|
|
|
// if(!is_check_apply_promote($param['game_id'],$user['promote_id'])){
|
|
|
// $user['promote_id']=0;
|
|
|
// $user['promote_account']="自然注册";
|
|
|
// }
|
|
|
$vo = new \Think\Pay\PayVo();
|
|
|
$vo->setBody("充值记录描述")
|
|
|
->setFee($param['price'])//支付金额
|
|
|
->setTitle($param['title'])
|
|
|
->setBody($param['body'])
|
|
|
->setOrderNo($out_trade_no)
|
|
|
->setRatio(get_game_selle_ratio($param["game_id"]))
|
|
|
->setService($param['server'])
|
|
|
->setSignType($param['signtype'])
|
|
|
->setPayMethod('mobile')
|
|
|
->setTable($table)
|
|
|
->setPayWay($param['payway'])
|
|
|
->setGameId($param['game_id'])
|
|
|
->setGameName(get_game_name($param['game_id']))
|
|
|
->setGameAppid($param['game_appid'])
|
|
|
->setServerId($param['server_id'])
|
|
|
->setGameplayerId($param['game_player_id'])
|
|
|
->setGameplayerName($param['game_player_name'])
|
|
|
->setServerName($param['server_name'])
|
|
|
->setUserId($param['user_id'])
|
|
|
->setAccount($user['account'])
|
|
|
->setUserNickName($user['nickname'])
|
|
|
->setPromoteId($user['promote_id'])
|
|
|
->setPromoteName($user['promote_account'])
|
|
|
->setExtend($param['extend'])
|
|
|
->setSdkVersion($param['sdk_version'])
|
|
|
->setSmallId($param['small_user_id'])
|
|
|
->setSmallAccount(get_user_account_by_id($param['small_user_id']))
|
|
|
->setDiscount($discount);
|
|
|
return $pay->buildRequestForm($vo);
|
|
|
}
|
|
|
|
|
|
|
|
|
private function pay($param=array()){
|
|
|
$table = $param['code'] == 1 ? "spend" : "deposit";
|
|
|
$prefix = $param['code'] == 1 ? "SP_" : "PF_";
|
|
|
$out_trade_no = $prefix.date('Ymd').date('His').sp_random_string(4);
|
|
|
$user = get_user_entity($param['user_id']);
|
|
|
switch ($param['apitype']) {
|
|
|
case 'swiftpass':
|
|
|
$pay = new \Think\Pay($param['apitype'],$param['config']);
|
|
|
break;
|
|
|
default:
|
|
|
$pay = new \Think\Pay($param['apitype'],C($param['config']));
|
|
|
break;
|
|
|
}
|
|
|
$discount = $this->get_discount($param['game_id'],$user['promote_id'],$param['user_id']);
|
|
|
$discount = $discount['discount'];
|
|
|
$vo = new \Think\Pay\PayVo();
|
|
|
$vo->setBody("充值")
|
|
|
->setFee($param['price'])//支付金额
|
|
|
->setTitle($param['title'])
|
|
|
->setOrderNo($out_trade_no)
|
|
|
->setService($param['server'])
|
|
|
->setSignType($param['signtype'])
|
|
|
->setPayMethod("wap")
|
|
|
->setTable($table)
|
|
|
->setPayWay($param['payway'])
|
|
|
->setGameId($param['game_id'])
|
|
|
->setGameName(get_game_name($param['game_id']))
|
|
|
->setGameAppid($param['game_appid'])
|
|
|
->setServerId($param['server_id'])
|
|
|
->setGameplayerId($param['game_player_id'])
|
|
|
->setCallback($param['callback'])
|
|
|
->setNotifyUrl($param['notifyurl'])
|
|
|
->setGameplayerName($param['game_player_name'])
|
|
|
->setServerName($param['server_name'])
|
|
|
->setUserId($param['user_id'])
|
|
|
->setAccount($user['account'])
|
|
|
->setUserNickName($user['nickname'])
|
|
|
->setPromoteId($user['promote_id'])
|
|
|
->setPromoteName($user['promote_account'])
|
|
|
->setExtend($param['extend'])
|
|
|
->setSdkVersion($param['sdk_version'])
|
|
|
->setDiscount($discount)
|
|
|
->setSmallId($param['small_user_id'])
|
|
|
->setSmallAccount(get_user_account_by_id($param['small_user_id']));
|
|
|
if($param['is_uc']==1){
|
|
|
return $pay->buildRequestForm($vo,1);
|
|
|
}else{
|
|
|
$pay_['url']= $pay->buildRequestForm($vo, 0, $param);
|
|
|
$pay_['out_trade_no']= $out_trade_no;
|
|
|
return $pay_;
|
|
|
}
|
|
|
}
|
|
|
/**
|
|
|
*微信支付
|
|
|
*/
|
|
|
public function apple_weixin_pay($user_id,$game_id)
|
|
|
{
|
|
|
$request = $this->get_sdk_request($game_id, $user_id);
|
|
|
$request['pay_status'] = 0;
|
|
|
$request['pay_way'] = C("PAY_WAY.WEIXIN");
|
|
|
$request['spend_ip'] = get_client_ip();
|
|
|
|
|
|
/* $file=file_get_contents("./Application/Sdk/OrderNo/".$user_id."-".$game_id.".txt");
|
|
|
$request = json_decode(think_decrypt($file),true); */
|
|
|
// Log::write("wxpay:".serialize($request));
|
|
|
/*$request['user_id'] = 1;
|
|
|
$request['game_id'] = 1;
|
|
|
$request['price'] = 157.01;
|
|
|
$request['extend'] = 21111178;
|
|
|
$request['pay_order_number'] = 21111178;
|
|
|
$request['sdk_version'] = 2;
|
|
|
$request['code'] =1;
|
|
|
*/
|
|
|
if (empty($request)) {
|
|
|
// $this->set_message(0, "fail", "登录数据不能为空");
|
|
|
redirect(U('Spend/notice_v1',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'登录数据不能为空')));exit;
|
|
|
}
|
|
|
// 支付验证 是否让支付
|
|
|
$payCheck = pay_check($user_id);
|
|
|
if (!$payCheck['code']) {
|
|
|
redirect(U('Spend/notice_v1',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=> $payCheck['msg'])));exit;
|
|
|
}
|
|
|
C(api('Config/lists'));
|
|
|
$game = M('Game','tab_')->where(['id'=>$request['game_id']])->field('pay_status')->find();
|
|
|
if($game['pay_status'] == 0){
|
|
|
redirect(U('Spend/notice_v1',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'该游戏暂时无法充值,请联系客服!')));exit;
|
|
|
}
|
|
|
if($request['price']*1<=0 || $request['price'] > C('WX_PAY_LIMIT')) {
|
|
|
// $this->set_message(0,"fail","充值金额有误");
|
|
|
redirect(U('Spend/notice_v1',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'充值金额有误')));exit;
|
|
|
}
|
|
|
// 微信支付日月限额
|
|
|
if (pay_limit('wx')) {
|
|
|
redirect(U('Spend/notice_v1',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'支付限额,暂不支持')));exit;
|
|
|
}
|
|
|
$extend_data = M('spend','tab_')->where(array('extend'=>$request['extend'],'game_id'=>$request['game_id']/* ,'pay_status'=>1 */))->find();
|
|
|
if($extend_data){
|
|
|
//$this->set_message(1089,"fail","订单号重复,请关闭支付页面重新支付");
|
|
|
redirect(U('Spend/notice_v1',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'订单号重复,请关闭支付页面重新支付')));exit;
|
|
|
}
|
|
|
/* $table = $request['code'] == 1 ? "spend" : "deposit";
|
|
|
$prefix = $request['code'] == 1 ? "SP_" : "PF_";
|
|
|
$request['pay_order_number'] = $prefix."_".date('Ymd').date('His').sp_random_string(4); */
|
|
|
$request['pay_way'] = C('PAY_WAY.WEIXIN');
|
|
|
$request['pay_status'] = 0;
|
|
|
$request['spend_ip'] = get_client_ip();
|
|
|
|
|
|
//折扣
|
|
|
$user = get_user_entity($request['user_id']);
|
|
|
$discount = $this->get_discount($request['game_id'],$user['promote_id'],$request['user_id']);
|
|
|
$discount = $discount['discount'];
|
|
|
$pay_amount = $discount * $request['price'] / 10;
|
|
|
// file_put_contents(dirname(__FILE__).'/1222222.txt',get_wx_pay_type());
|
|
|
// 绑币平台币优先处理
|
|
|
// $this->other_price($request, $discountAmount);
|
|
|
|
|
|
//0 官方 1威富通 2俊付通
|
|
|
if (get_wx_pay_type() == 0) {
|
|
|
$weixn = new Weixin();
|
|
|
$is_pay = json_decode($weixn->weixin_pay(isset($request['title']) ? $request['title']: "充值", $request['pay_order_number'], $pay_amount, 'MWEB'), true);
|
|
|
|
|
|
if($is_pay['status']==1){
|
|
|
if($request['code']==1){
|
|
|
$this->add_spend($request,1, 0);
|
|
|
}else{
|
|
|
$this->add_deposit($request, 1, 0);
|
|
|
}
|
|
|
|
|
|
$json_data['url'] = $is_pay['mweb_url'].'&redirect_url='.(is_ssl()?'https%3A%2F%2F':'http%3A%2F%2F'). $_SERVER ['HTTP_HOST'] . "%2Fsdk.php%2FSpend%2Fpay_success%2Forderno%2F".$request['pay_order_number'].'%2Fgame_id%2F'.$request['game_id'] ;
|
|
|
}else{
|
|
|
redirect(U('Spend/notice_v1',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'支付失败')));exit;
|
|
|
}
|
|
|
}elseif(get_wx_pay_type() == 1){
|
|
|
$request['pay_way'] = 4; // 威富通wx
|
|
|
if($request['code']==1){
|
|
|
$this->add_spend($request,1);
|
|
|
}else{
|
|
|
$this->add_deposit($request, 1);
|
|
|
}
|
|
|
|
|
|
$pay['agent_id'] = C('heepay.partner');//商户号
|
|
|
$pay['order_no'] = $request['pay_order_number'];
|
|
|
$pay['time'] = date('YmdHis', time());
|
|
|
$pay['pay_type'] = 30;
|
|
|
$pay['amount'] = $request['price'];
|
|
|
$pay['user_ip'] = get_client_ip();
|
|
|
$pay['sign_key'] = C('heepay.key');//密钥
|
|
|
$pay['payerName'] = "cs";
|
|
|
$pay['number'] = 1;
|
|
|
$pay['goods_note']="cs";
|
|
|
$pay['device'] = "wap";
|
|
|
$pay['bank_card_type'] = 0;
|
|
|
$pay['return_url'] ='http://' . $_SERVER ['HTTP_HOST'] . "/sdk.php/Spend/pay_success/orderno/".$pay['order_no'].'/game_id/'.$request['game_id'];
|
|
|
$heepay = new Heepay();
|
|
|
$url = $heepay->wxh5_pay($pay);
|
|
|
$json_data['url'] = $url;
|
|
|
|
|
|
}elseif(get_wx_pay_type() == 2){
|
|
|
|
|
|
if($request['code']==1){
|
|
|
$this->add_spend($request,1);
|
|
|
}else{
|
|
|
$this->add_deposit($request, 1);
|
|
|
}
|
|
|
|
|
|
$jtpay=new Jtpay();
|
|
|
|
|
|
$json_data['url']=$jtpay->jt_pay($request['pay_order_number'],$pay_amount,$user['account'],get_client_ip(),"sdk",3,'http://' . $_SERVER ['HTTP_HOST'] . "/sdk.php/Spend/pay_success2/orderno/".$request['pay_order_number'].'/game_id/'.$request['game_id'],3,2);//ios
|
|
|
|
|
|
}elseif(get_wx_pay_type() == 3){
|
|
|
if( empty(C('goldpig.partner'))||empty(C('goldpig.wooolid'))){
|
|
|
// $this->set_message(1009, "fail", "支付参数未配置");
|
|
|
redirect(U('Spend/notice_v1',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'支付参数未配置')));exit;
|
|
|
}
|
|
|
$request['pay_way'] = 8;
|
|
|
|
|
|
if($pay_amount*1<1){
|
|
|
redirect(U('Spend/notice_v1',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'单笔充值金额必须大于1元')));exit;
|
|
|
}
|
|
|
|
|
|
if($request['code']==1){
|
|
|
$this->add_spend($request,1);
|
|
|
}else{
|
|
|
$this->add_deposit($request, 1);
|
|
|
}
|
|
|
|
|
|
/*$goldpig=new GoldPig();
|
|
|
$res = $goldpig->GoldPig($user['account'],$pay_amount,29,$request['pay_order_number']);
|
|
|
if($res['status']==1){
|
|
|
$json_data['url']=$res['msg'];
|
|
|
}else{
|
|
|
$json_data['url']='http://'.$_SERVER ['HTTP_HOST'];
|
|
|
}*/
|
|
|
$wooolid = C('goldpig.wooolid');
|
|
|
$baseurl = 'http://api.357p.com/?';
|
|
|
$url = $baseurl . "UserName={$user['account']}&Price={$pay_amount}&shouji={$request['shouji']}&PayID=29&userid={$request['user_id']}&wooolID={$wooolid}&jinzhua={$request['pay_order_number']}&jinzhub={$request['jinzhub']}&jinzhuc={$request['jinzhuc']}&jinzhue={$request['pay_order_number']}";
|
|
|
$json_data['url'] = $url;
|
|
|
}elseif(get_wx_pay_type() == 4){
|
|
|
$data = array("orderInfo" => base64_encode($data['arg']), "out_trade_no" => $data['out_trade_no'], "order_sign" => $data['sign'], "md5_sign" => $md5_sign);
|
|
|
|
|
|
echo json_encode(['code'=>200,'msg'=>'','data'=>['url'=>json_encode($data),'wap'=>0]]);exit;
|
|
|
|
|
|
|
|
|
$request['pay_way'] = C("PAY_WAY.SQ_SMALL_PROGRAM"); // 双乾微信小程序
|
|
|
if($request['code']==1){
|
|
|
$this->add_spend($request,1);
|
|
|
}else{
|
|
|
$this->add_deposit($request, 1);
|
|
|
}
|
|
|
|
|
|
$pay['agent_id'] = C('heepay.partner');//商户号
|
|
|
$pay['order_no'] = $request['pay_order_number'];
|
|
|
$pay['time'] = date('YmdHis', time());
|
|
|
$pay['pay_type'] = 30;
|
|
|
$pay['amount'] = $request['price'];
|
|
|
$pay['user_ip'] = get_client_ip();
|
|
|
$pay['sign_key'] = C('heepay.key');//密钥
|
|
|
$pay['payerName'] = "cs";
|
|
|
$pay['number'] = 1;
|
|
|
$pay['goods_note']="cs";
|
|
|
$pay['device'] = "wap";
|
|
|
$pay['bank_card_type'] = 0;
|
|
|
$pay['return_url'] ='http://' . $_SERVER ['HTTP_HOST'] . "/sdk.php/Spend/pay_success/orderno/".$pay['order_no'].'/game_id/'.$request['game_id'];
|
|
|
$sqpay = new Sqpay();
|
|
|
// @todo: sq_pay
|
|
|
$url = $sqpay->sq_wxsmallpay($order_no);
|
|
|
$json_data['url'] = $url;
|
|
|
|
|
|
}else{
|
|
|
$Swiftpass=new Swiftpass(C('weixin_gf.partner'),C('weixin_gf.key'));
|
|
|
$param['service']="pay.weixin.wappay";
|
|
|
$param['ip']= $request['spend_ip'];
|
|
|
$param['pay_amount']=$pay_amount;//;
|
|
|
$param['out_trade_no']= $request['pay_order_number'];
|
|
|
$param['game_name']= get_game_name($request['game_id']);
|
|
|
$param['body']="游戏充值";
|
|
|
$param['callback_url']='http://' . $_SERVER ['HTTP_HOST'] . "/sdk.php/Spend/pay_success/orderno/".$request['pay_order_number'].'/game_id/'.$request['game_id'];
|
|
|
$url=$Swiftpass->submitOrderInfo($param);
|
|
|
if($url['status']==0){
|
|
|
$request['pay_way'] = 4;
|
|
|
if($request['code']==1){
|
|
|
$this->add_spend($request,1);
|
|
|
}else{
|
|
|
$this->add_deposit($request, 1);
|
|
|
}
|
|
|
$json_data['url']=$url['pay_info'];
|
|
|
}else{
|
|
|
$json_data['url']='http://'.$_SERVER ['HTTP_HOST'];
|
|
|
}
|
|
|
}
|
|
|
redirect($json_data['url']);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 银联支付
|
|
|
*/
|
|
|
public function apple_union_pay($user_id,$game_id)
|
|
|
{
|
|
|
$file=file_get_contents("./Application/Sdk/OrderNo/".$user_id."-".$game_id.".txt");
|
|
|
$request = json_decode(think_decrypt($file),true);
|
|
|
/* $request['user_id'] = 1;
|
|
|
$request['game_id'] = 1;
|
|
|
$request['price'] = 0.02;
|
|
|
$request['code'] = 1;
|
|
|
$request['extend'] = "11212452299229";
|
|
|
$request['pay_order_number'] = "11212452299229"; */
|
|
|
|
|
|
if (empty($request)) {
|
|
|
redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'登录数据不能为空')));exit;
|
|
|
}
|
|
|
// 支付验证 是否让支付
|
|
|
$payCheck = pay_check($request['user_id']);
|
|
|
if (!$payCheck['code']) {
|
|
|
redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>$payCheck['msg'])));exit;
|
|
|
}
|
|
|
$game = M('Game','tab_')->where(['id'=>$request['game_id']])->field('pay_status')->find();
|
|
|
if($game['pay_status'] == 0){
|
|
|
redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'该游戏暂时无法充值,请联系客服!')));exit;
|
|
|
}
|
|
|
if($request['price']*1<=0){
|
|
|
redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'充值金额有误')));exit;
|
|
|
}
|
|
|
|
|
|
C(api('Config/lists'));
|
|
|
|
|
|
$extend_data = M('spend','tab_')->where(array('extend'=>$request['extend'],'game_id'=>$request['game_id'],'game_status'=>1))->find();
|
|
|
if($extend_data){
|
|
|
redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>$request['game_id'].'订单号重复,请关闭支付页面重新支付'.$request['extend'])));exit;
|
|
|
}
|
|
|
|
|
|
$request['pay_way'] = 10; // 支付方式(-1绑币 0:平台币,1:支付宝,2:微信(扫码)3微信app 4 威富通 5聚宝云 6竣付通 7苹果支付8金猪支付 9双乾支付-支付宝 10双乾支付-银联
|
|
|
$request['pay_status'] = 0;
|
|
|
$request['spend_ip'] = get_client_ip();
|
|
|
$out_trade_no = $request['pay_order_number'];
|
|
|
//折扣
|
|
|
$user = get_user_entity($request['user_id']);
|
|
|
$discount = $this->get_discount($request['game_id'],$user['promote_id'],$request['user_id']);
|
|
|
$discount = $discount['discount'];
|
|
|
$pay_amount = $discount * $request['price'] / 10;
|
|
|
if ($pay_amount < 0.01) {
|
|
|
redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'充值金额有误.'.$pay_amount)));exit;
|
|
|
}
|
|
|
|
|
|
// file_put_contents(dirname(__FILE__).'/1222222.txt',get_wx_pay_type());
|
|
|
//0 官方 1双乾
|
|
|
if (get_union_pay_type() == 0) {
|
|
|
// 暂时只有双乾
|
|
|
}elseif(get_union_pay_type() == 1){
|
|
|
|
|
|
if($request['code']==1){
|
|
|
$this->add_spend($request,1);
|
|
|
}else{
|
|
|
$this->add_deposit($request, 1);
|
|
|
}
|
|
|
$sqpay=new Sqpay();
|
|
|
$returl = 'http://' . $_SERVER ['HTTP_HOST'] . "/sdk.php/Spend/pay_success/orderno/".$request['pay_order_number'].'/game_id/'.$request['game_id'];
|
|
|
$data['secret'] = C("sqpay.key");
|
|
|
$data['merno'] = C("sqpay.partner");
|
|
|
$data['amount'] = $request['price'];
|
|
|
$data['order_no'] = $request['pay_order_number'];
|
|
|
$data['paymenttype'] = "UNION";
|
|
|
$data['MerRemark'] = "mark";
|
|
|
$data['subject'] = "subject";
|
|
|
$data['notifyurl'] = "http://"."api.hexidongkeji.top"."/callback.php/Notify/sq_callback";//通知
|
|
|
$data['returnurl'] = $returl;
|
|
|
$data['mchAppId'] = "hexidongkeji.top";
|
|
|
$data['mchAppName'] = "mchAppName";
|
|
|
$data['deviceInfo'] = "AND_WAP";
|
|
|
$data['clientIp'] = get_client_ip();
|
|
|
|
|
|
$ret = $sqpay->sq_pay($data);
|
|
|
$ret = json_decode($ret, true);
|
|
|
$json_data['url']=$ret[0]['payHtml'];
|
|
|
echo ($json_data['url']);
|
|
|
exit();
|
|
|
}
|
|
|
// redirect($json_data['url']);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 平台币支付
|
|
|
* @author 鹿文学
|
|
|
*/
|
|
|
public function apple_platform_pay($user_id,$game_id) {
|
|
|
/* $file=file_get_contents("./Application/Sdk/OrderNo/".$user_id."-".$game_id.".txt");
|
|
|
$request = json_decode(think_decrypt($file),true); */
|
|
|
|
|
|
$request = $this->get_sdk_request($game_id, $user_id);
|
|
|
$request['pay_status'] = 0;
|
|
|
// $request['pay_way'] = C("PAY_WAY.ALIPAY");
|
|
|
$request['spend_ip'] = get_client_ip();
|
|
|
$out_trade_no = $request['pay_order_number'];
|
|
|
|
|
|
$code = $_POST['way'];
|
|
|
|
|
|
if (empty($request)) {
|
|
|
redirect(U('Spend/notice_v1',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'参数错误')));exit;
|
|
|
}
|
|
|
// 支付验证 是否让支付
|
|
|
$payCheck = pay_check($request['user_id']);
|
|
|
if (!$payCheck['code']) {
|
|
|
redirect(U('Spend/notice_v1',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=> $payCheck['msg'])));exit;
|
|
|
}
|
|
|
C(api('Config/lists'));
|
|
|
$user_info = get_user_entity($request['user_id']);
|
|
|
if($user_info['lock_status'] == 0 || $user_info['check_status'] == 0){
|
|
|
redirect(U('Spend/notice_v1',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'账号被禁用,无法充值,请联系客服!')));exit;
|
|
|
}
|
|
|
$game = M('Game','tab_')->where(['id'=>$request['game_id']])->field('pay_status')->find();
|
|
|
if($game['pay_status'] == 0){
|
|
|
redirect(U('Spend/notice_v1',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'该游戏暂时无法充值,请联系客服!')));exit;
|
|
|
}
|
|
|
if($request['price']*1<=0){
|
|
|
// $this->set_message(0,"fail","充值金额有误");
|
|
|
redirect(U('Spend/notice_v1',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'充值金额有误')));exit;
|
|
|
}
|
|
|
$extend_data = M('spend','tab_')->where(array('extend'=>$request['extend'],'game_id'=>$request['game_id']/* ,'pay_status'=>1 */))->find();
|
|
|
if($extend_data){
|
|
|
// $this->set_message(1089,"fail","订单号重复,请关闭支付页面重新支付");
|
|
|
redirect(U('Spend/notice_v1',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'订单号重复,请关闭支付页面重新支付')));exit;
|
|
|
}
|
|
|
$request['order_number'] = $out_trade_no;
|
|
|
$request['pay_order_number'] = $out_trade_no;
|
|
|
$request['out_trade_no'] = $out_trade_no;
|
|
|
$request['title'] = $request['title'];
|
|
|
$request['pay_status'] = 1;
|
|
|
$request['pay_way'] = 0;
|
|
|
$request['spend_ip'] = get_client_ip();
|
|
|
$user_entity = get_user_entity($request['user_id']);
|
|
|
$discount_arr = $this->get_discount($request['game_id'], $user_entity['promote_id'], $request['user_id']);
|
|
|
$discount = $discount_arr['discount'];
|
|
|
$user = M("user", "tab_");
|
|
|
//添加黑名单
|
|
|
$check_deposit_money = $this->check_deposit_money($user_entity);
|
|
|
$check_bind_money = $this->check_bind_money($user_entity);
|
|
|
if($check_deposit_money === false || $check_bind_money === false || (C('BRUSH_MONEY') && (abs($check_deposit_money)>=C('BRUSH_MONEY') || abs($check_bind_money)>=C('BRUSH_MONEY'))) || (!C('BRUSH_MONEY') && (abs($check_deposit_money) != 0 || abs($check_bind_money) != 0))){
|
|
|
if(C('BRUSH_SMS_STATUS') && C('BRUSH_PHONE')&& C('BRUSH_SMS_ID')){
|
|
|
$this-> send_block(C('BRUSH_PHONE'),$user_entity['account']);
|
|
|
}
|
|
|
$block_data['check_status'] = 0;
|
|
|
$block_data['block_time'] = time();
|
|
|
$user->where(['id'=>$user_entity['id']])->save($block_data);
|
|
|
redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'您的账号暂时无法充值,请联系客服处理')));exit;
|
|
|
exit();
|
|
|
}
|
|
|
|
|
|
$result = false;
|
|
|
|
|
|
switch ($code) {
|
|
|
case 1:#非绑定平台币
|
|
|
$real_price = $request['price'] * $discount / 10;
|
|
|
if ($user_entity['balance'] < $real_price) {
|
|
|
|
|
|
$data = array('discount'=>$discount,"real_price"=>$real_price,'balance'=>$user_entity['balance']);
|
|
|
|
|
|
// $this->set_message(1076,"fail","余额不足");
|
|
|
redirect(U('Spend/notice_v1',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'余额不足')));exit;
|
|
|
exit();
|
|
|
}
|
|
|
//防刷预警
|
|
|
if(C('BRUSH_PTB') && $user_entity['balance'] >= C('BRUSH_PTB') && C('BRUSH_EMAIL') && C('BRUSH_EMAIL_STATUS') ){
|
|
|
$content = "尊敬的用户:<br/> 系统检测到玩家【".$user_entity['account']."】账户平台币".$user_entity['balance'].",超出上限".C('BRUSH_PTB').",可能存在异常,请尽快处理。";
|
|
|
sendBrushMail(C('BRUSH_EMAIL'),$content);
|
|
|
}
|
|
|
if(C('BRUSH_PTB_TIME') && C('BRUSH_PTB_COUNT') && C('BRUSH_EMAIL') && C('BRUSH_EMAIL_STATUS')){
|
|
|
$where['pay_time'] = ['between',[time()-C('BRUSH_PTB_TIME')*60,time()]];
|
|
|
$where['user_id'] = $user_entity['id'];
|
|
|
$where['pay_status'] = 1;
|
|
|
$where['pay_way'] = 0;
|
|
|
$spend_count = M('spend','tab_')->where($where)->count('id');
|
|
|
$spend_count += 1;
|
|
|
if($spend_count > C('BRUSH_PTB_COUNT')){
|
|
|
$content = "尊敬的用户:<br/> 系统检测到玩家【".$user_entity['account']."】在".date('Y-m-d H:i:s',time()-C('BRUSH_PTB_TIME')*60)."-".date('Y-m-d H:i:s')."期间累计平台币消费".$spend_count."次,可能存在异常,请尽快处理。";
|
|
|
sendBrushMail(C('BRUSH_EMAIL'),$content);
|
|
|
}
|
|
|
}
|
|
|
#扣除平台币
|
|
|
$user->where("id=" . $request["user_id"])->setDec("balance", $real_price);
|
|
|
#TODO 添加绑定平台币消费记录
|
|
|
$result = $this->add_spend($request,1);
|
|
|
#检查返利设置
|
|
|
$this->set_ratio($request['pay_order_number']);
|
|
|
break;
|
|
|
case 2:#绑定平台币
|
|
|
$request['pay_way'] = -1;
|
|
|
$user_play = M("UserPlay", "tab_");
|
|
|
$user_play_map['user_id'] = $request['user_id'];
|
|
|
$user_play_map['game_id'] = $request['game_id'];
|
|
|
$user_play_data = $user_play->where($user_play_map)->find();
|
|
|
|
|
|
if ($user_play_data['bind_balance'] < $request['price']) {
|
|
|
// $this->set_message(1076,"fail","余额不足");
|
|
|
redirect(U('Spend/notice_v1',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'余额不足')));exit;
|
|
|
exit();
|
|
|
}
|
|
|
#扣除平台币
|
|
|
$user_play->where($user_play_map)->setDec("bind_balance", $request['price']);
|
|
|
#TODO 添加绑定平台币消费记录
|
|
|
$result = $this->add_spend($request,1);
|
|
|
#检查返利设置
|
|
|
$this->set_ratio($request['pay_order_number'],2);
|
|
|
break;
|
|
|
default:
|
|
|
// $this->set_message(1081,"fail","支付方式不明确");
|
|
|
redirect(U('Spend/notice_v1',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'支付方式不明确')));exit;
|
|
|
exit();
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
$game = new GameApi();
|
|
|
$game->game_pay_notify($request, $request['code']);
|
|
|
|
|
|
$url = 'http://' . $_SERVER ['HTTP_HOST'] . "/sdk.php/Spend/pay_success3/orderno/".$request['pay_order_number'].'/game_id/'.$request['game_id'];
|
|
|
|
|
|
redirect($url);
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
/*
|
|
|
* 平台币抵扣
|
|
|
* 优先抵扣绑币 平台币 调这个接口说明 不走第三方支付通道
|
|
|
*/
|
|
|
public function platform_coin_deduction($user_id, $game_id) {
|
|
|
$file=file_get_contents("./Application/Sdk/OrderNo/".$user_id."-".$game_id.".txt");
|
|
|
$request = json_decode(think_decrypt($file),true);
|
|
|
|
|
|
if (empty($request)) {
|
|
|
redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'参数错误')));exit;
|
|
|
}
|
|
|
// 支付验证 是否让支付
|
|
|
$payCheck = pay_check($request['user_id']);
|
|
|
if (!$payCheck['code']) {
|
|
|
redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=> $payCheck['msg'])));exit;
|
|
|
}
|
|
|
|
|
|
if ($request['price'] *1<=0) {
|
|
|
redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'充值金额有误')));exit;
|
|
|
}
|
|
|
$request['price'] = abs($request['price']);
|
|
|
$extend_data = M('spend','tab_')->where(array('extend'=>$request['extend'],'pay_status'=>1,'game_id'=>$request['game_id']))->find();
|
|
|
if($extend_data){
|
|
|
redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'订单号重复,请关闭支付页面重新支付')));exit;
|
|
|
}
|
|
|
$user_info = get_user_entity($request['user_id']);
|
|
|
if($user_info['lock_status'] == 0 || $user_info['check_status'] == 0){
|
|
|
redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'账号被禁用,无法充值,请联..系客服!')));exit;
|
|
|
}
|
|
|
$game = M('Game','tab_')->where(['id'=>$request['game_id']])->field('pay_status')->find();
|
|
|
if($game['pay_status'] == 0){
|
|
|
redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'该游戏暂时无法充值,请联系客服!')));exit;
|
|
|
}
|
|
|
$out_trade_no = "PF_" . date('Ymd') . date('His') . sp_random_string(4);
|
|
|
$request['order_number'] = $out_trade_no;
|
|
|
$request['pay_order_number'] = $out_trade_no;
|
|
|
$request['out_trade_no'] = $out_trade_no;
|
|
|
$request['title'] = $request['title'];
|
|
|
$request['pay_status'] = 1;
|
|
|
$request['pay_way'] = 0;
|
|
|
$request['spend_ip'] = get_client_ip();
|
|
|
$user_entity = get_user_entity($request['user_id']);
|
|
|
$discount_arr = $this->get_discount($request['game_id'], $user_entity['promote_id'], $request['user_id']);
|
|
|
$discount = $discount_arr['discount'];
|
|
|
$user = M("user", "tab_");
|
|
|
//添加黑名单
|
|
|
$check_deposit_money = $this->check_deposit_money($user_entity);
|
|
|
$check_bind_money = $this->check_bind_money($user_entity);
|
|
|
if($check_deposit_money === false || $check_bind_money === false || (C('BRUSH_MONEY') && (abs($check_deposit_money)>=C('BRUSH_MONEY') || abs($check_bind_money)>=C('BRUSH_MONEY'))) || (!C('BRUSH_MONEY') && (abs($check_deposit_money) != 0 || abs($check_bind_money) != 0))){
|
|
|
if(C('BRUSH_SMS_STATUS') && C('BRUSH_PHONE')&& C('BRUSH_SMS_ID')){
|
|
|
$result = $this-> send_block(C('BRUSH_PHONE'),$user_entity['account']);
|
|
|
}
|
|
|
$block_data['check_status'] = 0;
|
|
|
$block_data['block_time'] = time();
|
|
|
$user->where(['id'=>$user_entity['id']])->save($block_data);
|
|
|
redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'您的账号暂时无法充值,请联系客服处理.')));exit;
|
|
|
}
|
|
|
$result = false;
|
|
|
// 先扣绑币
|
|
|
$request['pay_way'] = -1;
|
|
|
$user_play = M("UserPlay", "tab_");
|
|
|
$user_play_map['user_id'] = $request['user_id'];
|
|
|
$user_play_map['game_id'] = $request['game_id'];
|
|
|
$user_play_data = $user_play->where($user_play_map)->find();
|
|
|
$balance = $user->where(array('id' => $request['user_id']))->getField("balance");
|
|
|
if ($balance + $user_play_data['bind_balance'] < $request['price']) {
|
|
|
redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'您金额不足,请退出重试.')));exit;
|
|
|
}
|
|
|
if ($user_play_data['bind_balance'] < $request['price']) {
|
|
|
$price = $request['price'];
|
|
|
if ($user_play_data['bind_balance'] > 0) {
|
|
|
$user_play->where($user_play_map)->save(array('bind_balance' => 0)); // 扣绑定币
|
|
|
$request['price'] = $user_play_data['bind_balance'];
|
|
|
$result = $this->add_spend($request);
|
|
|
$this->set_ratio($request['pay_order_number'], 2); // 游戏返利
|
|
|
}
|
|
|
$request['pay_way'] = 0; // 扣平台币
|
|
|
$real_price = $price - $user_play_data['bind_balance'];
|
|
|
$user->where(array('id' => $request["user_id"]))->setDec("balance", $real_price);
|
|
|
//$this->set_message(0,"fail", $request['pay_order_number']);
|
|
|
|
|
|
$request['pay_order_number'] = $request['pay_order_number']."_1";
|
|
|
$request['price'] = $real_price;
|
|
|
$result = $this->add_spend($request);
|
|
|
$this->set_ratio($request['pay_order_number'], 1); // 游戏返利
|
|
|
} else { // 绑定币足够扣
|
|
|
$user_play->where($user_play_map)->setDec('bind_balance', $request['price']); // 扣绑定币
|
|
|
$result = $this->add_spend($request);
|
|
|
$this->set_ratio($request['pay_order_number'], 2); // 游戏返利
|
|
|
}
|
|
|
|
|
|
$game = new GameApi();
|
|
|
$game->game_pay_notify($request, $request['code']);
|
|
|
$url = 'http://' . $_SERVER ['HTTP_HOST'] . "/sdk.php/Spend/pay_success3/orderno/".$request['pay_order_number'].'/game_id/'.$request['game_id'];
|
|
|
|
|
|
redirect($url);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
*苹果支付验证
|
|
|
*/
|
|
|
public function appleVerify(){
|
|
|
#获取SDK上POST方式传过来的数据 然后base64解密 然后将json字符串转化成数组
|
|
|
$request = json_decode(base64_decode(file_get_contents("php://input")),true);
|
|
|
//开始执行验证
|
|
|
try
|
|
|
{
|
|
|
$data = $this->getSignVeryfy($request, 1);
|
|
|
$info = json_decode($data,true);
|
|
|
if($info['status']==21007){
|
|
|
$data = $this->getSignVeryfy($request, 2);
|
|
|
$info = json_decode($data,true);
|
|
|
}
|
|
|
if($info['status'] == 0){
|
|
|
$paperVerify=M('spend','tab_')->field('id,order_number')->where(array('pay_way'=>7,'order_number'=>$info['receipt']['transaction_id']))->find();
|
|
|
if($paperVerify){
|
|
|
echo base64_encode(json_encode(array("status"=>0,"return_code"=>"fail","return_msg"=>"凭证重复")));
|
|
|
exit();
|
|
|
}
|
|
|
if($request['price']*1<0) {
|
|
|
echo base64_encode(json_encode(array("status"=>0,"return_code"=>"fail","return_msg"=>"金额不正确")));
|
|
|
exit();
|
|
|
}
|
|
|
$out_trade_no = $request['out_trade_no'];
|
|
|
$pay_where = substr($out_trade_no,0,2);
|
|
|
$result = 0;
|
|
|
$map['pay_order_number'] = $out_trade_no;
|
|
|
$payamountVerify=M('spend','tab_')->field('id,pay_order_number,extend,pay_amount')->where($map)->find();
|
|
|
if($payamountVerify['pay_amount']!=$request['price']){
|
|
|
$disdata=array();
|
|
|
$disdata['spend_id']=$payamountVerify['id'];
|
|
|
$disdata['pay_order_number']=$payamountVerify['pay_order_number'];
|
|
|
$disdata['extend']=$payamountVerify['extend'];
|
|
|
$disdata['last_amount']=$request['price'];
|
|
|
$disdata['currency']=$request['currency'];
|
|
|
$disdata['create_time']=NOW_TIME;
|
|
|
$pay_distinction=M('spend_distinction','tab_')->add($disdata);
|
|
|
if(!$pay_distinction){
|
|
|
\Think\Log::record('数据插入失败 pay_order_number'.$payamountVerify['pay_order_number']);
|
|
|
}
|
|
|
}
|
|
|
$field = array("pay_status"=>1,"pay_amount"=>$request['price'],"receipt"=>$data,"order_number"=>$info['receipt']['transaction_id']);
|
|
|
switch ($pay_where) {
|
|
|
case 'SP':
|
|
|
$result = M('spend','tab_')->where($map)->setField($field);
|
|
|
$param['out_trade_no'] = $out_trade_no;
|
|
|
$game = new GameApi();
|
|
|
$game->game_pay_notify($param);
|
|
|
break;
|
|
|
case 'PF':
|
|
|
$result = M('deposit','tab_')->where($map)->setField($field);
|
|
|
break;
|
|
|
case 'AG':
|
|
|
$result = M('agent','tab_')->where($map)->setField($field);
|
|
|
break;
|
|
|
default:
|
|
|
exit('accident order data');
|
|
|
break;
|
|
|
}
|
|
|
if($result){
|
|
|
$this->set_ratio($out_trade_no);
|
|
|
echo base64_encode(json_encode(array("status"=>200,"return_code"=>"success","return_msg"=>"支付成功")));
|
|
|
exit();
|
|
|
}else{
|
|
|
echo base64_encode(json_encode(array("status"=>0,"return_code"=>"fail","return_msg"=>"支付状态修改失败")));
|
|
|
exit();
|
|
|
}
|
|
|
}else{
|
|
|
echo base64_encode(json_encode(array("status"=>0,"return_code"=>"fail","return_msg"=>"支付失败")));
|
|
|
exit();
|
|
|
}
|
|
|
}
|
|
|
//捕获异常
|
|
|
catch(Exception $e)
|
|
|
{
|
|
|
echo 'Message: ' .$e->getMessage();
|
|
|
}
|
|
|
}
|
|
|
private function getSignVeryfy($receipt, $isSandbox = 1){
|
|
|
if ($isSandbox==2) {
|
|
|
$endpoint = 'https://sandbox.itunes.apple.com/verifyReceipt';
|
|
|
}
|
|
|
else {
|
|
|
$endpoint = 'https://buy.itunes.apple.com/verifyReceipt';
|
|
|
}
|
|
|
$postData = json_encode(
|
|
|
array('receipt-data' => $receipt["paper"])
|
|
|
);
|
|
|
$ch = curl_init($endpoint);
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
curl_setopt($ch, CURLOPT_POST, true);
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
|
|
|
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0); //这两行一定要加,不加会报SSL 错误
|
|
|
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
|
|
|
$response = curl_exec($ch);
|
|
|
$errno = curl_errno($ch);
|
|
|
$errmsg = curl_error($ch);
|
|
|
curl_close($ch);
|
|
|
//判断时候出错,抛出异常
|
|
|
if ($errno != 0) {
|
|
|
throw new \Think\Exception($errmsg, $errno);
|
|
|
}
|
|
|
return $response;
|
|
|
}
|
|
|
}
|