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.

285 lines
10 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 ("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;
}
// 微信 支付宝 快捷
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") {
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']}/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/PayH5/platform__alipay_pay/pay_order_number/{$result['pay_order_number']}/game_id/{$result['game_id']}/user_token/{$userToken}";
}
$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 ();
}
}