|
|
<?php
|
|
|
namespace Sdk\Controller;
|
|
|
use Think\Controller;
|
|
|
use Common\Api\GameApi;
|
|
|
use Org\WeixinSDK\Weixin;
|
|
|
use Org\HeepaySDK\Heepay;
|
|
|
use Org\UcenterSDK\Ucservice;
|
|
|
use Org\SwiftpassSDK\Swiftpass;
|
|
|
use Org\JtpaySDK\Jtpay;
|
|
|
use Org\GoldPig\GoldPig;
|
|
|
use Org\SqpaySDK\Sqpay;
|
|
|
use Qiniu\json_decode;
|
|
|
use Think\Log;
|
|
|
class WapPayController extends BaseController{
|
|
|
|
|
|
private function pay($param=array()){
|
|
|
$table = $param['code'] == 1 ? "spend" : "deposit";
|
|
|
$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'];
|
|
|
$vo = new \Think\Pay\PayVo();
|
|
|
$vo->setBody("充值记录描述")
|
|
|
->setFee($param['price'])//支付金额
|
|
|
->setTitle($param['title'])
|
|
|
->setBody($param['body'])
|
|
|
->setOrderNo($param['out_trade_no'])
|
|
|
->setRatio(get_game_selle_ratio($param["game_id"]))
|
|
|
->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'])
|
|
|
->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'])
|
|
|
->setDiscount($discount)
|
|
|
->setSmallId($param['small_user_id'])
|
|
|
->setSmallAccount(get_user_account_by_id($param['small_user_id']));
|
|
|
return $pay->buildRequestForm($vo, 0, $param);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
*支付宝移动支付
|
|
|
*/
|
|
|
public function alipay_pay(){
|
|
|
$request = json_decode(base64_decode(file_get_contents("php://input")),true);
|
|
|
// 支付验证 是否让支付
|
|
|
$payCheck = pay_check($request['user_id']);
|
|
|
if (!$payCheck['code']) {
|
|
|
$this->set_message(1088, "fail", $payCheck['msg']);
|
|
|
}
|
|
|
file_put_contents(dirname(__FILE__) . '/alipay_paywap.txt',json_encode($request));
|
|
|
C(api('Config/lists'));
|
|
|
if (empty($request)) {
|
|
|
$this->set_message(1001, "fail", "登录数据不能为空");
|
|
|
}
|
|
|
$game = M('Game','tab_')->where(['id'=>$request['game_id']])->field('pay_status')->find();
|
|
|
if($game['pay_status'] == 0){
|
|
|
$this->set_message(0,"fail","该游戏暂时无法充值,请联系客服!");
|
|
|
}
|
|
|
if($request['code'] == 1){ // 1正常充值 0平台币充值
|
|
|
$extend_data = M('spend','tab_')->where(array('extend'=>$request['extend'],'pay_status'=>1,'game_id'=>$request['game_id']))->find();
|
|
|
if($extend_data){
|
|
|
$this->set_message(1089,"fail","订单号重复,请关闭支付页面重新支付");
|
|
|
}
|
|
|
}
|
|
|
if($request['price']*1<=0){
|
|
|
$this->set_message(1011,"fail","充值金额有误");
|
|
|
}
|
|
|
|
|
|
$prefix = $request['code'] == 1 ? "SP_" : "PF_";
|
|
|
$out_trade_no = $prefix.date('Ymd').date('His').sp_random_string(4);
|
|
|
|
|
|
$request = $this->other_price($request);
|
|
|
//Log::write(serialize($request), Log::DEBUG);
|
|
|
|
|
|
if(get_zfb_type()==0){
|
|
|
$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['price'];
|
|
|
$request['body']=$request['price'];
|
|
|
$request['out_trade_no'] = $out_trade_no;
|
|
|
//$this->set_message(1011,"fail", $request['code']);
|
|
|
$pay_url=$this->pay($request);
|
|
|
|
|
|
|
|
|
$data = array(
|
|
|
'status' => 200,
|
|
|
"out_trade_no" => $out_trade_no,
|
|
|
"url" => $pay_url,
|
|
|
);
|
|
|
|
|
|
} elseif (get_zfb_type() == 2) { // 双乾支付H5
|
|
|
$request['pay_order_number'] = $out_trade_no;
|
|
|
$request['pay_way'] = C('PAY_WAY.SQ_ALIPAY');
|
|
|
$request['pay_status'] = 0;
|
|
|
$request['spend_ip'] = get_client_ip();
|
|
|
|
|
|
if($request['code']==1){
|
|
|
$this->add_spend($request,1);
|
|
|
}else{
|
|
|
$this->add_deposit($request);
|
|
|
}
|
|
|
$sqpay=new Sqpay();
|
|
|
$returl = C('pay_header'). "/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'] = "ZFBZF";
|
|
|
$data['MerRemark'] = "mark";
|
|
|
$data['subject'] = "subject";
|
|
|
$data['notifyurl'] = C('pay_header')."/callback.php/Notify/sq_callback";//通知
|
|
|
$data['returnurl'] = $returl;
|
|
|
$data['mchAppId'] = "wmtxkj.com";
|
|
|
$data['mchAppName'] = "mchAppName";
|
|
|
$data['deviceInfo'] = "AND_WAP";
|
|
|
$data['clientIp'] = get_client_ip();
|
|
|
|
|
|
$ret = $sqpay->sq_pay($data);
|
|
|
$ret = json_decode($ret, true);
|
|
|
|
|
|
unset($data);
|
|
|
if($ret[0]['respCode'] == '000000'){
|
|
|
$data = array(
|
|
|
"status" => 200,
|
|
|
"out_trade_no" => $out_trade_no,
|
|
|
"url" => $ret[0]['payURL'],
|
|
|
);
|
|
|
}else{
|
|
|
$data = array(
|
|
|
"status" => 0,
|
|
|
"out_trade_no" => $out_trade_no,
|
|
|
"url" => $ret['respMess'],
|
|
|
);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
else{
|
|
|
if( empty(C('goldpig.partner'))||empty(C('goldpig.wooolid'))){
|
|
|
$this->set_message(1009, "fail", "支付参数未配置");
|
|
|
}
|
|
|
|
|
|
if($request['price']*1<1){
|
|
|
$this->set_message(1011,"fail","单笔交易金额必须大于1元");
|
|
|
}
|
|
|
|
|
|
$request['pay_way'] = 8;
|
|
|
$request['pay_status'] = 0;
|
|
|
$request['pay_order_number'] = $out_trade_no;
|
|
|
$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);
|
|
|
}else{
|
|
|
$this->add_deposit($request);
|
|
|
}
|
|
|
|
|
|
|
|
|
$goldpig=new GoldPig();
|
|
|
$pay_url = $goldpig->GoldPig($user['account'],$pay_amount,15,$request['pay_order_number']);
|
|
|
|
|
|
|
|
|
if($pay_url['status']==0){
|
|
|
$url='http://'.$_SERVER['HTTP_HOST'];
|
|
|
$data = array(
|
|
|
'status' => 0,
|
|
|
"out_trade_no" => $out_trade_no,
|
|
|
"url" => $pay_url['info'],
|
|
|
);
|
|
|
}else{
|
|
|
$data = array(
|
|
|
'status' => 200,
|
|
|
"out_trade_no" => $out_trade_no,
|
|
|
"url" => $pay_url['msg'],
|
|
|
);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
echo base64_encode(json_encode($data));
|
|
|
}
|
|
|
/**\
|
|
|
* 快捷支付'merNo' => $data['merNo'],
|
|
|
'merOrderNo' => $data['merOrderNo'],
|
|
|
'cardNo' => $data['cardNo'],
|
|
|
'custName' => $data['custName'],
|
|
|
'idType' => '0',
|
|
|
'idNo' => $data['idNo'],
|
|
|
'phone' => $data['phoneNo'],
|
|
|
'purpose' => $data['purpose'],
|
|
|
'payAmount' => $data['payAmount'],
|
|
|
'bankCode' => $bankInfo['bank'],
|
|
|
'payType' => 'XYPAY',
|
|
|
'NotifyURL' => $data['NotifyURL'],
|
|
|
'txnTime' => $data['txnTime'],
|
|
|
'smsCode' => $data['smsCode'],
|
|
|
*/
|
|
|
public function shortcut_pay() {
|
|
|
$sqpay = new Sqpay();
|
|
|
$param = I();
|
|
|
$signContract = false; // 签约标记
|
|
|
|
|
|
if (!$param['user_id'] || !$param['game_id']) {
|
|
|
$this->error("参数有误", '', true);
|
|
|
}
|
|
|
|
|
|
// 支付验证 是否让支付
|
|
|
$payCheck = pay_check($param['user_id']);
|
|
|
if (!$payCheck['code']) {
|
|
|
$this->set_message(1088, "fail", $payCheck['msg']);
|
|
|
}
|
|
|
|
|
|
$payInfo = M('pay_info', 'tab_')->where(array(
|
|
|
'user_id' => $param['user_id'],
|
|
|
'game_id' => $param['game_id']
|
|
|
))->order('id desc')->find();
|
|
|
if ($payInfo['price'] <= 0) {
|
|
|
$this->error("数据有误", '', true);
|
|
|
}
|
|
|
if ($payInfo['status'] == 'payed') {
|
|
|
$this->error("订单已支付");
|
|
|
}
|
|
|
|
|
|
// 发起支付
|
|
|
if (IS_POST && $param['smsCode']) {
|
|
|
//echo "发起支付==》".time()."<br>";
|
|
|
$rsp = $sqpay->shortcut_pay(array(
|
|
|
'merNo' => C('sqpay.partner'),
|
|
|
'merOrderNo' => $payInfo['order_id'],
|
|
|
'custName' => $param['custName'],
|
|
|
'phoneNo' => $param['phoneNo'],
|
|
|
'cardNo' => $param['cardNo'],
|
|
|
'idNo' => $param['idNo'],
|
|
|
'purpose' => 'purpose',
|
|
|
'payAmount' => $payInfo['price'],
|
|
|
'txnTime' => $payInfo['txnTime'],
|
|
|
'smsCode' => $param['smsCode'],
|
|
|
'secret' => C('sqpay.key'),
|
|
|
));
|
|
|
//echo "发起支付==》".time()."<br>";
|
|
|
sleep(5);
|
|
|
if ($rsp['responseCode'] == '88') {
|
|
|
redirect(U('Spend/pay_success',array('orderno' => $payInfo['order_id'], 'user_id'=>$param['user_id'],'game_id'=>$param['game_id'])));exit;
|
|
|
} else {
|
|
|
// 支付失败
|
|
|
redirect(U('Spend/pay_success',array('orderno' => $payInfo['order_id'], 'user_id'=>$param['user_id'],'game_id'=>$param['game_id'])));exit;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 发送短信
|
|
|
if (IS_POST && !isset($param['smsCode'])) {
|
|
|
// 查看是否签约
|
|
|
//echo "查看是否签约==》".time()."<br>";
|
|
|
$rcs = $sqpay->contract_status(array(
|
|
|
'merNo' => C('sqpay.partner'),
|
|
|
'custName' => $param['custName'],
|
|
|
'phoneNo' => $param['phoneNo'],
|
|
|
'cardNo' => $param['cardNo'],
|
|
|
'idNo' => $param['idNo'],
|
|
|
'payAmount' => $payInfo['price'],
|
|
|
'secret' => C('sqpay.key'),
|
|
|
));
|
|
|
//echo "查看是否签约==》".time()."<br>";
|
|
|
if ($rcs['respCode'] == 4) {
|
|
|
$this->error($rcs['respMessage'], '', true);
|
|
|
pp($rcs);
|
|
|
pp($rcs['respMessage']);
|
|
|
}
|
|
|
// 调用认证 签约
|
|
|
if ($rcs['respCode'] == 1 || $rcs['respCode'] == 2 || $rcs['respCode'] == 3) {
|
|
|
//echo "调用认证 签约==》".time()."<br>";
|
|
|
$rsign = $sqpay->sign_contract(array(
|
|
|
'merNo' => C('sqpay.partner'),
|
|
|
'custName' => $param['custName'],
|
|
|
'phoneNo' => $param['phoneNo'],
|
|
|
'cardNo' => $param['cardNo'],
|
|
|
'idNo' => $param['idNo'],
|
|
|
'reqMsgId' => date('YmdHis').rand(0, 9999),
|
|
|
'authMsg' => 'ok',
|
|
|
'custType' => '01',
|
|
|
'secret' => C('sqpay.key'),
|
|
|
));
|
|
|
//echo "调用认证 签约==》".time()."<br>";
|
|
|
if ($rsign['respCode'] == 'success') { // 认证成功 接着签约
|
|
|
$rauth = $sqpay->sign_contract(array(
|
|
|
'merNo' => C('sqpay.partner'),
|
|
|
'custName' => $param['custName'],
|
|
|
'phoneNo' => $param['phoneNo'],
|
|
|
'cardNo' => $param['cardNo'],
|
|
|
'idNo' => $param['idNo'],
|
|
|
'reqMsgId' => date('YmdHis').rand(0, 9999),
|
|
|
'authMsg' => $rsign['authMsg'],
|
|
|
'custType' => '02',
|
|
|
'secret' => C('sqpay.key'),
|
|
|
));
|
|
|
if ($rauth['respCode'] == 'success') {
|
|
|
$signContract = true;
|
|
|
} else {
|
|
|
$this->error($rauth['respMessage'], '', true);
|
|
|
}
|
|
|
} else {
|
|
|
$this->error($r['respMessage'], '', true);
|
|
|
}
|
|
|
}
|
|
|
// 无需签约 发送短信
|
|
|
if ($rcs['respCode'] == 0 || $rcs['respCode'] == 10) {
|
|
|
//echo "发送短信==》".time()."<br>";
|
|
|
$ret = $sqpay->protocol_pay_send_sms(array(
|
|
|
'merNo' => C('sqpay.partner'),
|
|
|
'custName' => $param['custName'],
|
|
|
'phoneNo' => $param['phoneNo'],
|
|
|
'cardNo' => $param['cardNo'],//'6214855913999401',
|
|
|
'idNo' => $param['idNo'],
|
|
|
'payAmount' => $payInfo['price'],
|
|
|
'secret' => C('sqpay.key'),
|
|
|
'merOrderNo' => $payInfo['order_id'],
|
|
|
'NotifyURL' => "http://api.wmtxkj.com"."/callback.php?Notify/sq_callback",
|
|
|
'purpose' => 'aaaa'
|
|
|
));
|
|
|
//echo "发送短信==》".time()."<br>";
|
|
|
if ($ret['resFlag'] == 'success') {
|
|
|
M('pay_info', 'tab_')->where(array(
|
|
|
'id' => $payInfo['id'],
|
|
|
))->save(array(
|
|
|
'txn_time' => $ret['txnTime']
|
|
|
));
|
|
|
$this->success('发送成功', '', true);
|
|
|
} else {
|
|
|
$this->error($ret['resMess'], '', true);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
$this->display();
|
|
|
|
|
|
}
|
|
|
/**
|
|
|
* 测试
|
|
|
*/
|
|
|
public function test() {
|
|
|
$sqpay = new Sqpay();
|
|
|
$r = $sqpay->contract_status(array(
|
|
|
'merNo' => 204121,
|
|
|
'custName' => '张谷城',
|
|
|
'phoneNo' => '18950494552',
|
|
|
'cardNo' => '6225768783753476',
|
|
|
'idNo' => '352228199110130536',
|
|
|
'payAmount' => 0.01,
|
|
|
'secret' => 'NsyJOE!e',
|
|
|
));
|
|
|
if ($r['respCode'] == 4) {
|
|
|
pp($r);
|
|
|
pp($r['respMessage']);
|
|
|
}
|
|
|
// 调用签约
|
|
|
if ($r['respCode'] == 1 || $r['respCode'] == 2 || $r['respCode'] == 3) {
|
|
|
|
|
|
}
|
|
|
|
|
|
// 无需签约 发送短信
|
|
|
if ($r['respCode'] == 0 || $r['respCode'] == 10) {
|
|
|
$sqpay->protocol_pay_send_sms(array(
|
|
|
'merNo' => 204121,
|
|
|
'custName' => '张谷城',
|
|
|
'phoneNo' => '18950494552',
|
|
|
'cardNo' => '6225768783753476',//'6214855913999401',
|
|
|
'idNo' => '352228199110130536',
|
|
|
'payAmount' => 0.01,
|
|
|
'secret' => 'NsyJOE!e',
|
|
|
'merOrderNo' => 'SP_dfjlasjd1',
|
|
|
'NotifyURL' => 'www.baidu.com',
|
|
|
'purpose' => 'aaaa'
|
|
|
));
|
|
|
}
|
|
|
pp($r);
|
|
|
|
|
|
$url = "https://ccdcapi.alipay.com/validateAndCacheCardInfo.json";
|
|
|
$data['cardNo'] = "6225768783753476";
|
|
|
$r = curl_post($url, array('cardNo' => $data['cardNo'], 'cardBinCheck' => 'true', '_input_charset' => 'utf-8'));
|
|
|
$r = (json_decode($r, true));
|
|
|
pp($r['bank']);
|
|
|
$sqpay = new Sqpay();
|
|
|
$order_no = "232323";
|
|
|
$ret = $sqpay->sq_wxsmallpay($order_no);
|
|
|
pp(json_decode($ret[0]['wxjsapiStr']));
|
|
|
|
|
|
$request = json_decode(think_decrypt("MDAwMDAwMDAwMJndsKKZZYuXeqCgy324cpebidDdi6mplZy2vKCFdqeagKewp5CKas6JaJ3Nec6fnYSJtt96ztqbmbq0mpyJr5qDza-wgJywy4tod9aKummcmn2n1YuorGiBzKdoipyzqIG4q2mJnX6Xfnp3poKogayAntzOkr2xmJGVsKCRirSdjJafspF6j9uTpIfWirx5nYaert16ztqbm5S8rZyfuKqMlpuhmYqOy4Cfest8p3plmme73omXz52BzNWdh3ajmoCnsLOReq3IlaOH25OWnKqZnq6bes-sm4SlsGSZirSkjrevb4Cgh9iTiWaWkbuUZZpnt9d907VjmqmfqZJkrJmWlrihmWRyxZWKi81-q3qXm4nNzoupuZWctsCghazKlJi4v7KEepLRiX6Gln3RiWmPfbqXf9_PnJCqu2eFnLNlf7evrICgh9iLfYbLf815rICe3M6Ura2ikZS7nYeco6aBqKusgKCDkpOjf9iSq2mtgJ_Uzn7PqZuFubydgZvZmpeWtKiRimrOeqCgy5SsmKuZfKuVi9Kcq5q6tJ-Zq6ukfdHKoZmKj8iUfanKlbuGrY9nms2TvLibh8uvnYR1rKWOqLyfmmWl0JOfeph5znKehYyymn-8vKuGps6chYbOnY6otKWEoIvNfoqU2n3Odp6Eebaafs-0Y4HL3Z2SisphjrubpICdqMuUaIfblNGGrYqMtp5-mNtjm5S8rYuJs2qBuKexhIuG3JR6itl_qJtmnX2n3pOXtWORlbh-knaSqYHOq2qFnaCVfop6lX7OhZ2DeK_NipexqJy5m2SBnNGamKu8s5t3etl-iXrVedGUnJmMu8uT0qmmkrWvaoGe2mKC0bdpkJ-xk4B9e81-uqhlhaK634Cr22OGzK-rkpvKlJi4zbKRnaXFlYqKlX-7fpebicjef6nKooHL3Z2ZiZurjJfApZqhh9KTaGXLf815rIOfptp-qKylgdConJ2Im6eX0bilmp9y15WNYsuKvHmdhp6vuYarm6uFpqtphXbNqYLeq2yErYKSf4x6k5KqeZ2DeK_cir3PmJuVuJycerirfc7VsIN2g9mKjp3IlJZ2aYCf1Jh9qK2sm6m8qZJ4m6GXp69vgJ1-236JZdt9qIGphK-62n65yquB0JZx"),true);
|
|
|
pp($request);
|
|
|
$pay['agent_id'] = "2083328";//商户号
|
|
|
$pay['order_no'] = "SP_111111002";
|
|
|
$pay['time'] = date('YmdHis', time());
|
|
|
$pay['pay_type'] = 30;
|
|
|
$pay['amount'] = 0.01;
|
|
|
$pay['user_ip'] = get_client_ip();
|
|
|
$pay['sign_key'] = "852B4A10455E49F280EEFCB1";//密钥
|
|
|
$pay['payerName'] = "yb";
|
|
|
$pay['number'] = 1;
|
|
|
$pay['payerName'] = "sp";
|
|
|
$pay['goods_name'] = "cs";
|
|
|
$pay['goods_note']="cs";
|
|
|
$pay['device'] = "wap";
|
|
|
$pay['remark'] = "ios";
|
|
|
$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'];
|
|
|
$heepay = new Heepay();
|
|
|
$token_id = $heepay->wxh5_pay($pay);
|
|
|
pp($token_id);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* android获取 支付url
|
|
|
*/
|
|
|
public function android_shortcut_pay() {
|
|
|
$request = json_decode(base64_decode(file_get_contents("php://input")), true);
|
|
|
file_put_contents("./Application/Sdk/OrderNo/".$request['user_id']."-".$request['game_id'].".txt",think_encrypt(json_encode($request)));
|
|
|
|
|
|
// 支付验证 是否让支付
|
|
|
$payCheck = pay_check($request['user_id']);
|
|
|
if (!$payCheck['code']) {
|
|
|
$this->set_message(1088, "fail", $payCheck['msg']);
|
|
|
}
|
|
|
$user_id = $request['user_id'];
|
|
|
$game_id = $request['game_id'];
|
|
|
$data = array(
|
|
|
'status' => 200,
|
|
|
"url" => 'http://' . $_SERVER ['HTTP_HOST'] ."/sdk.php/WapPay/wap_shortcut_pay/user_id/{$user_id}/game_id/{$game_id}",
|
|
|
"html" => '',
|
|
|
"return_msg" => '',
|
|
|
"paytype" => 'shortcut',
|
|
|
);
|
|
|
|
|
|
echo base64_encode(json_encode($data));
|
|
|
exit();
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 快捷支付 用户点击
|
|
|
*/
|
|
|
public function wap_shortcut_pay($user_id,$game_id)
|
|
|
{
|
|
|
$file=file_get_contents("./Application/Sdk/OrderNo/".$user_id."-".$game_id.".txt");
|
|
|
$request = json_decode(think_decrypt($file),true);
|
|
|
Log::write(serialize($request), Log::DEBUG);
|
|
|
/* $request['user_id'] = 232;
|
|
|
$request['game_id'] = 78;
|
|
|
$request['price'] = 0.02;
|
|
|
$request['code'] = 1;
|
|
|
$request['extend'] = "SP_522992339581";
|
|
|
$request['pay_order_number'] = "SP_24522992339581"; */
|
|
|
|
|
|
if (empty($request)) {
|
|
|
redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'登录数据不能为空')));exit;
|
|
|
}
|
|
|
// 支付验证 是否让支付
|
|
|
$payCheck = pay_check($request['user_id']);
|
|
|
if (!$payCheck['code']) {
|
|
|
$this->set_message(1088, "fail", $payCheck['msg']);
|
|
|
}
|
|
|
|
|
|
$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'=>'该游戏暂时无法充值,请联系客服!')));exit;
|
|
|
}
|
|
|
if($request['price']*1<=0){
|
|
|
redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'充值金额有误')));exit;
|
|
|
}
|
|
|
|
|
|
C(api('Config/lists'));
|
|
|
|
|
|
if($request['code'] == 1){ // 1正常充值 0平台币充值
|
|
|
$extend_data = M('spend','tab_')->where(array('extend'=>$request['extend'],'game_id'=>$request['game_id'],'pay_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'])));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'] = 15; // 支付方式(-1绑币 0:平台币,1:支付宝,2:微信(扫码)3微信app 4 威富通 5聚宝云 6竣付通 7苹果支付8金猪支付 9双乾支付-支付宝 10双乾支付-银联 15双乾支付-快捷
|
|
|
$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)));exit;
|
|
|
}
|
|
|
|
|
|
$this->other_price($request, $request['price']-$pay_amount);
|
|
|
|
|
|
//0 官方 1双乾
|
|
|
if (get_shortcut_pay_type() == 0) {
|
|
|
// 暂时只有双乾
|
|
|
}elseif(get_shortcut_pay_type() == 1){
|
|
|
|
|
|
M('pay_info', 'tab_')->add(array(
|
|
|
'user_id' => $request['user_id'],
|
|
|
'game_id' => $request['game_id'],
|
|
|
'order_id' => $request['pay_order_number'],
|
|
|
'price' => $request['actual_amount'],
|
|
|
'type' => 'sq_shortcut',
|
|
|
'info' => json_encode($request),
|
|
|
'status' => 'normal',
|
|
|
'create_time' => time(),
|
|
|
));
|
|
|
if($request['code']==1){
|
|
|
$this->add_spend($request,1);
|
|
|
}else{
|
|
|
$this->add_deposit($request);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
$this->assign("pay_amount", $request['actual_amount']);
|
|
|
$this->assign("user_id", $request['user_id']);
|
|
|
$this->assign("game_id", $request['game_id']);
|
|
|
$this->display();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
*微信支付
|
|
|
*/
|
|
|
public function weixin_pay()
|
|
|
{
|
|
|
#获取SDK上POST方式传过来的数据 然后base64解密 然后将json字符串转化成数组
|
|
|
$request = json_decode(base64_decode(file_get_contents("php://input")), true);
|
|
|
/* file_put_contents(dirname(__FILE__) . '/weixin_paywap.txt',json_encode($request)); */
|
|
|
|
|
|
if (empty($request)) {
|
|
|
$this->set_message(1001, "fail", "登录数据不能为空");
|
|
|
}
|
|
|
// 支付验证 是否让支付
|
|
|
$payCheck = pay_check($request['user_id']);
|
|
|
if (!$payCheck['code']) {
|
|
|
$this->set_message(1088, "fail", $payCheck['msg']);
|
|
|
}
|
|
|
C(api('Config/lists'));
|
|
|
if($request['price']*1<=0 || $request['price'] >= C('WX_PAY_LIMIT')){
|
|
|
$this->set_message(1011,"fail","充值金额有误");
|
|
|
}
|
|
|
$game = M('Game','tab_')->where(['id'=>$request['game_id']])->field('pay_status')->find();
|
|
|
if($game['pay_status'] == 0){
|
|
|
$this->set_message(0,"fail","该游戏暂时无法充值,请联系客服!");
|
|
|
}
|
|
|
if($request['code'] == 1){ // 1正常充值 0平台币充值
|
|
|
$extend_data = M('spend','tab_')->where(array('extend'=>$request['extend'],'pay_status'=>1,'game_id'=>$request['game_id']))->find();
|
|
|
if($extend_data){
|
|
|
$this->set_message(1089,"fail","订单号重复,请关闭支付页面重新支付");
|
|
|
}
|
|
|
}
|
|
|
$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'] = 3;
|
|
|
$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'];
|
|
|
$discountAmount = 0;
|
|
|
if($prefix=='PF_'){
|
|
|
$pay_amount = $request['price'];
|
|
|
}else{
|
|
|
$pay_amount = $discount * $request['price'] / 10;
|
|
|
$discountAmount = $request['price'] - $pay_amount;
|
|
|
}
|
|
|
if(!empty($request['scheme'])) {
|
|
|
file_put_contents("./Application/Sdk/Scheme/".$request['game_id'].".txt",$request['scheme']);
|
|
|
}
|
|
|
// 绑币平台币优先处理
|
|
|
$this->other_price($request, $discountAmount);
|
|
|
$pay_amount = $request['price'];
|
|
|
|
|
|
$game_set_data = get_game_set_info($request['game_id']);
|
|
|
//$request['game_name']
|
|
|
//0 官方 1威富通
|
|
|
if (get_wx_pay_type() == 0) {
|
|
|
if(empty(C('wei_xin.email'))|| empty(C('wei_xin.partner'))||empty(C('wei_xin.key'))){
|
|
|
$this->set_message(1009, "fail", "支付参数未配置");
|
|
|
}
|
|
|
$weixn = new Weixin();
|
|
|
$is_pay = json_decode($weixn->weixin_pay("充值", $request['pay_order_number'], $pay_amount, 'MWEB'), true);
|
|
|
if($is_pay['status']==1){
|
|
|
if($request['code']==1){
|
|
|
$this->add_spend($request);
|
|
|
}else{
|
|
|
$this->add_deposit($request);
|
|
|
}
|
|
|
$json_data['status'] = 200;
|
|
|
if($request['sdk_version']==1){
|
|
|
$json_data['url'] = $is_pay['mweb_url'];
|
|
|
$json_data['orderno'] =$request['pay_order_number'];
|
|
|
$json_data['paytype'] ="wx";
|
|
|
}else{
|
|
|
if(!empty($request['scheme'])) {
|
|
|
$redirect_url = 'https://api.wmtxkj.com' . "/sdk.php/Spend/pay_success2/orderno/".$request['pay_order_number'].'/game_id/'.$request['game_id'];
|
|
|
} else {
|
|
|
$redirect_url = 'https://api.wmtxkj.com' . "/sdk.php/Spend/pay_success/orderno/".$request['pay_order_number'];
|
|
|
}
|
|
|
$json_data['url'] = $is_pay['mweb_url'].'&redirect_url='.urlencode( $redirect_url );
|
|
|
$json_data['paytype'] ="wx";
|
|
|
}
|
|
|
}else{
|
|
|
$json_data['status'] = 500;
|
|
|
$json_data['url'] = "https://" . 'api.wmtxkj.com';
|
|
|
}
|
|
|
$json_data['cal_url'] = 'https://api.wmtxkj.com';
|
|
|
echo base64_encode(json_encode($json_data));exit;
|
|
|
// $this->redirect('WapPay/weixin_pay_view',['user_id'=>$request['user_id'],'game_id'=>$request['game_id']]);
|
|
|
} else if(get_wx_pay_type() == 1){ // 威富通
|
|
|
if( empty(C('heepay.partner'))||empty(C('heepay.key'))){
|
|
|
$this->set_message(1009, "fail", "支付参数未配置");
|
|
|
}
|
|
|
|
|
|
if($request['code']==1){
|
|
|
$this->add_spend($request);
|
|
|
}else{
|
|
|
$this->add_deposit($request);
|
|
|
}
|
|
|
|
|
|
$heepay = new Heepay();
|
|
|
|
|
|
if(!empty($request['scheme'])) { // 跳转出app
|
|
|
$redirect_url = 'http://' . $_SERVER ['HTTP_HOST'] . "/sdk.php/Spend/pay_success2/orderno/".$request['pay_order_number'].'/game_id/'.$request['game_id'];
|
|
|
} else { // 应用内
|
|
|
$redirect_url = 'http://' . $_SERVER ['HTTP_HOST'] . "/sdk.php/Spend/pay_success/orderno/".$request['pay_order_number'];
|
|
|
}
|
|
|
|
|
|
$pay['agent_id'] = C('heepay.partner');//商户号
|
|
|
$pay['order_no'] = $request['pay_order_number'];
|
|
|
$pay['time'] = date('YmdHis', time());
|
|
|
$pay['pay_type'] = 30;
|
|
|
$pay['amount'] = $pay_amount;
|
|
|
$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'] = $redirect_url;
|
|
|
|
|
|
$url = $heepay->wxh5_pay($pay);
|
|
|
|
|
|
$json_data['status'] = 200;
|
|
|
$json_data['paytype'] = 'wft';
|
|
|
$json_data['url'] = $url;
|
|
|
echo base64_encode(json_encode($json_data)); exit;
|
|
|
}else if(get_wx_pay_type() == 2){
|
|
|
if( empty(C('jft_wap.partner'))||empty(C('jft_wap.key'))){
|
|
|
$this->set_message(1009, "fail", "支付参数未配置");
|
|
|
}
|
|
|
|
|
|
|
|
|
if($request['code']==1){
|
|
|
$this->add_spend($request);
|
|
|
}else{
|
|
|
$this->add_deposit($request);
|
|
|
}
|
|
|
|
|
|
$jtpay=new Jtpay();
|
|
|
if($request['sdk_version']==1){//1 安卓 2苹果
|
|
|
$p25_terminal=3;
|
|
|
$p26_iswappay=3;
|
|
|
}else{
|
|
|
$p25_terminal=2;
|
|
|
$p26_iswappay=3;
|
|
|
}
|
|
|
|
|
|
if(!empty($request['scheme'])) {
|
|
|
$redirect_url = 'http://' . $_SERVER ['HTTP_HOST'] . "/sdk.php/Spend/pay_success2/orderno/".$request['pay_order_number'].'/game_id/'.$request['game_id'];
|
|
|
} else {
|
|
|
$redirect_url = 'http://' . $_SERVER ['HTTP_HOST'] . "/sdk.php/Spend/pay_success/orderno/".$request['pay_order_number'];
|
|
|
}
|
|
|
|
|
|
$url=$jtpay->jt_pay($request['pay_order_number'],$pay_amount,$user['account'],get_client_ip(),"sdk",3,$redirect_url,$p26_iswappay,$p25_terminal);//安卓
|
|
|
|
|
|
$json_data['status'] = 200;
|
|
|
$json_data['paytype']='jft';
|
|
|
$json_data['url']=$url;
|
|
|
echo base64_encode(json_encode($json_data)); exit;
|
|
|
}else if(get_wx_pay_type() == 3){
|
|
|
if( empty(C('goldpig.partner'))||empty(C('goldpig.wooolid'))){
|
|
|
$this->set_message(1009, "fail", "支付参数未配置");
|
|
|
}
|
|
|
$request['pay_way'] = 8;
|
|
|
|
|
|
if($pay_amount*1<1){
|
|
|
$this->set_message(1011,"fail","单笔交易金额必须大于1元");
|
|
|
}
|
|
|
|
|
|
if($request['code']==1){
|
|
|
$this->add_spend($request);
|
|
|
}else{
|
|
|
$this->add_deposit($request);
|
|
|
}
|
|
|
|
|
|
$goldpig=new GoldPig();
|
|
|
$res = $goldpig->GoldPig($user['account'],$pay_amount,29,$request['pay_order_number']);
|
|
|
|
|
|
if($res['status']==1){
|
|
|
$json_data['status'] = 200;
|
|
|
$json_data['paytype']='wft';
|
|
|
$json_data['url']=$res['msg'];
|
|
|
|
|
|
}else{
|
|
|
$json_data['status'] = 500;
|
|
|
$json_data['msg']=$res['info'];
|
|
|
$json_data['url']='http://'.$_SERVER ['HTTP_HOST'];
|
|
|
$json_data['cal_url'] = C("pay_header");
|
|
|
}
|
|
|
|
|
|
echo base64_encode(json_encode($json_data)); exit;
|
|
|
}else{
|
|
|
if( empty(C('weixin_gf.partner'))||empty(C('weixin_gf.key'))){
|
|
|
$this->set_message(1009, "fail", "支付参数未配置");
|
|
|
}
|
|
|
$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']="游戏充值";
|
|
|
if(!empty($request['scheme'])) {
|
|
|
$param['callback_url'] = 'http://' . $_SERVER ['HTTP_HOST'] . "/sdk.php/Spend/pay_success2/orderno/" . $request['pay_order_number'].'/game_id/'.$request['game_id'];
|
|
|
}else {
|
|
|
$param['callback_url'] = 'http://' . $_SERVER ['HTTP_HOST'] . "/sdk.php/Spend/pay_success/orderno/" . $request['pay_order_number'];
|
|
|
}
|
|
|
$url=$Swiftpass->submitOrderInfo($param);
|
|
|
if($url['status']==0){
|
|
|
$request['pay_way'] = 4;
|
|
|
if($request['code']==1){
|
|
|
$this->add_spend($request);
|
|
|
}else{
|
|
|
$this->add_deposit($request);
|
|
|
}
|
|
|
$json_data['status'] = 200;
|
|
|
$json_data['url']=$url['pay_info'];
|
|
|
}else{
|
|
|
$json_data['status'] = 0;
|
|
|
$json_data['url']='http://'.$_SERVER ['HTTP_HOST'];
|
|
|
}
|
|
|
$json_data['paytype'] ="wft";
|
|
|
echo base64_encode(json_encode($json_data));
|
|
|
}
|
|
|
// Header("Location: $ssd");
|
|
|
}
|
|
|
/**
|
|
|
* 查询订单状态
|
|
|
* @return [type] [description]
|
|
|
*/
|
|
|
public function get_orderno_restart(){
|
|
|
$request = json_decode(base64_decode(file_get_contents("php://input")), true);
|
|
|
$pay_where = substr($request['orderno'], 0, 2);
|
|
|
$map['pay_order_number'] = $request['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;
|
|
|
}
|
|
|
if(empty($result['pay_status'])){
|
|
|
$status=1086;
|
|
|
}else{
|
|
|
$status=$result['pay_status']==0?1086:200;
|
|
|
}
|
|
|
echo base64_encode(json_encode(['status'=>$status]));
|
|
|
}
|
|
|
public function weixin_pay_view($user_id,$game_id){
|
|
|
$file=file_get_contents("./Application/Sdk/OrderNo/".$user_id."-".$game_id.".txt");
|
|
|
$request = json_decode(base64_decode($file),true);
|
|
|
$this->assign('url',$request['url'].'&redirect_url='.(is_ssl()?'https://':'http://'). $_SERVER ['HTTP_HOST'] . "/sdk.php/Spend/pay_success");
|
|
|
// Header("Location: $ssd");
|
|
|
$this->display();
|
|
|
}
|
|
|
/**
|
|
|
* 竣付通支付
|
|
|
* @return [type] [description]
|
|
|
*/
|
|
|
public function jft_wap(){
|
|
|
#获取SDK上POST方式传过来的数据 然后base64解密 然后将json字符串转化成数组
|
|
|
$request = json_decode(base64_decode(file_get_contents("php://input")), true);
|
|
|
if (empty($request)) {
|
|
|
$this->set_message(1001, "fail", "登录数据不能为空");
|
|
|
}
|
|
|
// 支付验证 是否让支付
|
|
|
$payCheck = pay_check($request['user_id']);
|
|
|
if (!$payCheck['code']) {
|
|
|
$this->set_message(1088, "fail", $payCheck['msg']);
|
|
|
}
|
|
|
|
|
|
C(api('Config/lists'));
|
|
|
if($request['price']<0){
|
|
|
$this->set_message(1011,"fail","充值金额有误");
|
|
|
}
|
|
|
$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'] = 3;
|
|
|
$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;
|
|
|
// 绑币平台币处理
|
|
|
$this->other_price($request, $request['price']-$pay_amount);
|
|
|
|
|
|
if($request['code']==1){
|
|
|
$this->add_spend($request);
|
|
|
}else{
|
|
|
$this->add_deposit($request);
|
|
|
}
|
|
|
file_put_contents("./Application/Sdk/OrderNo/".$request['user_id']."-".$request['game_id'].".txt",think_encrypt(json_encode($request)));
|
|
|
|
|
|
$sss="http://".$_SERVER['HTTP_HOST'].'/sdk.php/Spend/pay_way/user_id/'.$request['user_id'].'/game_id/'.$request['game_id'].'/type/3';
|
|
|
redirect($sss);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 双乾支付
|
|
|
* @return [type] [description]
|
|
|
*/
|
|
|
public function squnion_wap(){
|
|
|
$request = json_decode(base64_decode(file_get_contents("php://input")), true);
|
|
|
//pp($request);
|
|
|
/* $request['user_id'] = 80;
|
|
|
$request['game_id'] = 143;
|
|
|
$request['price'] = 0.01;
|
|
|
$request['code'] = 1;
|
|
|
$request['extend'] = "11212452299229";
|
|
|
$request['pay_order_number'] = "11212452299229"; */
|
|
|
|
|
|
// 支付验证 是否让支付
|
|
|
$payCheck = pay_check($request['user_id']);
|
|
|
if (!$payCheck['code']) {
|
|
|
$this->set_message(1088, "fail", $payCheck['msg']);
|
|
|
}
|
|
|
|
|
|
if (empty($request)) {
|
|
|
$this->set_message(1001, "fail","登录数据不能为空");
|
|
|
}
|
|
|
|
|
|
$game = M('Game','tab_')->where(['id'=>$request['game_id']])->field('pay_status')->find();
|
|
|
if($game['pay_status'] == 0){
|
|
|
$this->set_message(0, "fail","该游戏暂时无法充值,请联系客服!");
|
|
|
}
|
|
|
|
|
|
if($request['price']*1<=0){
|
|
|
$this->set_message(1011,"fail","充值金额有误");
|
|
|
}
|
|
|
|
|
|
C(api('Config/lists'));
|
|
|
|
|
|
if($request['code'] == 1){ // 1正常充值 0平台比充值
|
|
|
$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","订单号重复,请关闭支付页面重新支付");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
$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'] = 7; // 支付方式(-1绑币 0:平台币,1:支付宝,2:微信(扫码)3微信app 4 威富通 5聚宝云 6竣付通 7双乾银联
|
|
|
$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'=>$request['user_id'],'game_id'=>$request['game_id'],'msg'=>'充值金额有误.'.$pay_amount)));exit;
|
|
|
}
|
|
|
$this->other_price($request, $request['price']-$pay_amount);
|
|
|
|
|
|
//0 官方 1双乾
|
|
|
if (get_union_pay_type() == 0) {
|
|
|
// 暂时只有双乾
|
|
|
}elseif(get_union_pay_type() == 1){
|
|
|
file_put_contents("./Application/Sdk/OrderNo/".$request['user_id']."-".$request['game_id'].".txt",think_encrypt(json_encode($request)));
|
|
|
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_success2/orderno/".$request['pay_order_number'].'/game_id/'.$request['game_id'];
|
|
|
$ret = $sqpay->sq_pay($out_trade_no, $pay_amount, C("sqpay.partner"), "UNION", "测试产品1", get_client_ip(),$returl);
|
|
|
$ret = json_decode($ret, true);
|
|
|
|
|
|
if ($ret[0]['payHtml']) {
|
|
|
$data = array(
|
|
|
'status' => 200,
|
|
|
"url" => '',
|
|
|
"html" => $ret[0]['payHtml'],
|
|
|
"return_msg" => '',
|
|
|
"paytype" => 'squnion',
|
|
|
);
|
|
|
} else {
|
|
|
$data = array(
|
|
|
'status' => 1,
|
|
|
"url" => '',
|
|
|
"html" => '',
|
|
|
"return_msg" => '失败请重试',
|
|
|
"paytype" => '',
|
|
|
);
|
|
|
}
|
|
|
|
|
|
echo base64_encode(json_encode($data));
|
|
|
exit();
|
|
|
}
|
|
|
// redirect($json_data['url']);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 双乾小程序支付
|
|
|
* 流程:1.app端唤起小程序 2,小程序请求服务端拿到支付参数 3,小程序发起支付之后 回调服务端 4,服务端通知客户端
|
|
|
* return: 相关支付参数 回调url
|
|
|
*/
|
|
|
public function small_program() {
|
|
|
|
|
|
$request = json_decode(base64_decode(file_get_contents("php://input")), true);
|
|
|
if (empty($request)) {
|
|
|
$this->set_message(1001, "fail", "登录数据不能为空");
|
|
|
}
|
|
|
|
|
|
if (!$request['openid'] || !$request['price'] || !$request['game_id']) {
|
|
|
$this->set_message(1001, "fail", "小程序参数有误");
|
|
|
}
|
|
|
|
|
|
$game = M('Game','tab_')->where(['id'=>$request['game_id']])->field('pay_status')->find();
|
|
|
if($game['pay_status'] == 0){
|
|
|
$this->set_message(0, "fail","该游戏暂时无法充值,请联系客服!");
|
|
|
}
|
|
|
|
|
|
if($request['price']*1<=0){
|
|
|
$this->set_message(1011,"fail","充值金额有误");
|
|
|
}
|
|
|
|
|
|
$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","订单号重复,请关闭支付页面重新支付");
|
|
|
}
|
|
|
|
|
|
$prefix = ($request['code'] == 1) ? "SP_" : "PF_";
|
|
|
$request['pay_order_number'] = $prefix . date('Ymd') . date('His') . sp_random_string(4);
|
|
|
$request['pay_way'] = C('PAY_WAY.SQ_SMALL_PROGRAM');
|
|
|
$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'];
|
|
|
$discountAmount = 0;
|
|
|
if($prefix=='PF_'){
|
|
|
$pay_amount = $request['price'];
|
|
|
}else{
|
|
|
$pay_amount = $discount * $request['price'] / 10;
|
|
|
$discountAmount = $request['price'] - $pay_amount;
|
|
|
}
|
|
|
if(!empty($request['scheme'])) {
|
|
|
file_put_contents("./Application/Sdk/Scheme/".$request['game_id'].".txt",$request['scheme']);
|
|
|
}
|
|
|
// 绑币平台币优先处理
|
|
|
$this->other_price($request, $discountAmount);
|
|
|
$pay_amount = $request['price'];
|
|
|
if($request['code']==1){
|
|
|
$this->add_spend($request,1);
|
|
|
}else{
|
|
|
$this->add_deposit($request, 1);
|
|
|
}
|
|
|
|
|
|
$sqpay = new Sqpay();
|
|
|
$data['userId'] = $request['openid'];
|
|
|
$data['order_no'] = $request['pay_order_number'];
|
|
|
$data['merno'] = C('sqpay.partner');
|
|
|
$data['subject'] = '游戏充值';
|
|
|
$data['ip'] = get_client_ip();
|
|
|
$data['returnurl'] = C('pay_header'). "/sdk.php/Spend/pay_success/orderno/".$request['pay_order_number'].'/game_id/'.$request['game_id'];
|
|
|
$data['amount'] = $request['price'];
|
|
|
$data['appId'] = C('wei_xin.email');
|
|
|
$data['secret'] = C('sqpay.key');
|
|
|
$data['MerRemark'] = $data['order_no'];
|
|
|
|
|
|
$ret = $sqpay->sq_wxsmallpay($data);
|
|
|
|
|
|
if ($ret[0]['respCode'] == "000000") {
|
|
|
echo json_encode(array(
|
|
|
'code' => 1,
|
|
|
'Amount' => $ret[0]['Amount'],
|
|
|
'orderNo' => $ret[0]['orderNo'], // 微信生成的订单号
|
|
|
'platformNumber' => $request['pay_order_number'], // 平台订单号
|
|
|
'wxjsapiStr' => $ret[0]['wxjsapiStr']
|
|
|
));
|
|
|
exit();
|
|
|
}
|
|
|
echo json_encode(array(
|
|
|
'code' => 1,
|
|
|
'msg' => $ret[0]['respMess'],
|
|
|
));
|
|
|
exit();
|
|
|
}
|
|
|
}
|