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.
434 lines
14 KiB
PHP
434 lines
14 KiB
PHP
<?php
|
|
|
|
namespace Sdk\Controller;
|
|
|
|
use Think\Controller;
|
|
use Org\JtpaySDK\Jtpay;
|
|
use Org\SqpaySDK\Sqpay;
|
|
use Think\Log;
|
|
use Qiniu\json_decode;
|
|
|
|
class SpendController extends Controller {
|
|
|
|
/**
|
|
* 转发支付url
|
|
*/
|
|
public function get_pay_url($user_id, $game_id) {
|
|
$file = file_get_contents ( "./Application/Sdk/OrderNo/" . $user_id . "-" . $game_id . ".txt" );
|
|
$info = json_decode ( think_decrypt ( $file ), true );
|
|
redirect ( $info ['pay_url'] );
|
|
}
|
|
public function jft_pay($user_id, $game_id, $type) {
|
|
$file = file_get_contents ( "./Application/Sdk/OrderNo/" . $user_id . "-" . $game_id . ".txt" );
|
|
$request = json_decode ( think_decrypt ( $file ), true );
|
|
|
|
$jtpay = new Jtpay ();
|
|
if ($request ['sdk_version'] == 1) { // 1 安卓 2苹果
|
|
$p25_terminal = 3;
|
|
$p26_iswappay = 3;
|
|
} else {
|
|
$p25_terminal = 2;
|
|
$p26_iswappay = 3;
|
|
}
|
|
|
|
if ($type == "3") { // 3支付宝 4微信
|
|
$url = $jtpay->jt_pay ( $request ['pay_order_number'], $request ['price'], $request ['user_id'], get_client_ip (), "sdk", 4, 'http://' . $_SERVER ['HTTP_HOST'] . "/sdk.php/Spend/pay_success", $p26_iswappay, $p25_terminal ); // 安卓
|
|
} else {
|
|
$url = $jtpay->jt_pay ( $request ['pay_order_number'], $request ['price'], $request ['user_id'], get_client_ip (), "sdk", 3, 'http://' . $_SERVER ['HTTP_HOST'] . "/sdk.php/Spend/pay_success", 3, 2 ); // 安卓
|
|
}
|
|
redirect ( $url );
|
|
}
|
|
/**
|
|
* 支付页面
|
|
*
|
|
* @return [type] [description]
|
|
*/
|
|
public function pay_way() {
|
|
$user_id = I ('user_id');
|
|
$game_id = I ('game_id');
|
|
$user_token = I('user_token');
|
|
if (!$user_token) {
|
|
echo "access deny!";
|
|
die();
|
|
}
|
|
$userId = M('user_token', 'tab_')->where([
|
|
'user_token'=>$user_token,
|
|
'user_id' => $user_id,
|
|
'game_id' => $game_id
|
|
])->getField('id');
|
|
if (!$userId) {
|
|
echo $user_token."请重新登入!".$user_id.$game_id;
|
|
die();
|
|
}
|
|
C(BaseController::get_tool());
|
|
// pp(BaseController::get_tool());
|
|
|
|
$file = file_get_contents ( "./Application/Sdk/OrderNo/" . $user_id . "-" . $game_id . ".txt" );
|
|
$request = json_decode ( think_decrypt ( $file ), true );
|
|
$data = array(
|
|
'coin' => $request ['body'],
|
|
'price' => $request ['price'],
|
|
'game_name' => $request ['game_name'],
|
|
'code' => $request ['code']
|
|
);
|
|
$balance = M ( 'user', 'tab_' )->where ( array (
|
|
'id' => $user_id
|
|
) )->getField ( 'balance' );
|
|
$bind_balance = M ( 'user_play', 'tab_' )->where ( array (
|
|
'user_id' => $user_id,
|
|
'game_id' => $game_id
|
|
) )->getField ( 'bind_balance' );
|
|
// $data['price'] = 1;
|
|
$this->assign ( 'balance', $balance );
|
|
$this->assign ( 'bind_balance', $bind_balance );
|
|
$this->assign ( 'data', $data );
|
|
$this->assign ( 'btncolor', $request ['btncolor'] );
|
|
|
|
if ($balance + $bind_balance > $data['price']) {
|
|
$apply_money = $data['price'];
|
|
$this->assign ('pay_price', 0); // 是否第三方支付
|
|
} else {
|
|
$apply_money = $balance + $bind_balance;
|
|
$payPrice = round($data['price'] - $balance - $bind_balance, 2);
|
|
$this->assign ('pay_price', $payPrice ? $payPrice : 0);
|
|
}
|
|
|
|
/* $this->assign ( 'alipayurl', $ret[0]['payURL']);
|
|
header("Access-Control-Allow-Origin: *"); */
|
|
$data = $request;
|
|
//unset($data['md5_sign']);
|
|
unset($data['pay_order_number']);
|
|
unset($data['pay_status']);
|
|
unset($data['spend_ip']);
|
|
unset($data['pay_way']);
|
|
/* if ($request['sdk_version'] == 1) // android 没有 is_create_ordernumer苹果内购
|
|
unset($data['is_create_ordernumer']); */
|
|
$this->assign('apply_money',$apply_money); //适用平台金额
|
|
$this->assign('sdk_version', $request['sdk_version']);
|
|
$this->assign('small_json', json_encode(array(
|
|
'appId' => 'wx8419130aa4ff123b',
|
|
'userName' => 'gh_e3bff77d318e',
|
|
'path' => 'pages/pay/pay?kx='.base64_encode(json_encode($data)),
|
|
'miniprogramType' => 2, // 0正式版 1开发版 2体验版
|
|
)));
|
|
|
|
$this->assign('user_token', $user_token);
|
|
$this->display();
|
|
|
|
}
|
|
|
|
public function pay_way_v1() {
|
|
$user_id = I ('user_id');
|
|
$game_id = I ('game_id');
|
|
|
|
$file = file_get_contents ( "./Application/Sdk/OrderNo/" . $user_id . "-" . $game_id . ".txt" );
|
|
$request = json_decode ( think_decrypt ( $file ), true );
|
|
|
|
C(BaseController::get_tool());
|
|
|
|
$data = array(
|
|
'coin' => $request ['body'],
|
|
'price' => $request ['price'],
|
|
'game_name' => $request ['game_name'],
|
|
'code' => $request ['code']
|
|
);
|
|
$balance = M ( 'user', 'tab_' )->where ( array (
|
|
'id' => $user_id
|
|
) )->getField ( 'balance' );
|
|
$bind_balance = M ( 'user_play', 'tab_' )->where ( array (
|
|
'user_id' => $user_id,
|
|
'game_id' => $game_id
|
|
) )->getField ( 'bind_balance' );
|
|
// $data['price'] = 1;
|
|
|
|
$this->assign ( 'balance', $balance );
|
|
$this->assign ( 'bind_balance', $bind_balance );
|
|
$this->assign ( 'data', $data );
|
|
$this->assign ( 'btncolor', $request ['btncolor'] );
|
|
if ($balance + $bind_balance > $data['price']) {
|
|
$this->assign ('pay_price', 0); // 是否第三方支付
|
|
} else {
|
|
$payPrice = $data['price'] - $balance - $bind_balance;
|
|
$this->assign ('pay_price', $payPrice ? $payPrice : 0);
|
|
}
|
|
|
|
/* $this->assign ( 'alipayurl', $ret[0]['payURL']);
|
|
header("Access-Control-Allow-Origin: *"); */
|
|
$this->display ();
|
|
}
|
|
|
|
/**
|
|
* 支付页面
|
|
*
|
|
* @return [type] [description]
|
|
*/
|
|
/* public function pay_way_v2() {
|
|
$user_id = I ('user_id');
|
|
$game_id = I ('game_id');
|
|
|
|
$file = file_get_contents ( "./Application/Sdk/OrderNo/" . $user_id . "-" . $game_id . ".txt" );
|
|
$request = json_decode ( think_decrypt ( $file ), true );
|
|
|
|
$data = array(
|
|
'coin' => $request ['body'],
|
|
'price' => $request ['price'],
|
|
'game_name' => $request ['game_name'],
|
|
'code' => $request ['code']
|
|
);
|
|
$balance = M ( 'user', 'tab_' )->where ( array (
|
|
'id' => $user_id
|
|
) )->getField ( 'balance' );
|
|
$bind_balance = M ( 'user_play', 'tab_' )->where ( array (
|
|
'user_id' => $user_id,
|
|
'game_id' => $game_id
|
|
) )->getField ( 'bind_balance' );
|
|
// $data['price'] = 1;
|
|
|
|
$this->assign ( 'balance', $balance );
|
|
$this->assign ( 'bind_balance', $bind_balance );
|
|
$this->assign ( 'data', $data );
|
|
$this->assign ( 'btncolor', $request ['btncolor'] );
|
|
if ($balance + $bind_balance > $data['price']) {
|
|
$this->assign ('pay_price', 0); // 是否第三方支付
|
|
} else {
|
|
$payPrice = $data['price'] - $balance - $bind_balance;
|
|
$this->assign ('pay_price', $payPrice ? $payPrice : 0);
|
|
}
|
|
$this->assign ('pay_price', $data['price']);
|
|
|
|
// $this->assign ( 'alipayurl', $ret[0]['payURL']);
|
|
// header("Access-Control-Allow-Origin: *");
|
|
|
|
$this->assign ('sdk_version', $request['sdk_version']);
|
|
$this->display();
|
|
} */
|
|
|
|
public function pay_success() {
|
|
|
|
$orderno = $_GET ['orderno'] == "" ? $_GET ['out_trade_no'] : $_GET ['orderno'];
|
|
if (! empty ( $_GET ['jinzhue'] )) {
|
|
sleep ( 3 );
|
|
$orderno = $_GET ['jinzhue'];
|
|
}
|
|
$pay_where = substr ( $orderno, 0, 2 );
|
|
$Scheme = file_get_contents ( "./Application/Sdk/Scheme/" . $_GET ['game_id'] . ".txt" );
|
|
$map ['pay_order_number'] = $orderno;
|
|
switch ($pay_where) {
|
|
case 'SP' :
|
|
$result = M ( 'Spend', 'tab_' )->field ( "pay_status" )->where ( $map )->find ();
|
|
break;
|
|
case 'PF' :
|
|
$result = M ( 'deposit', 'tab_' )->field ( 'pay_status' )->where ( $map )->find ();
|
|
break;
|
|
|
|
case 'TB' :
|
|
$result = M ( 'balance', 'tab_' )->field ( 'pay_status' )->where ( $map )->find ();
|
|
break;
|
|
|
|
case 'BR' :
|
|
$result = M ( 'bind_recharge', 'tab_' )->field ( 'pay_status' )->where ( $map )->find ();
|
|
break;
|
|
}
|
|
$this->assign ( 'Scheme', $Scheme );
|
|
$this->assign ( 'paystatus', $result ['pay_status'] );
|
|
$this->display ();
|
|
}
|
|
|
|
public function pay_success2() {
|
|
$orderno = $_GET ['orderno'] == "" ? $_GET ['out_trade_no'] : $_GET ['orderno'];
|
|
$pay_where = substr ( $orderno, 0, 2 );
|
|
$Scheme = file_get_contents ( "./Application/Sdk/Scheme/" . $_GET ['game_id'] . ".txt" );
|
|
$map ['pay_order_number'] = $orderno;
|
|
switch ($pay_where) {
|
|
case 'SP' :
|
|
$result = M ( 'Spend', 'tab_' )->field ( "pay_status" )->where ( $map )->find ();
|
|
break;
|
|
case 'PF' :
|
|
$result = M ( 'deposit', 'tab_' )->field ( 'pay_status' )->where ( $map )->find ();
|
|
break;
|
|
case 'TB' :
|
|
$result = M ( 'balance', 'tab_' )->field ( 'pay_status' )->where ( $map )->find ();
|
|
break;
|
|
|
|
case 'BR' :
|
|
$result = M ( 'bind_recharge', 'tab_' )->field ( 'pay_status' )->where ( $map )->find ();
|
|
break;
|
|
}
|
|
$this->assign ( 'paystatus', $result ['pay_status'] );
|
|
$this->assign ( 'Scheme', $Scheme );
|
|
$this->display ();
|
|
}
|
|
public function pay_success3() {
|
|
$orderno = $_GET ['orderno'] == "" ? $_GET ['out_trade_no'] : $_GET ['orderno'];
|
|
if (! empty ( $_GET ['jinzhue'] )) {
|
|
$orderno = $_GET ['jinzhue'];
|
|
}
|
|
$pay_where = substr ( $orderno, 0, 2 );
|
|
$map ['pay_order_number'] = $orderno;
|
|
$result = M ( 'Spend', 'tab_' )->field ( "pay_status" )->where ( $map )->find ();
|
|
|
|
$this->assign ( 'paystatus', $result ['pay_status'] );
|
|
$this->display ( 'pay_success3' );
|
|
}
|
|
public function pay_error() {
|
|
$Scheme = file_get_contents ( "./Application/Sdk/Scheme/" . $_GET ['game_id'] . ".txt" );
|
|
|
|
$this->assign ('Scheme', $Scheme?$Scheme:'txplatformsdk');
|
|
$this->display ();
|
|
}
|
|
public function notice($user_id = 0, $game_id = 0, $is_platform=0, $msg = '') {
|
|
if ($is_platform) {
|
|
$this->assign("gourl", U('UserH/get_user_money',array('user_id'=>I('user_id'),'game_id'=>I('game_id'), 'user_token' => I('user_token'))));
|
|
} else {
|
|
$this->assign("gourl", U('Spend/pay_way',array('user_id'=>I('user_id'),'game_id'=>I('game_id'), 'user_token' => I('user_token'))));
|
|
}
|
|
$this->display ();
|
|
}
|
|
|
|
public function notice_v1($user_id = 0, $game_id = 0, $msg = '') {
|
|
$this->display ();
|
|
}
|
|
|
|
/*
|
|
* ALTER TABLE `tab_deposit`
|
|
ADD COLUMN `pay_url` varchar(255) NOT NULL DEFAULT '' AFTER `check_sign`;
|
|
* 支付中转页
|
|
*/
|
|
public function paycallback() {
|
|
$userToken = I('user_token');
|
|
$orderno = $_GET['orderno'] == "" ? $_GET ['out_trade_no'] : $_GET ['orderno'];
|
|
$pay_where = substr($orderno, 0, 2);
|
|
// $Scheme = file_get_contents("./Application/Sdk/Scheme/" . $_GET ['game_id'] . ".txt");
|
|
$gameId = $_GET ['game_id'];
|
|
$Scheme = "txgame".$gameId;
|
|
$map ['pay_order_number'] = $orderno;
|
|
$paytype = I('request.paytype', 0); // 支付方式 weixinpay alipay
|
|
$gopay = I('request.gopay');
|
|
|
|
switch ($pay_where) {
|
|
case 'SP' :
|
|
$result = M('Spend', 'tab_')->field ("*")->where ($map)->find();
|
|
break;
|
|
case 'PF' :
|
|
$result = M('deposit', 'tab_')->field ('*')->where ($map)->find();
|
|
break;
|
|
case 'TB' :
|
|
$result = M('balance', 'tab_')->field ('*')->where ($map)->find();
|
|
break;
|
|
case 'BR' :
|
|
$result = M('bind_recharge', 'tab_')->field ('*')->where ($map)->find();
|
|
break;
|
|
}
|
|
// 支付成功跳转页面
|
|
if ($result['pay_status'] == 1) {
|
|
// $this->success("支付成功", U("userH/get_user_money", ['user_token' => $userToken]));
|
|
}
|
|
|
|
// 微信 支付宝 快捷
|
|
if ($pay_where == "SP") {
|
|
/* if ($result['pay_way'] == C('PAY_WAY.WEIXIN') || $result['pay_way'] == C('PAY_WAY.WEIXIN_APP') || $result['pay_way'] == C('PAY_WAY.SQ_SMALL_PROGRAM'))
|
|
$gopayUrl = "/sdk.php/Apple/apple_weixin_pay/user_id/{$result['user_id']}/game_id/{$result['game_id']}/user_token/{$userToken}";
|
|
if ($result['pay_way'] == C('PAY_WAY.ALIPAY') || $result['pay_way'] == C('PAY_WAY.SQ_ALIPAY'))
|
|
$gopayUrl = "/sdk.php/Apple/apple_alipay_pay/user_id/{$result['user_id']}/game_id/{$result['game_id']}/user_token/{$userToken}";
|
|
*/
|
|
$gopayUrl = $result['pay_url'];
|
|
}
|
|
if ($pay_where == "PF") {
|
|
$gopayUrl = $result['pay_url'];
|
|
// if ($result['pay_way'] == C('PAY_WAY.WEIXIN') || $result['pay_way'] == C('PAY_WAY.WEIXIN_APP') || $result['pay_way'] == C('PAY_WAY.SQ_SMALL_PROGRAM'))
|
|
// $gopayUrl = "/sdk.php/PayH5/platform_weixin_pay/pay_order_number/{$result['pay_order_number']}/price/{$result['pay_amount']}/user_token/{$userToken}";
|
|
// if ($result['pay_way'] == C('PAY_WAY.ALIPAY') || $result['pay_way'] == C('PAY_WAY.SQ_ALIPAY'))
|
|
// $gopayUrl = "/sdk.php/PayH5/platform_alipay_pay/pay_order_number/{$result['pay_order_number']}/game_id/{$result['game_id']}/user_token/{$userToken}";
|
|
}
|
|
// 如果是json格式 且是alipay 则 alipay app
|
|
if (json_decode($gopayUrl) && $paytype == 'alipay') {
|
|
$this->assign("aliapp", 1);
|
|
} else {
|
|
$this->assign("aliapp", 0);
|
|
}
|
|
if(get_zfb_type() == 2) {
|
|
$this->assign("sqzfb", 1);
|
|
} else {
|
|
$this->assign("sqzfb", 0);
|
|
}
|
|
|
|
// pp($orderno);
|
|
$this->assign('payway', $payway);
|
|
$this->assign("orderno", $orderno);
|
|
$this->assign("paytype", $paytype);
|
|
$this->assign ('pay_url', $result['pay_url']);
|
|
$this->assign("sdk_version", $result['sdk_version']?:0);
|
|
$this->assign ('Scheme', $Scheme);
|
|
$this->assign ('gopay', $gopay);
|
|
$this->assign ('user_token', $userToken);
|
|
$this->assign ('game_id', $gameId);
|
|
|
|
$this->assign ('gopay_url', $gopayUrl);
|
|
$this->assign ('paystatus', $result ['pay_status']);
|
|
$this->display ();
|
|
}
|
|
|
|
/**
|
|
* 订单状态 return 0未支付 1已支付
|
|
*/
|
|
public function order_status() {
|
|
$userToken = I('user_token');
|
|
$orderno = I('orderno');
|
|
$gameId = I('game_id');
|
|
$pay_where = substr ($orderno, 0, 2);
|
|
$payStatus = 0;
|
|
$table = "spend";
|
|
if ($pay_where == "SP") {
|
|
$table = "spend";
|
|
}
|
|
if ($pay_where == "PF") {
|
|
$table = "deposit";
|
|
}
|
|
|
|
$order = M($table, "tab_")->where(['pay_order_number' => $orderno])->find();
|
|
$payStatus = $order["pay_status"];
|
|
|
|
echo json_encode([
|
|
'type' => $table,
|
|
'payStatus' => $payStatus?'1':'0',
|
|
'game_id' => $gameId,
|
|
'url' => "/sdk.php/userH/get_user_money/user_token/{$userToken}/game_id/{$gameId}/sdk_version/{$order['sdk_version']}api_ver/2", //?action=pay&nav_title=%E4%BD%99%E9%A2%9D
|
|
]);
|
|
exit();
|
|
}
|
|
|
|
// 快捷支付通知
|
|
public function shortcut_notice() {
|
|
$status = $_GET['status'];
|
|
$orderno = $_GET ['orderno'] == "" ? $_GET ['out_trade_no'] : $_GET ['orderno'];
|
|
|
|
$pay_where = substr($orderno, 0, 2);
|
|
$Scheme = file_get_contents ( "./Application/Sdk/Scheme/" . $_GET ['game_id'] . ".txt" );
|
|
$map ['pay_order_number'] = $orderno;
|
|
switch ($pay_where) {
|
|
case 'SP' :
|
|
$result = M ( 'Spend', 'tab_' )->field ( "pay_status" )->where ( $map )->find ();
|
|
break;
|
|
case 'PF' :
|
|
$result = M ( 'deposit', 'tab_' )->field ( 'pay_status' )->where ( $map )->find ();
|
|
break;
|
|
case 'TB' :
|
|
$result = M ( 'balance', 'tab_' )->field ( 'pay_status' )->where ( $map )->find ();
|
|
break;
|
|
case 'BR' :
|
|
$result = M ( 'bind_recharge', 'tab_' )->field ( 'pay_status' )->where ( $map )->find ();
|
|
break;
|
|
}
|
|
$this->assign('Scheme', $Scheme);
|
|
$this->assign('status', $status);
|
|
$this->display();
|
|
|
|
}
|
|
|
|
// 通知下线
|
|
public function notice_logout() {
|
|
$this->display();
|
|
}
|
|
|
|
}
|