"; 发送短信
$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' => '',
'custType' => '01', // 认证 发短信
'secret' => C('sqpay.key'),
));
//echo "调用认证 签约==》".time()."
";
if ($rsign['respCode'] == 'success') { // 认证成功发送短信
$this->success('签约短信发送成功', '', true);
} else {
if (strlen($rsign['respMessage']) > 100) {
$this->error('填写信息有误,请核对!', '', true);
} else {
$this->error($rsign['respMessage'], '', true);
}
}
// var_dump($rsign);
exit();
}
if (IS_POST && $param['signCode']) {
$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' => $param['signCode'],
'custType' => '02', // 签约
'secret' => C('sqpay.key'),
));
if ($rauth['respCode'] == 'success') { // 签约成功
$this->success('签约成功', '', true);
$signContract = true;
} else {
$this->error($rauth['respMessage'], '', true);
}
}
}
/**\
* 快捷支付'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("request.");
$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']);
}
$w = array(
'user_id' => $param['user_id'],
'game_id' => $param['game_id'],
);
if ($param['extend']) $w['extend'] = $param['extend'];
if ($param['order_id']) $w['order_id'] = $param['order_id'];
$payInfo = M('pay_info', 'tab_')->where($w)->order('id desc')->find();
if (!$payInfo) {
$this->error("数据有误..", '', true);
}
// $info = json_decode($payInfo['info'], true);
$deductionAmount = 0;
if ($payInfo['type'] == 'sq_shortcut') {
$spend = M('spend', 'tab_')->where([
'pay_order_number' => $payInfo['order_id']
])->find();
$orderPrice = round($spend['pay_amount']+$spend['deduction_amount'], 2);
$deductionAmount = $spend['deduction_amount'];
} else {
$deposit = M('deposit', 'tab_')->where([
'pay_order_number' => $payInfo['order_id']
])->find();
$orderPrice = $deposit['pay_amount'];
}
// if ($orderPrice != $payInfo['price']) {
// $this->error($orderPrice."数据有误.".$payInfo['price'], '', true);
// }
$payInfo['price'] = round($payInfo['price'] - $deductionAmount, 2);
if ($payInfo['type'] == 'sq_shortcut_platform' && $payInfo['price'] < 1) {
$this->error("数据有误", '', true);
}
if ($payInfo['status'] == 'payed') {
$this->error("订单已支付");
}
// 发起支付
if (IS_POST && $param['smsCode']) {
//echo "发起支付==》".time()."
";
$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'),
'NotifyURL' => C('PAY_DOMAIN')."/callback.php/Notify/sq_callback",//通知
));
//echo "发起支付==》".time()."
";
if ($rsp['responseCode'] == '88') {
// sleep(5);
echo json_encode([
'status' => 1,
'info' => '请求成功',
'url' => U('Spend/shortcut_notice',array('status'=> 1, 'orderno' => $payInfo['order_id'], 'user_id'=>$param['user_id'],'game_id'=>$param['game_id'])),
]);
exit();
// redirect(U('Spend/shortcut_notice',array('status'=> 1, 'orderno' => $payInfo['order_id'], 'user_id'=>$param['user_id'],'game_id'=>$param['game_id'])));exit;
} else {
// 支付失败
echo json_encode([
'status' => 0,
'info' => $rsp['resMess']
]);
exit();
// redirect(U('Spend/pay_success',array('status'=> 0, 'orderno' => $payInfo['order_id'], 'user_id'=>$param['user_id'],'game_id'=>$param['game_id'])));exit;
}
}
// 发送短信
if (IS_POST && !isset($param['smsCode'])) {
// 查看是否签约
//echo "查看是否签约==》".time()."
";
$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'),
));
// pp($rcs);
//echo "查看是否签约==》".time()."
";
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 json_encode([
'status' => 2, //
'info' => '未签约'
]);
exit();
}
/* // 调用认证 签约 6222031402001028203 500236199608024075
if ($rcs['respCode'] == 1 || $rcs['respCode'] == 2 || $rcs['respCode'] == 3) {
//echo "调用认证 签约==》".time()."
"; 发送短信
$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()."
";
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'),
));
pp($rauth);
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()."
";
$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' => C("PAY_DOMAIN")."/callback.php/Notify/sq_callback",
'purpose' => '消费-'.$payInfo['order_id']
));
//echo "发送短信==》".time()."
";
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();
}
/**
* 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);
// $is_platform = 0;
// if (I('request.code') == 0 && I('request.type') == 'platform') {
// $is_platform = 1; // 平台币充值
// }
//
// //$prefix = ($is_platform == 1) ? 'PF_' : 'SP_';
// //$request['pay_order_number'] = $prefix . date('Ymd') . date('His') . sp_random_string(4);
// $request['game_id'] = I('request.game_id');
// $game_id = $request['game_id'];
// $request['user_id'] = I('request.user_id');
// $user_id = $request['user_id'];
// $request['code'] = I('request.code');
//
// $payInfo = M('pay_info', 'tab_')->where([
// 'user_id' => I('user_id'),
// 'game_id' => I('game_id'),
// 'extend' => I('extend'),
// ])->order('id desc')->find();
// $request['price'] = $payInfo['price'];
//
// $userToken = I('request.user_token');
//
// if (empty($request)) {
// redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'is_platform'=> $is_platform,'msg'=>'登录数据不能为空', 'user_token' => $userToken)));exit;
// }
// // 支付验证 是否让支付
// $payCheck = pay_check($request['user_id']);
// if (!$payCheck['code']) {
// redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'is_platform'=> $is_platform,'msg'=>$payCheck['msg'], 'user_token' => $userToken)));exit;
// }
//
// $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,'is_platform'=> $is_platform,'msg'=>'该游戏暂时无法充值,请联系客服!', 'user_token' => $userToken)));exit;
// }
// if($request['price']*1<=0){
// redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'is_platform'=> $is_platform,'msg'=>'充值金额有误', 'user_token' => $userToken)));exit;
// }
//
// C(api('Config/lists'));
//
// if (!$is_platform) {
// $request['extend'] = I('request.extend');
// $extend_data = M('spend','tab_')->where(array('extend'=>$request['extend'],'game_id'=>$request['game_id']))->find();
// if($extend_data){
// redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'is_platform'=> $is_platform,'msg'=>$request['game_id'].'订单号重复,请关闭支付页面重新支付'.$request['extend'], 'user_token' => $userToken)));exit;
// }
// }
//
// //折扣
// $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,'is_platform'=> $is_platform, 'msg'=>'充值金额有误.'.$pay_amount, 'user_token' => $userToken)));exit;
// }
//
// if (!$is_platform) {
// $this->other_price($request, $request['price']-$pay_amount);
// }
//
// // 平台币充值
// if ($is_platform) {
// $request['code'] = 0;
// $request['user_id'] = I('request.user_id');
// $request['price'] = intval(I('request.price'));
// $request['game_id'] = I('request.game_id');
// $request['pay_way'] = C("PAY_WAY.SQ_SHORTCUT"); // 支付方式(-1绑币 0:平台币,1:支付宝,2:微信(扫码)3微信app 4 威富通 5聚宝云 6竣付通 7苹果支付8金猪支付 9双乾支付-支付宝 10双乾支付-银联 15双乾支付-快捷
// $request['pay_status'] = 0;
// $request['spend_ip'] = get_client_ip();
// $payInfo = M('pay_info', 'tab_')->where([
// 'user_id' => I('user_id'),
// 'game_id' => I('game_id'),
// 'extend' => I('extend'),
// ])->order('id desc')->find();
// $request['pay_order_number'] = $payInfo['order_id'];
//
// if (!$payInfo) {
// return ;
// }
// } else { // 游戏充值
// $request['code'] = 1;
// $payInfo = M('pay_info', 'tab_')->where([
// 'user_id' => I('user_id'),
// 'game_id' => I('game_id'),
// 'extend' => I('extend'),
// ])->order('id desc')->find();
// if ($payInfo) {
// $info = json_decode($payInfo['info'], true);
// $info['deduction_amount'] = $request['deduction_amount'];
// $info['actual_amount'] = $request['actual_amount'];
// $info['discount_amount'] = $request['discount_amount'];
// $info['price'] = $request['price'];
// $infosave = json_encode($info);
// M('pay_info', 'tab_')->where([
// 'id' => $payInfo['id']
// ])->save([
// 'type' => 'sq_shortcut', // 游戏充值
// //'order_id' => $request['pay_order_number'],
// //'price' => $request['actual_amount'] ? $request['actual_amount'] : $request['price'],
// 'info' => $infosave
// ]);
// $info['code'] = $request['code'];
// $info['pay_order_number'] = $request['pay_order_number'];
// $request = $info;
// $request['pay_way'] = C("PAY_WAY.SQ_SHORTCUT");
// $request['pay_status'] = 0;
// $request['spend_ip'] = get_client_ip();
// $request['pay_order_number'] = $payInfo['order_id'];
// }
// }
//
// //0 官方 1双乾
// if (get_shortcut_pay_type() == 0) {
// // 暂时只有双乾
// }elseif(get_shortcut_pay_type() == 1){
// if($request['code']==1){
// $this->add_spend($request,1);
// }else{
// $this->add_deposit($request,1);
// }
// }
//
// $this->assign("pay_amount", $request['actual_amount']?$request['actual_amount']:$request['price']);
// $this->assign("user_id", $request['user_id']);
// $this->assign("game_id", $request['game_id']);
// $this->assign("user_token", $userToken);
// $this->assign("extend", I('extend'));
// $this->assign("order_id", $request['pay_order_number']);
// $this->display();
$this->sq_pay_step1();
}
// 快捷---易宝支付
public function yee_pay($user_id,$game_id) {
$is_platform = 0;
if (I('request.code') == 0 && I('request.type') == 'platform') {
$is_platform = 1; // 平台币充值
}
$request['game_id'] = I('request.game_id');
$game_id = $request['game_id'];
$request['user_id'] = I('request.user_id');
$user_id = $request['user_id'];
$request['code'] = I('request.code');
$payInfo = M('pay_info', 'tab_')->where([
'user_id' => I('request.user_id'),
'game_id' => I('request.game_id'),
'extend' => I('request.extend', ''),
])->order('id desc')->find();
$request['price'] = $payInfo['price'];
$userToken = I('request.user_token');
if (empty($request)) {
echo json_encode(['code'=>0, 'msg'=> '登录数据不能为空']);
exit;
}
// 支付验证 是否让支付
$payCheck = pay_check($request['user_id']);
if (!$payCheck['code']) {
echo json_encode(['code'=>0, 'msg'=> $payCheck['msg']]);
exit;
}
$game = M('Game','tab_')->where(['id'=>$request['game_id']])->field('id, game_type_id, pay_status')->find();
if($game['pay_status'] == 0){
echo json_encode(['code'=>0, 'msg'=> "该游戏暂时无法充值,请联系客服!"]);
exit;
}
if($request['price']*1<=0){
echo json_encode(['code'=>0, 'msg'=> "充值金额有误"]);
exit;
}
$payLimitConf = new PayLimitConfModel();
// 先判断意向记录支付请求情况
$check = $payLimitConf->check($request['user_id'], $request['price'], $payLimitConf::PAY_TYPE_YEEPAY, $payInfo['order_id']);
// 在更新历史支付请求订单提交情况
$payChannelInterntion = new PayChannelIntentionModel();
$payChannelInterntion->paySubmit($payInfo['order_id']);
if ($check) {
echo json_encode(['code'=>1001,'msg'=> "请求发起失效,编号{$payInfo['order_id']},请选择其他支付方式或联系客服"]);exit;
}
C(api('Config/lists'));
if (!$is_platform) {
$request['extend'] = I('request.extend');
$extend_data = M('spend','tab_')->where(array('extend'=>$request['extend'],'game_id'=>$request['game_id']))->find();
if($extend_data){
echo json_encode(['code'=>0, 'msg'=> "订单号重复,请关闭支付页面重新支付."]);
exit;
}
}
//折扣
$user = get_user_entity($request['user_id']);
$discount = get_discount($request['game_id'], $request['user_id']);
$discount = $discount['discount'];
$discountAmount = 0;
if ($discount < 10) {
$discountAmount = round($request['price'] - ($discount * $request['price'] / 10), 2);
$request['discount_amount'] = $discountAmount;
}
$pay_amount = round($discount * $request['price'] / 10, 2);
if ($pay_amount < 0.01) {
echo json_encode(['code'=>0, 'msg'=> "充值金额有误."]);
exit;
}
if (!$is_platform) {
$this->other_price($request, $discountAmount);
}
// 平台币充值
if ($is_platform) {
$request['code'] = 0;
$request['user_id'] = I('request.user_id');
$request['price'] = intval(I('request.price'));
$request['game_id'] = I('request.game_id');
$request['pay_way'] = C("PAY_WAY.YEEPAY"); // 支付方式(-1绑币 0:平台币,1:支付宝,2:微信(扫码)3微信app 4 威富通 5聚宝云 6竣付通 7苹果支付8金猪支付 9双乾支付-支付宝 10双乾支付-银联 15双乾支付-快捷
$request['pay_status'] = 0;
$request['spend_ip'] = get_client_ip();
$payInfo = M('pay_info', 'tab_')->where([
'user_id' => I('request.user_id'),
'game_id' => I('request.game_id'),
'extend' => I('request.extend', ''),
])->order('id desc')->find();
$request['pay_order_number'] = $payInfo['order_id'];
if (!$payInfo) {
return ;
}
} else { // 游戏充值
$request['code'] = 1;
$payInfo = M('pay_info', 'tab_')->where([
'user_id' => I('request.user_id'),
'game_id' => I('request.game_id'),
'extend' => I('request.extend'),
])->order('id desc')->find();
if ($payInfo) {
$info = json_decode($payInfo['info'], true);
$info['deduction_amount'] = $request['deduction_amount'];
$info['actual_amount'] = $request['actual_amount'];
$info['discount_amount'] = $request['discount_amount'];
$info['price'] = $request['price'];
$info['cost'] = $request['cost'];
$infosave = json_encode($info);
M('pay_info', 'tab_')->where([
'id' => $payInfo['id']
])->save([
'type' => 'yee_shortcut', // 游戏充值
//'order_id' => $request['pay_order_number'],
//'price' => $request['actual_amount'] ? $request['actual_amount'] : $request['price'],
'info' => $infosave
]);
$info['code'] = $request['code'];
$info['pay_order_number'] = $request['pay_order_number'];
$request = $info;
$request['pay_way'] = C("PAY_WAY.YEEPAY");
$request['pay_status'] = 0;
$request['spend_ip'] = get_client_ip();
$request['pay_order_number'] = $payInfo['order_id'];
}
}
$pay_info = get_payment_config(PayH5Controller::EXPRESS_PAY, $game, I('request.user_id'));
if ($pay_info['code'] != 0) {
echo json_encode(['code'=>1010,'msg'=> $pay_info['msg']]);
exit;
}
$request['main_id'] = $pay_info['data']['main_id'];
$pay_conf = json_decode($pay_info['data']['config'], true);
$pay_info = $pay_info['data'];
$pay_conf['id'] = $pay_info['id'];
$request['merchant_id'] = $pay_info['id'];
$request['merchant_way'] = PayH5Controller::EXPRESS_PAY;
$yeepay = new Yeepay();
$data['appKey'] = $pay_conf['key'];//C('yeepay.key');
$data['privateKey'] = $pay_conf['private_key'];//C('yeepay.private_key');
$data['parentMerchantNo'] = $pay_conf['parent_merchant'];//C('yeepay.parent_merchant');
$data['merchantNo'] = $pay_conf['partner'];//C('yeepay.partner');
$data['orderId'] = $request['pay_order_number'];
$data['orderAmount'] = $request['price'];
$data['notifyUrl'] = C('PAY_DOMAIN')."/callback.php/Notify/yeepay_callback";
$data['goodsParamExt'] = '{"goodsName":"游戏充值","goodsDesc":"充值"}';
$data['userNo'] = $request['user_id'];
$data['userType'] = "USER_ID";
$data['memo'] = "游戏充值-{$request['pay_order_number']}";
if ($is_platform) {
$data['redirectUrl'] = C('PAY_DOMAIN').U('Spend/shortcut_payed',array('status'=> 1, 'orderno' => $payInfo['order_id'], 'user_id'=>I('user_id'),'game_id'=>I('game_id'), 'user_token' => I('request.user_token')));
} else {
$data['redirectUrl'] = C('PAY_DOMAIN').U('Spend/shortcut_notice',array('status'=> 1, 'orderno' => $payInfo['order_id'], 'user_id'=>I('user_id'),'game_id'=>I('game_id'), 'user_token' => I('request.user_token')));
}
$data['paymentParamExt'] = '{}';
$yeeData = $yeepay->yee_pay($data);
// var_dump($data, $yeeData);//die;
if ($yeeData['data']['result']['code'] != 'OPR00000') {
echo json_encode(['code'=>0, 'msg'=> '支付参数有误,请重试'.$yeeData['data']['result']['code']]);
exit;
}
$request['pay_url'] = $yeeData['url'];
if($request['code']==1){
$this->add_spend($request,1);
}else{
$this->add_deposit($request,1);
}
$returl = html_entity_decode($yeeData['url']);
echo json_encode(['code'=>200, 'url'=> $returl]);
return ;
}
public function sq_pay_step1() {
$is_platform = 0;
if (I('request.code') == 0 && I('request.type') == 'platform') {
$is_platform = 1; // 平台币充值
}
//$prefix = ($is_platform == 1) ? 'PF_' : 'SP_';
//$request['pay_order_number'] = $prefix . date('Ymd') . date('His') . sp_random_string(4);
$request['game_id'] = I('request.game_id');
$game_id = $request['game_id'];
$request['user_id'] = I('request.user_id');
$user_id = $request['user_id'];
$request['code'] = I('request.code');
$extend = I('request.extend');
if (!$user_id) {
echo json_encode(['code'=>0,'msg'=>'用户id为空,请退出支付界面重新进入']);exit;
}
$payInfo = M('pay_info', 'tab_')->where([
'user_id' => $user_id,
'game_id' => $game_id,
'extend' => $extend,
])->order('id desc')->find();
$request['price'] = $payInfo['price'];
$userToken = I('request.user_token');
if (empty($request)) {
// redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'is_platform'=> $is_platform,'msg'=>'登录数据不能为空', 'user_token' => $userToken)));
echo json_encode(['code'=>0,'msg'=>'登录数据不能为空']);
exit;
}
// 支付验证 是否让支付
$payCheck = pay_check($request['user_id']);
if (!$payCheck['code']) {
// redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'is_platform'=> $is_platform,'msg'=>$payCheck['msg'], 'user_token' => $userToken)));
echo json_encode(['code'=>0,'msg'=>$payCheck['msg']]);
exit;
}
$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,'is_platform'=> $is_platform,'msg'=>'该游戏暂时无法充值,请联系客服!', 'user_token' => $userToken)));
echo json_encode(['code'=>0,'msg'=>'该游戏暂时无法充值,请联系客服!']);
exit;
}
if($request['price']*1<=0){
// redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'is_platform'=> $is_platform,'msg'=>'充值金额有误', 'user_token' => $userToken)));
echo json_encode(['code'=>0,'msg'=>'充值金额有误']);
exit;
}
$payLimitConf = new PayLimitConfModel();
// 先判断意向记录支付请求情况
$check = $payLimitConf->check($request['user_id'], $request['price'], $payLimitConf::PAY_TYPE_SQPAY, $payInfo['order_id']);
// 在更新历史支付请求订单提交情况
$payChannelInterntion = new PayChannelIntentionModel();
$payChannelInterntion->paySubmit($payInfo['order_id']);
if ($check) {
echo json_encode(['code'=>1001,'msg'=> "请求发起失效,编号{$payInfo['order_id']},请选择其他支付方式或联系客服"]);exit;
}
C(api('Config/lists'));
if (!$is_platform) {
$request['extend'] = I('request.extend');
$extend_data = M('spend','tab_')->where(array('extend'=>$request['extend'],'game_id'=>$request['game_id']))->find();
if($extend_data){
// redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'is_platform'=> $is_platform,'msg'=>$request['game_id'].'订单号重复,请关闭支付页面重新支付'.$request['extend'], 'user_token' => $userToken)));
echo json_encode(['code'=>0,'msg'=>$request['game_id'].'订单号重复,请关闭支付页面重新支付'.$request['extend']]);
exit;
}
}
//折扣
$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,'is_platform'=> $is_platform, 'msg'=>'充值金额有误.'.$pay_amount, 'user_token' => $userToken)));
echo json_encode(['code'=>0,'msg'=>'充值金额有误.'.$pay_amount]);
exit;
}
if (!$is_platform) {
$this->other_price($request, $request['price']-$pay_amount);
}
// 平台币充值
if ($is_platform) {
$request['code'] = 0;
$request['user_id'] = I('request.user_id');
$request['price'] = intval(I('request.price'));
$request['game_id'] = I('request.game_id');
$request['pay_way'] = C("PAY_WAY.SQ_SHORTCUT"); // 支付方式(-1绑币 0:平台币,1:支付宝,2:微信(扫码)3微信app 4 威富通 5聚宝云 6竣付通 7苹果支付8金猪支付 9双乾支付-支付宝 10双乾支付-银联 15双乾支付-快捷
$request['pay_status'] = 0;
$request['spend_ip'] = get_client_ip();
// $payInfo['info'] = json_decode($payInfo['info'],true);
$request['goods_info'] = '平台币充值';
$payInfo = M('pay_info', 'tab_')->where([
'user_id' => I('user_id'),
'game_id' => I('game_id'),
'extend' => I('extend'),
])->order('id desc')->find();
$request['pay_order_number'] = $payInfo['order_id'];
if (!$payInfo) {
return ;
}
} else { // 游戏充值
$request['code'] = 1;
$payInfo = M('pay_info', 'tab_')->where([
'user_id' => I('user_id'),
'game_id' => I('game_id'),
'extend' => I('extend'),
])->order('id desc')->find();
if ($payInfo) {
$info = json_decode($payInfo['info'], true);
$info['deduction_amount'] = $request['deduction_amount'];
$info['actual_amount'] = $request['actual_amount'];
$info['discount_amount'] = $request['discount_amount'];
$info['price'] = $request['price'];
$infosave = json_encode($info);
$info['code'] = $request['code'];
$info['pay_order_number'] = $request['pay_order_number'];
$request = $info;
$request['pay_way'] = C("PAY_WAY.SQ_SHORTCUT");
$request['pay_status'] = 0;
$request['spend_ip'] = get_client_ip();
$request['pay_order_number'] = $payInfo['order_id'];
$payInfo['info'] = json_decode($payInfo['info'],true);
$request['goods_info'] = $payInfo['info']['game_name'].$payInfo['info']['title'];
}
}
if ($_REQUEST['sign']) {
echo json_encode(['code'=>200,'msg'=>'success']);
exit;
}
//0 官方 1双乾
if (get_shortcut_pay_type() == 0) {
// 暂时只有双乾
}elseif(get_shortcut_pay_type() == 1){
if($request['code']==1){
$this->add_spend($request,1);
}else{
$this->add_deposit($request,1);
}
}
$this->assign("type", $is_platform ? "platform" : "");
$this->assign("code", $request['code']);
$this->assign("pay_amount", $request['actual_amount']?$request['actual_amount']:$request['price']);
$this->assign("user_id", $request['user_id']);
$this->assign("game_id", $request['game_id']);
$this->assign("user_token", $userToken);
$this->assign("extend", I('extend'));
$this->assign("order_id", $request['pay_order_number']);
$this->assign('goods_info',$request['goods_info']);
$this->display('yee_step1');
}
public function sq_pay_step2() {
$is_platform = 0;
$code = I('request.code', 0);
if ($code == 0 && I('request.type') == 'platform') {
$is_platform = 1; // 平台币充值
}
$userId = I('request.user_id');
$gameId = I('request.game_id');
$extend = I('request.extend', '');
//$prefix = ($is_platform == 1) ? 'PF_' : 'SP_';
//$request['pay_order_number'] = $prefix . date('Ymd') . date('His') . sp_random_string(4);
$request['game_id'] = $gameId;
$game_id = $request['game_id'];
$request['user_id'] = $userId;
$user_id = $request['user_id'];
$request['code'] = I('request.code');
$payInfo = M('pay_info', 'tab_')->where([
'user_id' => $userId,
'game_id' => $gameId,
'extend' => $extend,
])->order('id desc')->find();
$request['price'] = $payInfo['price'];
$userToken = I('request.user_token');
if (empty($request)) {
redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'is_platform'=> $is_platform,'msg'=>'登录数据不能为空', 'user_token' => $userToken)));exit;
}
// 支付验证 是否让支付
$payCheck = pay_check($request['user_id']);
if (!$payCheck['code']) {
redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'is_platform'=> $is_platform,'msg'=>$payCheck['msg'], 'user_token' => $userToken)));exit;
}
$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,'is_platform'=> $is_platform,'msg'=>'该游戏暂时无法充值,请联系客服!', 'user_token' => $userToken)));exit;
}
if($request['price']*1<=0){
redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'is_platform'=> $is_platform,'msg'=>'充值金额有误', 'user_token' => $userToken)));exit;
}
C(api('Config/lists'));
// if (!$is_platform) {
// $request['extend'] = I('request.extend');
// $extend_data = M('spend','tab_')->where(array('extend'=>$request['extend'],'game_id'=>$request['game_id']))->find();
// if($extend_data){
// redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'is_platform'=> $is_platform,'msg'=>$request['game_id'].'订单号重复,请关闭支付页面重新支付'.$request['extend'], 'user_token' => $userToken)));exit;
// }
// }
//折扣
$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,'is_platform'=> $is_platform, 'msg'=>'充值金额有误.'.$pay_amount, 'user_token' => $userToken)));exit;
}
if (!$is_platform) {
$this->other_price($request, $request['price']-$pay_amount);
}
// 平台币充值
if ($is_platform) {
$request['code'] = 0;
$request['user_id'] = $user_id;
$request['game_id'] = $game_id;
$request['pay_way'] = C("PAY_WAY.SQ_SHORTCUT"); // 支付方式(-1绑币 0:平台币,1:支付宝,2:微信(扫码)3微信app 4 威富通 5聚宝云 6竣付通 7苹果支付8金猪支付 9双乾支付-支付宝 10双乾支付-银联 15双乾支付-快捷
$request['pay_status'] = 0;
$request['spend_ip'] = get_client_ip();
// $payInfo['info'] = json_decode($payInfo['info'],true);
$request['goods_info'] = "平台币充值";
$payInfo = M('pay_info', 'tab_')->where([
'user_id' => $user_id,
'game_id' => $game_id,
'extend' => $extend,
])->order('id desc')->find();
$request['pay_order_number'] = $payInfo['order_id'];
if (!$payInfo) {
return ;
}
} else { // 游戏充值
$request['code'] = 1;
$payInfo = M('pay_info', 'tab_')->where([
'user_id' => $user_id,
'game_id' => $game_id,
'extend' => $extend,
])->order('id desc')->find();
if ($payInfo) {
$info = json_decode($payInfo['info'], true);
$info['deduction_amount'] = $request['deduction_amount'];
$info['actual_amount'] = $request['actual_amount'];
$info['discount_amount'] = $request['discount_amount'];
$info['price'] = $request['price'];
$infosave = json_encode($info);
M('pay_info', 'tab_')->where([
'id' => $payInfo['id']
])->save([
'type' => 'sq_shortcut', // 游戏充值
//'order_id' => $request['pay_order_number'],
//'price' => $request['actual_amount'] ? $request['actual_amount'] : $request['price'],
'info' => $infosave
]);
$info['code'] = $request['code'];
$info['pay_order_number'] = $request['pay_order_number'];
$request = $info;
$request['pay_way'] = C("PAY_WAY.SQ_SHORTCUT");
$request['pay_status'] = 0;
$request['spend_ip'] = get_client_ip();
$request['pay_order_number'] = $payInfo['order_id'];
$payInfo['info'] = json_decode($payInfo['info'],true);
$request['goods_info'] = $payInfo['info']['game_name'].$payInfo['info']['body'];
}
}
//0 官方 1双乾
// if (get_shortcut_pay_type() == 0) {
// // 暂时只有双乾
// }elseif(get_shortcut_pay_type() == 1){
// if($request['code']==1){
// $this->add_spend($request,1);
// }else{
// $this->add_deposit($request,1);
// }
// }
// var_dump($request['goods_info']);die();
$this->assign("pay_amount", $request['actual_amount']?$request['actual_amount']:$request['price']);
$this->assign("user_id", $request['user_id']);
$this->assign("game_id", $request['game_id']);
$this->assign("user_token", $userToken);
$this->assign("extend", $extend);
$this->assign("order_id", $request['pay_order_number']);
$this->assign('goods_info',$request['goods_info']);
$bank_info = $this->checkBankCard();
$this->assign('bank_info',$bank_info);
$this->assign('cardNo',I('request.card_no'));
// var_dump($request);
$this->display('yee_step2');
}
//返回银行卡信息
public function checkBankCard() {
$card_no = I('card_no');
// var_dump(preg_match('/^([1-9]{1})\d{10,19}$/', $card_no));die();
if (!preg_match('/^([1-9]{1})\d{10,19}$/', $card_no)) {
return false;
}
$card_list = include(APP_PATH . "/Sdk/Conf/bankList.php");
$bank_info = '';
for($i = 3; $i <= 9; $i++) {
$back_no = substr($card_no,0,$i);
if ($card_list[$back_no]) {
$bank_info = $card_list[$back_no];
}
}
$info['bank_info'] = substr($bank_info,0,strpos($bank_info,"-"));
$info['card_info'] = substr($bank_info,strripos($bank_info,"-")+1);
$info['end_num'] = substr($card_no,strlen($card_no)-4,strlen($card_no));
$info['image'] = $this->getBankImage($info['bank_info']);
return $info;
}
//返回银行图标
public function getBankImage($bankName) {
$image = '';
if ($bankName == '工商银行') {
$image = 'bank1.png';
} else if($bankName == '农业银行') {
$image = 'bank2.png';
} else if($bankName == '中国银行') {
$image = 'bank3.png';
} else if($bankName == '建设银行') {
$image = 'bank4.png';
} else if($bankName == '招商银行') {
$image = 'bank5.png';
} else if($bankName == '交通银行') {
$image = 'bank6.png';
} else if($bankName == '中信银行') {
$image = 'bank7.png';
} else if($bankName == '光大银行') {
$image = 'bank8.png';
} else if($bankName == '兴业银行') {
$image = 'bank9.png';
} else if($bankName == '邮政银行') {
$image = 'bank10.png';
} else if($bankName == '平安银行') {
$image = 'bank11.png';
} else if($bankName == '浦发银行') {
$image = 'bank12.png';
} else if($bankName == '广发银行') {
$image = 'bank13.png';
} else if($bankName == '华夏银行') {
$image = 'bank14.png';
} else if($bankName == '民生银行') {
$image = 'bank15.png';
} else if($bankName == '北京银行') {
$image = 'bank16.png';
} else if($bankName == '上海银行') {
$image = 'bank17.png';
} else if($bankName == '恒丰银行') {
$image = 'bank18.png';
} else if($bankName == '渤海银行') {
$image = 'bank19.png';
} else if($bankName == '浙商银行') {
$image = 'bank20.png';
}
return $image;
}
}