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.
319 lines
11 KiB
PHP
319 lines
11 KiB
PHP
<?php
|
|
|
|
namespace Sdk\Controller;
|
|
|
|
use Think\Controller;
|
|
use Org\JtpaySDK\Jtpay;
|
|
use Org\SqpaySDK\Sqpay;
|
|
use Think\Log;
|
|
|
|
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', 'tab_')->where(['user_token'=>$user_token])->getField('id');
|
|
if ($userId != $user_id) {
|
|
echo "请重新登入!";
|
|
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']) {
|
|
$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: *"); */
|
|
$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('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();
|
|
|
|
}
|
|
|
|
/**
|
|
* 支付页面
|
|
*
|
|
* @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_success' );
|
|
}
|
|
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, $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");
|
|
$map ['pay_order_number'] = $orderno;
|
|
$type = I('request.type', 0); // 1 直接唤起支付
|
|
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}";
|
|
}
|
|
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}";
|
|
}
|
|
// pp($gopayUrl);
|
|
|
|
$this->assign("orderno", $orderno);
|
|
$this->assign("type", $type);
|
|
$this->assign ('pay_url', $result['pay_url']);
|
|
$this->assign("device", $result['sdk_version']?:0);
|
|
$this->assign ('Scheme', $Scheme);
|
|
|
|
$this->assign ('gopay_url', $gopayUrl);
|
|
$this->assign ('paystatus', $result ['pay_status']);
|
|
$this->display ();
|
|
}
|
|
|
|
/**
|
|
* 订单状态 return 0未支付 1已支付
|
|
*/
|
|
public function order_status() {
|
|
|
|
$orderno = I('orderno');
|
|
$pay_where = substr ($orderno, 0, 2);
|
|
$payStatus = 0;
|
|
$table = "Spend";
|
|
if ($pay_where == "SP") {
|
|
$table = "spend";
|
|
}
|
|
if ($pay_where == "PF") {
|
|
$table = "deposit";
|
|
}
|
|
|
|
$payStatus = M($table, "tab_")->where(['pay_order_number' => $orderno])->getField("pay_status");
|
|
|
|
echo json_encode([
|
|
'payStatus' => $payStatus?'1':'0',
|
|
]);
|
|
exit();
|
|
}
|
|
|
|
}
|