You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1815 lines
91 KiB
PHP

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?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;
use Sdk\Model\ValueDetailLogModel;
use Sdk\Model\PayLimitConfModel;
use Sdk\Model\PayChannelInterntionModel;
use Sdk\Model\PayChannelIntentionModel;
use Org\Kudian\Api as KDApi;
class PayH5Controller extends BaseController{
const ALI_PAY = 1;
const WX_PAY = 2;
const EXPRESS_PAY = 4;
/**
* 平台币 alipay 充值
*/
public function platform_alipay_pay() {
C(api('Config/lists'));
if (!$this->userId) {
$this->error("用户未登入");
}
$user_id = $this->userId;
$game_id = I('request.game_id');
// 支付验证 是否让支付
$payCheck = pay_check($this->userId);
if (!$payCheck['code']) {
echo json_encode(['code'=>0,'msg'=> $payCheck['msg']]);exit;
// redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>$payCheck['msg'], 'user_token' => $this->userToken)));exit;
}
$request['user_id'] = $user_id;
$request['price'] = I('request.price');
$pay_info = M('pay_info', 'tab_')->where([
'user_id' => $user_id,
'game_id' => $game_id,
'type' => 'platform_pay',
])->order('id desc')->find();
if ($pay_info['price'] != $request['price']) {
echo json_encode(['code'=>0,'msg'=> '充值金额有误..']);exit;
}
$price = $request['price'];
$price = round($price, 2);
if($price <= 0){
echo json_encode(['code'=>0,'msg'=> '充值金额有误']);exit;
// redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'充值金额有误', 'user_token' => $this->userToken)));exit;
}
$request['pay_order_number'] = $pay_info['order_id'];
$payLimitConf = new PayLimitConfModel();
// 先判断意向记录支付请求情况
$check = $payLimitConf->check($request['user_id'], $request['price'], $payLimitConf::PAY_TYPE_ALIPAY, $request['pay_order_number']);
// 在更新历史支付请求订单提交情况
$payChannelInterntion = new PayChannelIntentionModel();
$payChannelInterntion->paySubmit($request['pay_order_number']);
if ($check) {
echo json_encode(['code'=>1001,'msg'=> "请求发起失效,编号{$request['pay_order_number']},请选择其他支付方式或联系客服"]);exit;
}
$game = M('game', 'tab_')->where(['id' => $game_id])->find();
$pay_info = get_payment_config(self::ALI_PAY, $game, $request['user_id'], $request['price'], true);
if ($pay_info['code'] != 0) {
echo json_encode(['code'=>1010,'msg'=> $pay_info['msg']]);
exit;
}
$pay_conf = json_decode($pay_info['data']['config'], true);
$main_id = $pay_info['data']['main_id'];
$pay_info = $pay_info['data'];
$pay_conf['id'] = $pay_info['id'];
$pay_conf['merchant_id'] = $pay_info['id'];
$pay_conf['merchant_way'] = self::ALI_PAY;
$pay_conf['main_id'] = $main_id;
if ($pay_info['channel'] == 1) { // 支付宝官方
$request['apitype'] = "alipay";
$request['config'] = "alipay";
$request['signtype']= "MD5";
$request['server'] = "alipay.wap.create.direct.pay.by.user";
$request['payway'] = C("PAY_WAY.ALIPAY"); // 1 支付宝
$request['title'] = "平台币充值"; //$request['price'];
$request['body'] = "平台币充值";
$request['price'] = $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, $pay_conf);
$request['pay_url'] = $pay_url['url']."&tx_client=hideopen";;
$orderno = $pay_url['out_trade_no'];
// 存入pay_url 继续支付
M("deposit", "tab_")->where([
'extend' => $request['extend'],
'game_id' => $request['game_id'],
'pay_order_number' => $orderno
])->save([
'pay_url' => $request['pay_url'],
]);
} elseif ($pay_info['channel'] == 4) { // 双乾
$request['pay_way'] = C('PAY_WAY.SQ_ALIPAY');
$request['pay_status'] = 0;
$request['spend_ip'] = get_client_ip();
$request['id'] = $pay_info['id'];
$request['merchant_id'] = $pay_info['id'];
$request['merchant_way'] = 1;
$request['main_id'] = $main_id;
$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'] = $pay_conf['secret']; // C("sqpay.key");
$data['merno'] = $pay_conf['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'] = "jianghuifa.cn";
$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'){
$json_data['url'] .= "?tx_client=hideopen";
// 存入pay_url 继续支付
M("deposit", "tab_")->where([
'extend' => $request['extend'],
'game_id' => $request['game_id'],
'pay_order_number' => $request["pay_order_number"]
])->save([
'pay_url' => $json_data['url']
]);
$orderno = $request['pay_order_number'];
//redirect($json_data['url']);
//echo json_encode(['code'=>200,'msg'=>'','data'=>['url'=>$json_data['url'],'wap'=>1]]);
//exit;
} else {
redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>$ret[0]['respMess'], 'user_token' => $this->userToken)));exit;
//echo json_encode(['code'=>0,'msg'=>$ret[0]['respMess'],'wap'=>1]);
//exit;
}
} elseif ($pay_info['channel'] == 5) { // 汇付宝
$request['pay_way'] = C('PAY_WAY.WFT_PAY');
$request['pay_status'] = 0;
$request['spend_ip'] = get_client_ip();
$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'] = 22;
$pay['amount'] = $request['price'];
$pay['user_ip'] = get_client_ip();
$pay['sign_key'] = C('heepay.key');//密钥
$pay['payerName'] = iconv("UTF-8", "gb2312//IGNORE", "聚游");
$pay['number'] = 1;
$pay['goods_note']= "消费-".$request["pay_order_number"];
$pay['device'] = "wap";
$pay['bank_card_type'] = 0;
$pay['return_url'] = C('PAY_DOMAIN')."sdk.php/Spend/paycallback/orderno/{$request['pay_order_number']}/user_token/".$this->userToken."/paytype/weixinpay/game_id/{$game_id}";
$pay['notifyurl'] = C('PAY_DOMAIN')."/callback.php/Notify/heepay_callback";//通知
$heepay = new Heepay();
$json_data = $heepay->alih5_pay($pay);
// pp($json_data);
if($json_data['ret_code'] == "0000"){
$json_data['url'] = $json_data['url']/* . "?tx_client=hideopen" */;
// 存入pay_url 继续支付
M("deposit", "tab_")->where([
'extend' => $request['extend'],
'game_id' => $request['game_id'],
'pay_order_number' => $request["pay_order_number"]
])->save([
'pay_url' => $json_data['url']
]);
$orderno = $request['pay_order_number'];
} else {
echo json_encode(['code'=>1001,'msg'=> "请求发起失败【{$json_data['ret_msg']}】,请选择其他支付方式或联系客服"]);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'] == 6) { // 酷点
$request['pay_way'] = 11;
$request['pay_status'] = 0;
$request['spend_ip'] = get_client_ip();
$this->add_deposit($request, 1);
$notifyUrl = C('PAY_DOMAIN')."/callback.php/Notify/kd_callback";
$backUrl = C('PAY_DOMAIN')."sdk.php/Spend/paycallback/orderno/{$request['pay_order_number']}/user_token/".$this->userToken."/paytype/weixinpay/game_id/{$game_id}";
$body = '消费-' . $request["pay_order_number"];
$response = KDApi::h5Pay($request['pay_order_number'], $request['price']*100, $notifyUrl, $backUrl, 'ALIPAY', $body, get_client_ip());
if($response->isSuccess()) {
// 存入pay_url 继续支付
M("deposit", "tab_")->where([
'extend' => $request['extend'],
'game_id' => $request['game_id'],
'pay_order_number' => $request["pay_order_number"]
])->save([
'pay_url' => $response->getResult('url')
]);
$orderno = $request['pay_order_number'];
} else {
echo json_encode(['code'=>1001,'msg'=> "请求发起失败【{$response->getMsg()}】,请选择其他支付方式或联系客服"]);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;
}
}
echo json_encode(['code' => 200, 'url' => U('spend/paycallback', array(
'sdk_version' => $request['sdk_version'],
'paytype' => 'alipay',
'orderno' => $orderno,
'game_id' => $game_id,
'gopay' => 1, // 立即支付
'user_token' => $this->userToken,
))]);
exit;
}
/**
*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 ali_pay($user_id, $game_id){
#获取SDK上POST方式传过来的数据 然后base64解密 然后将json字符串转化成数组
$request = $this->get_sdk_request($game_id);
$request['pay_status'] = 0;
$request['pay_way'] = C("PAY_WAY.ALIPAY");
$request['spend_ip'] = get_client_ip();
C(api('Config/lists'));
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('id, pay_status, game_type_id')->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;
}
$payLimitConf = new PayLimitConfModel();
// 先判断意向记录支付请求情况
$check = $payLimitConf->check($request['user_id'], $request['price'], $payLimitConf::PAY_TYPE_ALIPAY, $request['pay_order_number']);
// 在更新历史支付请求订单提交情况
$payChannelInterntion = new PayChannelIntentionModel();
$payChannelInterntion->paySubmit($request['pay_order_number']);
if ($check) {
echo json_encode(['code'=>1001,'msg'=> "请求发起失效,编号{$request['pay_order_number']},请选择其他支付方式或联系客服"]);exit;
}
$discount = get_discount($request['game_id'], $request['user_id']);
$discount = $discount['discount'];
$discountAmount = 0;
$request['discount'] = 10;
if ($discount < 10) {
$discountAmount = round($request['price'] - ($discount * $request['price'] / 10), 2);
$request['discount_amount'] = $discountAmount;
$request['discount'] = $discount;
}
$this->other_price($request, $discountAmount);
$skipOuterPay = false;
if ($request['deduction_amount'] > 0) {
$skipOuterPay = true;
}
$pay_info = get_payment_config(self::ALI_PAY, $game, $request['user_id'], $request['price'], $skipOuterPay);
if ($pay_info['code'] != 0) {
echo json_encode(['code'=>1010,'msg'=> $pay_info['msg']]);
exit;
}
$main_id = $pay_info['data']['main_id'];
$pay_conf = json_decode($pay_info['data']['config'], true);
$pay_info = $pay_info['data'];
$pay_conf['id'] = $pay_info['id'];
$pay_conf['merchant_id'] = $pay_info['id'];
$pay_conf['merchant_way'] = self::ALI_PAY;
$pay_conf['main_id'] = $main_id;
if ($pay_info['channel'] == 1) { // 支付宝官方
// $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["pay_order_number"];
$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, $pay_conf);
$request['pay_url'] = $pay_url['url']."&tx_client=hideopen";
$orderno = $pay_url['out_trade_no'];
//echo json_encode(['code'=>200,'msg'=>'','data'=>['url'=>$pay_url['url'],'wap'=>1]]);exit;
// 存入pay_url 继续支付
M("spend", "tab_")->where([
'extend' => $request['extend'],
'game_id' => $request['game_id'],
'pay_order_number' => $orderno
])->save([
'pay_url' => $request['pay_url'],
]);
} elseif ($pay_info['channel'] == 4) { // 双乾
// }elseif(get_zfb_type($game_id, $user_id) == 2) { // 双乾
$request['pay_way'] = C('PAY_WAY.SQ_ALIPAY');
$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;
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);
}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'] = $pay_conf['secret']; // C("sqpay.key");
$data['merno'] = $pay_conf['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'] = "jianghuifa.cn";
$data['mchAppName'] = "mchAppName";
$data['deviceInfo'] = "AND_WAP";
$data['clientIp'] = get_client_ip();
$orderno = $request['pay_order_number'];
$ret = $sqpay->sq_pay($data);
$ret = json_decode($ret, true);
$json_data['url']=$ret[0]['payURL'];
if($ret[0]['respCode'] == '000000'){
$json_data['url'] .= "?tx_client=hideopen";
// 存入pay_url 继续支付
M("spend", "tab_")->where([
'extend' => $request['extend'],
'game_id' => $request['game_id'],
'pay_order_number' => $request["pay_order_number"]
])->save([
'pay_url' => $json_data['url'],
]);
/* 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;
}
} elseif($pay_info['channel'] == 5) {
// } elseif(get_zfb_type($game_id, $user_id) == 4) { // 汇付宝
$request['pay_way'] = C('PAY_WAY.WFT_PAY');
$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;
$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);
$pay['agent_id'] = $pay_conf['merno']; //C('heepay.partner');//商户号
$pay['order_no'] = $request['pay_order_number'];
$pay['time'] = date('YmdHis', time());
$pay['pay_type'] = 22;
$pay['amount'] = $request['price'];
$pay['user_ip'] = get_client_ip();
$pay['sign_key'] = $pay_conf['secret']; //C('heepay.key');//密钥
$pay['payerName'] = iconv("UTF-8", "gb2312//IGNORE", "聚游");
$pay['number'] = 1;
$pay['goods_note']= "消费-".$request["pay_order_number"];
$pay['device'] = "wap";
$pay['bank_card_type'] = 0;
$pay['return_url'] = C('PAY_DOMAIN')."sdk.php/Spend/paycallback/orderno/{$request['pay_order_number']}/user_token/".$this->userToken."/paytype/weixinpay/game_id/{$game_id}";
$pay['notifyurl'] = C('PAY_DOMAIN')."/callback.php/Notify/heepay_callback";//通知
$heepay = new Heepay();
$json_data = $heepay->alih5_pay($pay);
if($json_data['ret_code'] == "0000"){
$json_data['url'] = $json_data['url']/* . "?tx_client=hideopen" */;
// 存入pay_url 继续支付
M("spend", "tab_")->where([
'extend' => $request['extend'],
'game_id' => $request['game_id'],
'pay_order_number' => $request["pay_order_number"]
])->save([
'pay_url' => $json_data['url']
]);
$orderno = $request['pay_order_number'];
} else {
echo json_encode(['code'=>1001,'msg'=> "请求发起失败【{$json_data['ret_msg']}】,请选择其他支付方式或联系客服"]);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'] == 6) { // 酷点
$request['pay_way'] = 11;
$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;
$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/kd_callback";
$backUrl = C('PAY_DOMAIN')."sdk.php/Spend/paycallback/orderno/{$request['pay_order_number']}/user_token/".$this->userToken."/paytype/weixinpay/game_id/{$game_id}";
$body = '消费-' . $request["pay_order_number"];
$response = KDApi::h5Pay($request['pay_order_number'], $request['price']*100, $notifyUrl, $backUrl, 'ALIPAY', $body, get_client_ip());
if($response->isSuccess()){
// 存入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->getResult('url')
]);
$orderno = $request['pay_order_number'];
} else {
echo json_encode(['code'=>1001,'msg'=> "请求发起失败【{$response->getMsg()}】,请选择其他支付方式或联系客服"]);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;
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;
}
}
/* $url = U('spend/paycallback', array(
'sdk_version' => $request['sdk_version'],
'paytype' => 'alipay',
'orderno' => $orderno,
'game_id' => $game_id,
'gopay' => 1 // 立即支付
));
redirect($url); */
echo json_encode(['code' => 200, 'url' => U('spend/paycallback', array(
'sdk_version' => $request['sdk_version'],
'paytype' => 'alipay',
'orderno' => $orderno,
'game_id' => $game_id,
'gopay' => 1, // 立即支付
'tx_client' => 'tx_forbid_return', // android 返回键
'user_token' => $this->userToken,
))]);
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'];
$param['callback'] = C('PAY_DOMAIN')."/sdk.php/Spend/paycallback/orderno/".$out_trade_no.'/game_id/'.$param['game_id']."/paytype/alipay";
// 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(), $payConf=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);
if ($param['pay_order_number']) $out_trade_no = $param['pay_order_number'];
$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;
}
$param['callback'] = C('PAY_DOMAIN')."/sdk.php/Spend/paycallback/orderno/".$out_trade_no.'/game_id/'.$param['game_id']."/paytype/alipay";
$vo = new \Think\Pay\PayVo();
$vo->setBody("充值")
->setFee($param['price'])
->setTitle($param['title'])
->setDiscount($param['discount_amount'])
->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'])
->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, $payConf);
$pay_['out_trade_no']= $out_trade_no;
return $pay_;
}
}
/**
*微信支付
* 增加
* ALTER TABLE `tab_deposit`
ADD COLUMN `pay_url` text NULL AFTER `check_sign`;
*/
public function platform_weixin_pay() {
if (!$this->userId) {
jsonOutput(0, "用户未登入");
}
$request['user_id'] = $this->userId;
// 支付验证 是否让支付
$payCheck = pay_check($this->userId);
if (!$payCheck['code']) {
echo json_encode(['code'=>0,'msg'=> $payCheck['msg']]);exit;
// echo json_encode(['code'=>0,'msg'=> $payCheck['msg']]);exit;
}
C(api('Config/lists'));
$request['price'] = I('request.price');
$game_id = I('request.game_id');
$user_id = $request['user_id'];
if($request['price']*1<=0 || $request['price'] > C('WX_PAY_LIMIT')) {
echo json_encode(['code'=>0,'msg'=> "微信单笔充值限额".C('WX_PAY_LIMIT').'元']);exit;
//redirect(U('Spend/notice',array('user_id'=>$user_id, 'is_platform' => 1, 'msg'=>'充值金额有误', 'game_id' => $game_id, 'user_token' => $this->userToken)));exit;
}
$pay_info = M('pay_info', 'tab_')->where([
'user_id' => $user_id,
'game_id' => $game_id,
'type' => 'platform_pay',
])->order('id desc')->find();
if ($pay_info['price'] != $request['price']) {
echo json_encode(['code'=>0,'msg'=> "充值金额有误..."]);exit;
}
$pay_amount = $request['price'];
$prefix = "PF_";
$request['pay_way'] = C("PAY_WAY.WEIXIN");
$request['pay_status'] = 0;
$request['spend_ip'] = get_client_ip();
$request['pay_order_number'] = $pay_info['order_id']; //'PF_'.date('Ymd').date('His').sp_random_string(4);
$request['sdk_version'] = I('request.sdk_version');
$payLimitConf = new PayLimitConfModel();
// 先判断意向记录支付请求情况
$check = $payLimitConf->check($request['user_id'], $request['price'], $payLimitConf::PAY_TYPE_WXPAY, $request['pay_order_number']);
// 在更新历史支付请求订单提交情况
$payChannelInterntion = new PayChannelIntentionModel();
$payChannelInterntion->paySubmit($request['pay_order_number']);
if ($check) {
echo json_encode(['code'=>1001,'msg'=> "请求发起失效,编号{$request['pay_order_number']},请选择其他支付方式或联系客服"]);exit;
}
$game = M('game', 'tab_')->where(['id' => $game_id])->find();
$pay_info = get_payment_config(self::WX_PAY, $game, $request['user_id'], $request['price'], true);
if ($pay_info['code'] != 0) {
echo json_encode(['code'=>1010,'msg'=> $pay_info['msg']]);
exit;
}
$pay_conf = json_decode($pay_info['data']['config'], true);
$main_id = $pay_info['data']['main_id'];
$pay_info = $pay_info['data'];
$pay_conf['id'] = $pay_info['id'];
$pay_conf['merchant_id'] = $pay_info['id'];
$pay_conf['merchant_way'] = self::WX_PAY;
$pay_conf['main_id'] = $main_id;
//0 官方 1威富通 2俊付通
// if (get_wx_pay_type() == 0) {
if ($pay_info['channel'] == 2) {
$weixn = new Weixin();
$is_pay = json_decode($weixn->weixin_pay("充值", $request['pay_order_number'], $pay_amount, 'MWEB', 1, $pay_conf), true);
if($is_pay['status']==1){
$json_data['url'] = $is_pay['mweb_url'].'&redirect_url='.C('PAY_DOMAIN')."sdk.php/Spend/paycallback/orderno/{$request['pay_order_number']}/user_token/".$this->userToken."/paytype/weixinpay/game_id/{$game_id}";
$request['pay_url'] = $json_data['url']."&tx_client=hideopen";
$request['merchant_id'] = $pay_info['id'];
$request['merchant_way'] = self::WX_PAY;
$request['main_id'] = $main_id;
if (C('SHARE_ID.'.$pay_conf['partner']) == 'y') {
$request['share_status'] = 1;
}
$this->add_deposit($request, 1);
// .(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'] ;
/* if (I('request.api_ver') == 1) {
$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'.$game_id;
redirect($json_data['url']);
} */
}else{
jsonOutput(0, "支付失败");
Log::write("platform_weixin_pay支付失败".serialize($is_pay));
exit();
// redirect(U('Spend/notice',array('user_id'=>$user_id, 'is_platform' => 1,'game_id'=>$game_id,'msg'=>'支付失败', 'user_token' => $this->userToken)));exit;
}
}elseif ($pay_info['channel'] == 5) { // 汇付宝
$request['pay_way'] = self::WX_PAY; // 威富通wx
$pay['agent_id'] = $pay_conf['merno'];//商户号
$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'] = $pay_conf['secret'];//密钥
$pay['payerName'] = iconv("UTF-8", "gb2312//IGNORE", "聚游");
$pay['number'] = 1;
$pay['goods_note']= "消费-".$request["pay_order_number"];
$pay['device'] = "wap";
$pay['bank_card_type'] = 0;
$pay['notify_url'] = C('PAY_DOMAIN')."/callback.php/Notify/heepay_callback";
$pay['return_url'] = C('PAY_DOMAIN')."sdk.php/Spend/paycallback/orderno/{$request['pay_order_number']}/user_token/".$this->userToken."/paytype/weixinpay/game_id/{$game_id}";
$heepay = new Heepay();
$json_data = $heepay->wxh5_pay($pay);
if($json_data['ret_code'] == "0000"){
$request['pay_url'] = $json_data['url'] . "&tx_client=hideopen";
$request['merchant_id'] = $pay_info['id'];
$request['merchant_way'] = self::WX_PAY;
$request['main_id'] = $main_id;
$this->add_deposit($request, 1);
} else {
jsonOutput(0, "支付失败");
exit;
}
} elseif($pay_info['channel'] == 6) { // 酷点
$request['pay_way'] = 21;
$notifyUrl = C('PAY_DOMAIN')."/callback.php/Notify/kd_callback";
$backUrl = C('PAY_DOMAIN')."sdk.php/Spend/paycallback/orderno/{$request['pay_order_number']}/user_token/".$this->userToken."/paytype/weixinpay/game_id/{$game_id}";
$body = '消费-' . $request["pay_order_number"];
$response = KDApi::h5Pay($request['pay_order_number'], $request['price']*100, $notifyUrl, $backUrl, 'WXPAY', $body, get_client_ip());
if($response->isSuccess()){
$request['pay_url'] = $response->getResult('url');
$request['merchant_id'] = $pay_info['id'];
$request['merchant_way'] = self::WX_PAY;
$request['main_id'] = $main_id;
$this->add_deposit($request, 1);
} else {
jsonOutput(0, "支付失败");
exit;
}
} 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',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'支付参数未配置', 'user_token' => $this->userToken)));exit;
}
$request['pay_way'] = 8;
if($pay_amount*1<1){
redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'单笔充值金额必须大于1元', 'user_token' => $this->userToken)));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'] = "";
$pay['number'] = 1;
$pay['goods_note']="游戏充值";
$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'];
}
}
echo json_encode(['code' => 200, 'url' => U('spend/paycallback', array(
'sdk_version' => $request['sdk_version'],
'paytype' => 'weixinpay',
'orderno' => $request['pay_order_number'],
'game_id' => $game_id,
'gopay' => 1, // 立即支付
'user_token' => $this->userToken,
// 'tx_client' => 'tx_forbid_return', // android 返回键
))]);
exit;
/* echo json_encode(array(
'status' => 1,
'data' => $json_data['url'],
));
exit(); */
//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'=>'登录数据不能为空', 'user_token' => $this->userToken)));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'], 'user_token' => $this->userToken)));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'=>'该游戏暂时无法充值,请联系客服!', 'user_token' => $this->userToken)));exit;
}
if($request['price']*1<=0){
redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'充值金额有误', 'user_token' => $this->userToken)));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'], 'user_token' => $this->userToken)));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, 'user_token' => $this->userToken)));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'] = "消费-".$request["pay_order_number"];
$data['notifyurl'] = C("PAY_DOMAIN")."/callback.php/Notify/sq_callback";//通知
$data['returnurl'] = $returl;
$data['mchAppId'] = "jianghuifa.cn";
$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);
$code = $_POST['way'];
if (empty($request)) {
redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'参数错误', 'user_token' => $this->userToken)));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'], 'user_token' => $this->userToken)));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',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'账号被禁用,无法充值,请联系客服!', 'user_token' => $this->userToken)));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'=>'该游戏暂时无法充值,请联系客服!', 'user_token' => $this->userToken)));exit;
}
if($request['price']*1<=0){
// $this->set_message(0,"fail","充值金额有误");
redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'充值金额有误', 'user_token' => $this->userToken)));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',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'订单号重复,请关闭支付页面重新支付', 'user_token' => $this->userToken)));exit;
}
$out_trade_no = "PF_" . date('Ymd') . date('His') . sp_random_string(4);
if ($request['pay_order_number']) $out_trade_no = $request['pay_order_number'];
$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'=>'您的账号暂时无法充值,请联系客服处理', 'user_token' => $this->userToken)));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',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'余额不足', 'user_token' => $this->userToken)));exit;
exit();
}
//防刷预警
if(C('BRUSH_PTB') && $user_entity['balance'] >= C('BRUSH_PTB') && C('BRUSH_EMAIL') && C('BRUSH_EMAIL_STATUS') ){
$content = "尊敬的用户:<br/>&nbsp;&nbsp;&nbsp;&nbsp;系统检测到玩家【".$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/>&nbsp;&nbsp;&nbsp;&nbsp;系统检测到玩家【".$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',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'余额不足', 'user_token' => $this->userToken)));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',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'支付方式不明确', 'user_token' => $this->userToken)));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) {
$request = $this->get_sdk_request($game_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); */
if (empty($request)) {
redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>urlencode('参数错误'), 'user_token' => $this->userToken)));exit;
}
// 支付验证 是否让支付
$payCheck = pay_check($request['user_id']);
if (!$payCheck['code']) {
redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=> urlencode($payCheck['msg']), 'user_token' => $this->userToken)));exit;
}
if ($request['price'] *1<=0) {
redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>urlencode('充值金额有误'), 'user_token' => $this->userToken)));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'=>urlencode('订单号重复,请关闭支付页面重新支付'), 'user_token' => $this->userToken)));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'=>urlencode('账号被禁用,无法充值,请联系客服!..'), 'user_token' => $this->userToken)));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'=>urlencode('该游戏暂时无法充值,请联系客服!'), 'user_token' => $this->userToken)));exit;
}
$out_trade_no = "PF_" . date('Ymd') . date('His') . sp_random_string(4);
if ($request['pay_order_number']) $out_trade_no = $request['pay_order_number'];
$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']);
if (isset($request['discount']) && $request['discount'] < 10) {
$discountInfo = discountInfo($request['game_id']);
if (!$discountInfo) {
redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>urlencode('折扣无效,请重试!'), 'user_token' => $this->userToken)));exit;
}
}
$discount = get_discount($request['game_id'], $request['user_id']);
$discount = $discount['discount'];
$discountAmount = 0;
if ($discount < 10) {
$discountAmount = round($request['price'] - ($discount * $request['price'] / 10), 2);
$request['discount_amount'] = $discountAmount;
}
$request['actual_amount'] = round($request['price'] - $discountAmount, 2);
$request['discount_amount'] = $discountAmount;
$request['cost'] = $request['price'];
$request['price'] = $request['actual_amount'];
$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'=>urlencode('您的账号暂时无法充值,请联系客服处理.'), 'user_token' => $this->userToken)));exit;
}
$result = false;
$notice_order = []; // 需要更新的通知游戏订单
$valueDetailLogModel = new ValueDetailLogModel(); // 记录数值增减 (绑定币 平台币)
// 先扣绑币
$request['pay_way'] = C('PAY_WAY.BIND_COIN');
$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'=>urlencode('您金额不足,请退出重试.'), 'user_token' => $this->userToken)));exit;
}
if ($user_play_data['bind_balance'] < $request['price']) {
$price = $request['price'];
$pay_order_number = $request['pay_order_number'];
if ($user_play_data['bind_balance'] > 0) {
$request['pay_order_number'] = $request['pay_order_number']."_1";
$user_play->where($user_play_map)->save(array('bind_balance' => 0)); // 扣绑定币
$request['price'] = $user_play_data['bind_balance'];
$request['cost'] = $request['price'];
$request['deduction_amount'] = $price - $user_play_data['bind_balance'];
$request['actual_amount'] = $request['price'];
$result = $this->add_spend($request);
// 绑币不记录
// $valueDetailLogModel->addLog($request['user_id'], $request['pay_order_number'], $user_play_data['bind_balance'], -$user_play_data['bind_balance'], 0, $valueDetailLogModel::BANDBI, "绑定币消费:".$user_play_data['pay_amount']);
$this->set_ratio($request['pay_order_number'], 2); // 游戏返利
$notice_order[] = $request['pay_order_number'];
}
$request['pay_order_number'] = $pay_order_number;
$request['pay_way'] = 0; // 扣平台币
$real_price = $price - $user_play_data['bind_balance'];
$valueDetailLogModel->addLog($request['user_id'], $request['pay_order_number'], $balance, -$real_price, $balance-$real_price, $valueDetailLogModel::BALANCE, "平台币消费:".$real_price);
$user->where(array('id' => $request["user_id"]))->setDec("balance", $real_price);
//$this->set_message(0,"fail", $request['pay_order_number']);
$request['price'] = $real_price;
$request['cost'] = $request['price'];
$request['actual_amount'] = $request['price'];
$request['deduction_amount'] = 0;
$result = $this->add_spend($request);
$this->set_ratio($request['pay_order_number'], 1); // 游戏返利
$notice_order[] = $request['pay_order_number'];
} else { // 绑定币足够扣
// $valueDetailLogModel->addLog($request['user_id'], $request['pay_order_number'], $user_play_data['bind_balance'], -$request['price'], $user_play_data['bind_balance'] - $request['price'], $valueDetailLogModel::BANDBI, "绑定币消费.".$request['price']);
$user_play->where($user_play_map)->setDec('bind_balance', $request['price']); // 扣绑定币
$result = $this->add_spend($request);
$this->set_ratio($request['pay_order_number'], 2); // 游戏返利
$notice_order[] = $request['pay_order_number'];
}
$game = new GameApi();
$url = C('TASK_URL')."/game-event/recharge";
// 通知后台
try {
post_async($url, [
'form_params' => [
'pay_order_number' => $request['pay_order_number']
],
]);
} catch(\Exception $e) {
}
$r = $game->game_pay_notify($request, $request['code']);
if ($r == 'success') {
foreach ($notice_order as $v) {
$result = M('spend',"tab_")->where([
'pay_order_number' => $v
])->setField([
'pay_game_status' => 1
]);
// 通知后台
try {
post_async($url, [
'form_params' => [
'pay_order_number' => $v
],
]);
} catch(\Exception $e) {
}
}
}
$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;
}
/**
*微信支付
*ALTER TABLE `tab_spend`
ADD COLUMN `pay_url` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL AFTER `old_promote_account`;
*/
public function weixin_pay($user_id,$game_id) {
$request = $this->get_sdk_request($game_id);
$request['pay_status'] = 0;
$request['pay_way'] = C("PAY_WAY.WEIXIN");
$request['spend_ip'] = get_client_ip();
if (empty($request)) {
echo json_encode(['code'=>0,'msg'=> "登录数据不能为空"]);exit;
//redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'登录数据不能为空', 'user_token' => $this->userToken)));exit;
}
// 支付验证 是否让支付
$payCheck = pay_check($user_id);
if (!$payCheck['code']) {
echo json_encode(['code'=>0,'msg'=> $payCheck['msg']]);exit;
//redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=> $payCheck['msg'], 'user_token' => $this->userToken)));exit;
}
C(api('Config/lists'));
$game = M('Game','tab_')->where(['id'=>$request['game_id']])->field('id, pay_status, game_type_id')->find();
if($game['pay_status'] == 0){
echo json_encode(['code'=>0,'msg'=> '该游戏暂时无法充值,请联系客服!']);exit;
//redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'该游戏暂时无法充值,请联系客服!', 'user_token' => $this->userToken)));exit;
}
if($request['price']*1<=0 || $request['price'] > C('WX_PAY_LIMIT')) {
echo json_encode(['code'=>0,'msg'=> "微信单笔充值限额".C('WX_PAY_LIMIT').'元']);exit;
// $this->set_message(0,"fail","充值金额有误");
// redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'充值金额有误', 'user_token' => $this->userToken)));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->set_message(1089,"fail","订单号重复,请关闭支付页面重新支付");
//redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'订单号重复,请关闭支付页面重新支付', 'user_token' => $this->userToken)));exit;
}
// 微信支付日月限额
if (pay_limit('wx')) {
echo json_encode(['code'=>0,'msg'=> '支付限额,暂不支持']);exit;
}
$payLimitConf = new PayLimitConfModel();
// 先判断意向记录支付请求情况
$check = $payLimitConf->check($request['user_id'], $request['price'], $payLimitConf::PAY_TYPE_WXPAY, $request['pay_order_number']);
// 在更新历史支付请求订单提交情况
$payChannelInterntion = new PayChannelIntentionModel();
$payChannelInterntion->paySubmit($request['pay_order_number']);
if ($check) {
echo json_encode(['code'=>1001,'msg'=> "请求发起失效,编号{$request['pay_order_number']},请选择其他支付方式或联系客服"]);exit;
}
//折扣
$user = get_user_entity($request['user_id']);
$discount = get_discount($request['game_id'], $request['user_id']);
$discount = $discount['discount'];
$discountAmount = 0;
if ($discount < 10) {
$discountAmount = round($request['price'] - ($discount * $request['price'] / 10), 2);
$request['discount_amount'] = $discountAmount;
}
// 绑币平台币优先处理
$this->other_price($request, $discountAmount);
$pay_amount = $request['price'];
$pay_info = get_payment_config(self::WX_PAY, $game, $request['user_id'], $request['price']);
if ($pay_info['code'] != 0) {
echo json_encode(['code'=>1010,'msg'=> $pay_info['msg']]);
exit;
}
$main_id = $pay_info['data']['main_id'];
$pay_conf = json_decode($pay_info['data']['config'], true);
$pay_info = $pay_info['data'];
$pay_conf['id'] = $pay_info['id'];
$pay_conf['merchant_id'] = $pay_info['id'];
$pay_conf['merchant_way'] = self::WX_PAY;
$pay_conf['main_id'] = $main_id;
//0 官方 1威富通 2俊付通
// if (get_wx_pay_type() == 0) {
if ($pay_info['channel'] == 2) {
$weixn = new Weixin();
$is_pay = json_decode($weixn->weixin_pay(!empty($request['title']) ? $request['title']: "充值", $request['pay_order_number'], $pay_amount, 'MWEB', 1, $pay_conf), true);
if($is_pay['status']==1){
if($request['code']==1){
$json_data['url'] = $is_pay['mweb_url'].'&redirect_url='.urlencode(C('PAY_DOMAIN')."sdk.php/Spend/paycallback/orderno/{$request['pay_order_number']}/game_id/{$request['game_id']}/paytype/weixinpay");
$request['pay_url'] = $json_data['url'] . "&tx_client=hideopen";
$request['merchant_id'] = $pay_info['id'];
$request['merchant_way'] = self::WX_PAY;
$request['main_id'] = $main_id;
if (C('SHARE_ID.'.$pay_conf['partner']) == 'y') {
$request['share_status'] = 1;
}
$this->add_spend($request,1);
}
// $json_data['url'] = $is_pay['mweb_url'].'&redirect_url='.C('PAY_DOMAIN')."sdk.php/Spend/paycallback/orderno/{$request['pay_order_number']}/game_id/{$request['game_id']}";
// (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{
echo json_encode(['code'=>0,'msg'=> '支付失败']);
Log::write("platform_weixin_pay支付失败".serialize($is_pay));
exit;
// redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'支付失败', 'user_token' => $this->userToken)));exit;
}
}elseif ($pay_info['channel'] == 5) {
$request['pay_way'] = self::WX_PAY;
$pay['agent_id'] = $pay_conf['merno'];//商户号
$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'] = $pay_conf['secret'];//密钥
$pay['payerName'] = iconv("UTF-8", "gb2312//IGNORE", "聚游");
$pay['number'] = 1;
$pay['goods_note']= "消费-".$request["pay_order_number"];
$pay['device'] = "wap";
$pay['bank_card_type'] = 0;
$pay['return_url'] = C('PAY_DOMAIN')."sdk.php/Spend/paycallback/orderno/{$request['pay_order_number']}/user_token/".$this->userToken."/paytype/weixinpay/game_id/{$game_id}";
$pay['notify_url'] = C('PAY_DOMAIN')."/callback.php/Notify/heepay_callback";
$heepay = new Heepay();
$json_data = $heepay->wxh5_pay($pay);
if($json_data['ret_code'] == "0000"){
$request['pay_url'] = $json_data['url'] . "&tx_client=hideopen";
$request['merchant_id'] = $pay_info['id'];
$request['merchant_way'] = self::WX_PAY;
$request['main_id'] = $main_id;
$this->add_spend($request,1);
} else {
echo json_encode(['code'=>0,'msg'=> '支付失败,请重试'.$json_data['ret_msg']]);
exit;
}
} elseif($pay_info['channel'] == 6) { // 酷点
$request['pay_way'] = 21;
$request['pay_status'] = 0;
$request['spend_ip'] = get_client_ip();
$request['merchant_id'] = $pay_info['id'];
$request['merchant_way'] = 2;
$request['main_id'] = $main_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/kd_callback";
$backUrl = C('PAY_DOMAIN')."sdk.php/Spend/paycallback/orderno/{$request['pay_order_number']}/user_token/".$this->userToken."/paytype/weixinpay/game_id/{$game_id}";
$body = '消费-' . $request["pay_order_number"];
$response = KDApi::h5Pay($request['pay_order_number'], $request['price']*100, $notifyUrl, $backUrl, 'WXPAY', $body, get_client_ip());
if($response->isSuccess()){
// 存入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->getResult('url')
]);
$orderno = $request['pay_order_number'];
} else {
echo json_encode(['code'=>1001,'msg'=> "请求发起失败【{$response->getMsg()}】,请选择其他支付方式或联系客服"]);exit;
// redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>$ret[0]['respMess'], 'user_token' => $this->userToken)));exit;
}
} 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',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'支付参数未配置', 'user_token' => $this->userToken)));exit;
}
$request['pay_way'] = 8;
if($pay_amount*1<1){
redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'单笔充值金额必须大于1元', 'user_token' => $this->userToken)));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'];
}
}
echo json_encode(['code' => 200, 'url' => U('spend/paycallback', array(
'sdk_version' => $request['sdk_version'],
'paytype' => 'weixinpay',
'orderno' => $request['pay_order_number'],
'game_id' => $game_id,
'gopay' => 1, // 立即支付
'user_token' => $this->userToken,
'tx_client' => 'tx_forbid_return', // android 返回键
))]);
exit;
// redirect($json_data['url']);
}
}