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.

534 lines
18 KiB
PHTML

5 years ago
<?php
namespace Sdk\Controller;
use Think\Controller;
use Org\JtpaySDK\Jtpay;
use Org\SqpaySDK\Sqpay;
use Think\Log;
5 years ago
use Qiniu\json_decode;
5 years ago
class SpendController extends Controller {
5 years ago
/**
* 转发支付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();
}
5 years ago
$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());
5 years ago
$pay_info = M('pay_info', 'tab_')->where([
'user_id' => $user_id,
'game_id' => $game_id
])->order("id desc")->find();
$request = json_decode($pay_info['info'], true);
/* $file = file_get_contents ( "./Application/Sdk/OrderNo/" . $user_id . "-" . $game_id . ".txt" );
$request = json_decode ( think_decrypt ( $file ), true ); */
5 years ago
$data = array(
'coin' => $request ['body'],
'price' => $request ['price'] + $request['deduction_amount'],
5 years ago
'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', isset($request['btncolor']) ? $request['btncolor'] : '' );
5 years ago
if ($balance + $bind_balance > $data['price']) {
$apply_money = $data['price'];
$this->assign ('pay_price', 0); // 是否第三方支付
5 years ago
} else {
$apply_money = $balance + $bind_balance;
$payPrice = round($data['price'] - $balance - $bind_balance, 2);
5 years ago
$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();
5 years ago
5 years ago
}
5 years ago
5 years ago
public function pay_way_v1() {
$user_id = I ('user_id');
$game_id = I ('game_id');
$pay_info = M('pay_info', 'tab_')->where([
'user_id' => $user_id,
'game_id' => $game_id
])->order("id desc")->find();
$request = json_decode($pay_info['info'], true);
/* $file = file_get_contents ( "./Application/Sdk/OrderNo/" . $user_id . "-" . $game_id . ".txt" );
$request = json_decode ( think_decrypt ( $file ), true ); */
5 years ago
C(BaseController::get_tool());
5 years ago
$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 ();
}
5 years ago
/**
* 支付页面
*
* @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();
} */
5 years ago
public function pay_success() {
$orderno = I('request.orderno');
if (!$orderno) $orderno = I('request.out_trade_no');
$pay_where = substr($orderno, 0, 2);
$pay_info = M('pay_info', 'tab_')->where(['order_id' => $orderno])->find();
$json = json_decode($pay_info['info'], true);
$Scheme = $json['scheme'];
// $Scheme = file_get_contents ( "./Application/Sdk/Scheme/" . $_GET ['game_id'] . ".txt" );
5 years ago
$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 ();
}
5 years ago
5 years ago
public function pay_success2() {
$orderno = I('request.orderno');
if (!$orderno) $orderno = I('request.out_trade_no');
$pay_where = substr($orderno, 0, 2);
$pay_info = M('pay_info', 'tab_')->where(['order_id' => $orderno])->find();
$json = json_decode($pay_info['info'], true);
$Scheme = $json['scheme'];
//$orderno = $_GET ['orderno'] == "" ? $_GET ['out_trade_no'] : $_GET ['orderno'];
5 years ago
$pay_where = substr ( $orderno, 0, 2 );
//$Scheme = file_get_contents ( "./Application/Sdk/Scheme/" . $_GET ['game_id'] . ".txt" );
5 years ago
$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 = I('request.orderno');
if (!$orderno) $orderno = I('request.out_trade_no');
// $orderno = $_GET ['orderno'] == "" ? $_GET ['out_trade_no'] : $_GET ['orderno'];
// if (! empty ( $_GET ['jinzhue'] )) {
// $orderno = $_GET ['jinzhue'];
// }
5 years ago
$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'] );
5 years ago
$this->display ( 'pay_success3' );
5 years ago
}
public function pay_error() {
$Scheme = file_get_contents ( "./Application/Sdk/Scheme/" . $_GET ['game_id'] . ".txt" );
$this->assign ('Scheme', $Scheme?$Scheme:'txplatformsdk');
$this->display ();
}
5 years ago
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'))));
}
5 years ago
$this->display ();
}
5 years ago
public function notice_v1($user_id = 0, $game_id = 0, $msg = '') {
$this->display ();
}
/*
5 years ago
* ALTER TABLE `tab_deposit`
ADD COLUMN `pay_url` varchar(255) NOT NULL DEFAULT '' AFTER `check_sign`;
* 支付中转页
*/
public function paycallback() {
$userToken = I('user_token');
$orderno = I('request.orderno');
if (!$orderno) $orderno = I('request.out_trade_no');
// $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;
5 years ago
$paytype = I('request.paytype', 0); // 支付方式 weixinpay alipay
5 years ago
$gopay = I('request.gopay');
switch ($pay_where) {
case 'SP' :
5 years ago
$result = M('Spend', 'tab_')->field ("*")->where ($map)->find();
break;
case 'PF' :
5 years ago
$result = M('deposit', 'tab_')->field ('*')->where ($map)->find();
break;
case 'TB' :
5 years ago
$result = M('balance', 'tab_')->field ('*')->where ($map)->find();
break;
case 'BR' :
5 years ago
$result = M('bind_recharge', 'tab_')->field ('*')->where ($map)->find();
break;
}
5 years ago
// 支付成功跳转页面
if ($result['pay_status'] == 1) {
5 years ago
// $this->success("支付成功", U("userH/get_user_money", ['user_token' => $userToken]));
5 years ago
}
// 微信 支付宝 快捷
5 years ago
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'))
5 years ago
$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'];
5 years ago
}
if ($pay_where == "PF") {
5 years ago
$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}";
5 years ago
}
5 years ago
// 如果是json格式 且是alipay 则 alipay app
if (json_decode($gopayUrl) && $paytype == 'alipay') {
$this->assign("aliapp", 1);
} else {
$this->assign("aliapp", 0);
5 years ago
}
if(get_zfb_type() == 2) {
$this->assign("sqzfb", 1);
} else {
$this->assign("sqzfb", 0);
5 years ago
}
5 years ago
5 years ago
// pp($orderno);
5 years ago
$this->assign('payway', $payway);
5 years ago
$this->assign("orderno", $orderno);
5 years ago
$this->assign("paytype", $paytype);
5 years ago
$this->assign ('pay_url', $result['pay_url']);
5 years ago
$this->assign("sdk_version", $result['sdk_version']?:0);
$this->assign ('Scheme', $Scheme);
5 years ago
$this->assign ('gopay', $gopay);
5 years ago
$this->assign ('user_token', $userToken);
$this->assign ('game_id', $gameId);
5 years ago
$this->assign ('gopay_url', $gopayUrl);
$this->assign ('paystatus', $result ['pay_status']);
$this->display ();
}
5 years ago
/**
* 订单状态 return 0未支付 1已支付
*/
public function order_status() {
5 years ago
$userToken = I('user_token');
5 years ago
$orderno = I('orderno');
$gameId = I('game_id');
5 years ago
$pay_where = substr ($orderno, 0, 2);
$payStatus = 0;
5 years ago
$table = "spend";
5 years ago
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"];
5 years ago
echo json_encode([
5 years ago
'type' => $table,
5 years ago
'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
5 years ago
]);
exit();
}
5 years ago
// 快捷支付通知
5 years ago
public function shortcut_notice() {
5 years ago
$status = $_GET['status'];
$orderno = I('request.orderno');
if (!$orderno) $orderno = I('request.out_trade_no');
5 years ago
$pay_where = substr($orderno, 0, 2);
$pay_info = M('pay_info', 'tab_')->where(['order_id' => $orderno])->find();
$json = json_decode($pay_info['info'], true);
$Scheme = $json['scheme'];
// $Scheme = file_get_contents ( "./Application/Sdk/Scheme/" . $_GET ['game_id'] . ".txt" );
5 years ago
$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);
5 years ago
$this->assign('status', $status);
5 years ago
$this->display();
}
5 years ago
// 通知下线
public function notice_logout() {
$this->display();
}
// 易宝快捷支付 通知页面
public function shortcut_payed() {
$userToken = I('user_token');
$orderno = I('request.orderno');
if (!$orderno) $orderno = I('request.out_trade_no');
// $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") {
$gopayUrl = $result['pay_url'];
}
if ($pay_where == "PF") {
$gopayUrl = $result['pay_url'];
}
// 如果是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("price", $result['pay_amount']);
$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 ();
}
5 years ago
}