From a6c99cda3afee61fa202645f52603276bd390963 Mon Sep 17 00:00:00 2001 From: tpingzhang <635929049@qq.com> Date: Thu, 17 Oct 2019 17:04:44 +0800 Subject: [PATCH] =?UTF-8?q?1=EF=BC=8C=E4=BF=AE=E6=94=B9server=5Fid?= =?UTF-8?q?=E4=BC=A00=20=20=E5=A2=9E=E5=8A=A0game=5Fplayer=5Fid=202?= =?UTF-8?q?=EF=BC=8C=E5=BE=AE=E4=BF=A1=E9=99=90=E9=A2=9D=E3=80=8B=3D3000?= =?UTF-8?q?=203=EF=BC=8C=E5=B0=8F=E7=A8=8B=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sdk/Controller/WapPayController.class.php | 116 ++++++++++++++++-- ThinkPHP/Library/Think/Pay/PayVo.class.php | 15 +++ 2 files changed, 118 insertions(+), 13 deletions(-) diff --git a/Application/Sdk/Controller/WapPayController.class.php b/Application/Sdk/Controller/WapPayController.class.php index 50600d2a8..e66462acc 100644 --- a/Application/Sdk/Controller/WapPayController.class.php +++ b/Application/Sdk/Controller/WapPayController.class.php @@ -11,7 +11,7 @@ use Org\GoldPig\GoldPig; use Org\SqpaySDK\Sqpay; use Qiniu\json_decode; use Think\Log; -class WapPayController extends BaseController{ +class WapPayController extends BaseController{ private function pay($param=array()){ $table = $param['code'] == 1 ? "spend" : "deposit"; @@ -41,7 +41,8 @@ class WapPayController extends BaseController{ ->setGameId($param['game_id']) ->setGameName(get_game_name($param['game_id'])) ->setGameAppid($param['game_appid']) - ->setServerId(0) + ->setServerId($param['server_id']) + ->setGamePlayerId($param['game_player_id']) ->setGameplayerName($param['game_player_name']) ->setServerName($param['server_name']) ->setUserId($param['user_id']) @@ -452,7 +453,7 @@ class WapPayController extends BaseController{ $game_id = $request['game_id']; $data = array( 'status' => 200, - "url" => 'http://api.wmtxkj.com'."/sdk.php/WapPay/wap_shortcut_pay/user_id/{$user_id}/game_id/{$game_id}", + "url" => 'http://' . $_SERVER ['HTTP_HOST'] ."/sdk.php/WapPay/wap_shortcut_pay/user_id/{$user_id}/game_id/{$game_id}", "html" => '', "return_msg" => '', "paytype" => 'shortcut', @@ -497,7 +498,7 @@ class WapPayController extends BaseController{ C(api('Config/lists')); - $extend_data = M('spend','tab_')->where(array('extend'=>$request['extend'],'game_id'=>$request['game_id'],'game_status'=>1))->find(); + $extend_data = M('spend','tab_')->where(array('extend'=>$request['extend'],'game_id'=>$request['game_id'],'pay_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; } @@ -545,7 +546,7 @@ class WapPayController extends BaseController{ $this->assign("pay_amount", $request['actual_amount']); $this->assign("user_id", $request['user_id']); $this->assign("game_id", $request['game_id']); - $this->display("index"); + $this->display(); } /** @@ -566,14 +567,14 @@ class WapPayController extends BaseController{ $this->set_message(1088, "fail", $payCheck['msg']); } C(api('Config/lists')); - if($request['price']*1<=0 || $request['price'] > C('WX_PAY_LIMIT')){ + if($request['price']*1<=0 || $request['price'] >= C('WX_PAY_LIMIT')){ $this->set_message(1011,"fail","充值金额有误"); } $game = M('Game','tab_')->where(['id'=>$request['game_id']])->field('pay_status')->find(); if($game['pay_status'] == 0){ $this->set_message(0,"fail","该游戏暂时无法充值,请联系客服!"); } - $extend_data = M('spend','tab_')->where(array('extend'=>$request['extend'],'pay_status'=>1,'game_id'=>$request['game_id']))->find(); + $extend_data = M('spend','tab_')->where(array('extend'=>$request['extend'],'pay_status'=>1,'game_id'=>$request['game_id']))->find(); if($extend_data){ $this->set_message(1089,"fail","订单号重复,请关闭支付页面重新支付"); } @@ -599,6 +600,7 @@ class WapPayController extends BaseController{ } // 绑币平台币优先处理 $this->other_price($request, $discountAmount); + $pay_amount = $request['price']; $game_set_data = get_game_set_info($request['game_id']); //$request['game_name'] @@ -633,10 +635,9 @@ class WapPayController extends BaseController{ $json_data['status'] = 500; $json_data['url'] = "http://" . $_SERVER['HTTP_HOST']; } - $json_data['cal_url'] = C("pay_header"); - - echo base64_encode(json_encode($json_data));exit; - // $this->redirect('WapPay/weixin_pay_view',['user_id'=>$request['user_id'],'game_id'=>$request['game_id']]); + $json_data['cal_url'] = $_SERVER ['HTTP_HOST']; + echo base64_encode(json_encode($json_data));exit; + // $this->redirect('WapPay/weixin_pay_view',['user_id'=>$request['user_id'],'game_id'=>$request['game_id']]); } else if(get_wx_pay_type() == 1){ // 威富通 if( empty(C('heepay.partner'))||empty(C('heepay.key'))){ $this->set_message(1009, "fail", "支付参数未配置"); @@ -905,7 +906,7 @@ class WapPayController extends BaseController{ $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; + redirect(U('Spend/notice',array('user_id'=>$request['user_id'],'game_id'=>$request['game_id'],'msg'=>'充值金额有误.'.$pay_amount)));exit; } $this->other_price($request, $request['price']-$pay_amount); @@ -917,7 +918,7 @@ class WapPayController extends BaseController{ if($request['code']==1){ $this->add_spend($request,1); }else{ - $this->add_deposit($request); + $this->add_deposit($request, 1); } $sqpay=new Sqpay(); $returl = 'http://' . $_SERVER ['HTTP_HOST'] . "/sdk.php/Spend/pay_success2/orderno/".$request['pay_order_number'].'/game_id/'.$request['game_id']; @@ -947,4 +948,93 @@ class WapPayController extends BaseController{ } // redirect($json_data['url']); } + + /** + * 双乾小程序支付 + * 流程:1.app端唤起小程序 2,小程序请求服务端拿到支付参数 3,小程序发起支付之后 回调服务端 4,服务端通知客户端 + * return: 相关支付参数 回调url + */ + public function small_program() { + + $request = json_decode(base64_decode(file_get_contents("php://input")), true); + if (empty($request)) { + $this->set_message(1001, "fail", "登录数据不能为空"); + } + + if (!$request['openid'] || !$request['price'] || !$request['game_id']) { + $this->set_message(1001, "fail", "小程序参数有误"); + } + + $game = M('Game','tab_')->where(['id'=>$request['game_id']])->field('pay_status')->find(); + if($game['pay_status'] == 0){ + $this->set_message(0, "fail","该游戏暂时无法充值,请联系客服!"); + } + + if($request['price']*1<=0){ + $this->set_message(1011,"fail","充值金额有误"); + } + + $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","订单号重复,请关闭支付页面重新支付"); + } + + $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.SQ_SMALL_PROGRAM'); + $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']; + $discountAmount = 0; + if($prefix=='PF_'){ + $pay_amount = $request['price']; + }else{ + $pay_amount = $discount * $request['price'] / 10; + $discountAmount = $request['price'] - $pay_amount; + } + if(!empty($request['scheme'])) { + file_put_contents("./Application/Sdk/Scheme/".$request['game_id'].".txt",$request['scheme']); + } + // 绑币平台币优先处理 + $this->other_price($request, $discountAmount); + $pay_amount = $request['price']; + if($request['code']==1){ + $this->add_spend($request,1); + }else{ + $this->add_deposit($request, 1); + } + + $sqpay = new Sqpay(); + $data['userId'] = $request['openid']; + $data['order_no'] = $request['pay_order_number']; + $data['merno'] = C('sqpay.partner'); + $data['subject'] = '游戏充值'; + $data['ip'] = get_client_ip(); + $data['returnurl'] = C('pay_header'). "/sdk.php/Spend/pay_success/orderno/".$request['pay_order_number'].'/game_id/'.$request['game_id']; + $data['amount'] = $request['price']; + $data['appId'] = C('wei_xin.email'); + $data['secret'] = C('sqpay.key'); + $data['MerRemark'] = $data['order_no']; + + $ret = $sqpay->sq_wxsmallpay($data); + + if ($ret[0]['respCode'] == "000000") { + echo json_encode(array( + 'code' => 1, + 'Amount' => $ret[0]['Amount'], + 'orderNo' => $ret[0]['orderNo'], // 微信生成的订单号 + 'platformNumber' => $request['pay_order_number'], // 平台订单号 + 'wxjsapiStr' => $ret[0]['wxjsapiStr'] + )); + exit(); + } + echo json_encode(array( + 'code' => 1, + 'msg' => $ret[0]['respMess'], + )); + exit(); + } } \ No newline at end of file diff --git a/ThinkPHP/Library/Think/Pay/PayVo.class.php b/ThinkPHP/Library/Think/Pay/PayVo.class.php index bc52288a8..22344066b 100644 --- a/ThinkPHP/Library/Think/Pay/PayVo.class.php +++ b/ThinkPHP/Library/Think/Pay/PayVo.class.php @@ -24,6 +24,7 @@ class PayVo { protected $_serverid; protected $_serverName; protected $_gameplayerName; + protected $_gameplayerId; protected $_userid; protected $_account; protected $_userNickName; @@ -59,6 +60,12 @@ class PayVo { $this->_gameplayerName = $gameplayerName; return $this; } + + // 设置游戏玩家ID + public function setGameplayerId($gameplayerId) { + $this->_gameplayerId = $gameplayerId; + return $this; + } //退款批次号 public function setBatchNo($batchno) { @@ -445,6 +452,14 @@ class PayVo { public function getGameId() { return $this->_gameid; } + + /** + * 获取角色id + * @return type + */ + public function getGameplayerId() { + return $this->_gameplayerId; + } /** * 获取游戏名称