Merge branch 'hotfix/pament_rule23' of wmtx/sdk into master

支付规则
master
张谷诚 4 years ago committed by Gogs
commit 4d3176e176

@ -114,6 +114,13 @@ class BaseController extends Controller {
$this->rechargeAwardPoint($d['user_id'],$d['pay_amount']); $this->rechargeAwardPoint($d['user_id'],$d['pay_amount']);
// 当天累计充值 // 当天累计充值
$this->payTodayTotal($d['pay_amount'], $d['pay_way']); $this->payTodayTotal($d['pay_amount'], $d['pay_way']);
$data_save['pay_status'] = 1;
$data_save['order_number'] = $data['trade_no'];
$data_save['payed_time'] = time();
$map_s['pay_order_number'] = $data['out_trade_no'];
$r = $spend->where($map_s)->save($data_save);
return false; return false;
} }
@ -835,4 +842,67 @@ class BaseController extends Controller {
return false; return false;
} }
} */ } */
// 根据订单号 获取支付配置
protected function getPayConfByOrderId($orderNo) {
$order = array();
if (substr($orderNo, 0, 2) == "SP") {
$order = M('spend', 'tab_')->where([
'pay_order_number' => $orderNo
])->find();
} else {
$order = M('despo', 'tab_')->where([
'pay_order_number' => $orderNo
])->find();
}
if (!$order) {
return array(
'code' => 1,
'msg' => "订单号不存在pay_order_number".$orderNo,
'data' => array()
);
}
$payConf = M('payment_merchant', 'tab_')->where([
'id' => $order['merchant_id']
])->find();
if (!$payConf) {
return array(
'code' => 1,
'msg' => "找不到支付配置merchant_id".$order['merchant_id'],
'data' => array()
);
}
$payConf = json_decode($payConf['config'], true);
return array(
'code' => 0,
'msg' => '',
'data' => $payConf,
);
}
// 根据商户号 获取支付配置
protected function getPayConfByIdentifier($identifier) {
$payConf = M('payment_merchant', 'tab_')->where([
'identifier' => $identifier
])->find();
if (!$payConf) {
return array(
'code' => 1,
'msg' => "找不到支付配置identifier".$identifier,
'data' => array()
);
}
$payConf = json_decode($payConf['config'], true);
return array(
'code' => 0,
'msg' => '',
'data' => $payConf,
);
}
} }

@ -41,15 +41,26 @@ class Notify2Controller extends BaseController
Vendor('Alipay.AopSdk'); Vendor('Alipay.AopSdk');
$aop = new \AopClient(); $aop = new \AopClient();
$aop->alipayrsaPublicKey = C('alipay.pub_secret'); Vendor('Alipay.AopSdk');
if (isset($notify['auth_app_id']) && $notify['auth_app_id'] == C('ALIPAY_KBC_APPID')) { $aop = new \AopClient();
$aop->alipayrsaPublicKey = C('ALIPAY_KBC_PUB');
if (!$notify['auth_app_id']) {
$this->record_logs("auth_app_id不存在");
echo 'fail';
exit();
} }
$merchant = M('payment_merchant', 'tab_')->where([
if (!$aop->alipayrsaPublicKey) { 'identifier' => $notify['auth_app_id']
$aop->alipayrsaPublicKey = file_get_contents("./Application/Sdk/SecretKey/alipay/alipay2_public_key.txt"); ])->find();
if (!$merchant) {
$this->record_logs("找不到商户!".$notify['auth_app_id']);
echo 'fail';
exit();
} }
$payConf = json_decode($merchant['config'], true);
$aop->alipayrsaPublicKey = $payConf['public_key'];
$result = $aop->rsaCheckV1($notify,'','RSA2'); $result = $aop->rsaCheckV1($notify,'','RSA2');
if ($result) { if ($result) {
//获取回调订单信息 //获取回调订单信息
@ -74,9 +85,9 @@ class Notify2Controller extends BaseController
case 'TB': case 'TB':
$result = $this->set_balance($order_info); $result = $this->set_balance($order_info);
break; break;
case 'SI': case 'SI':
$result = $this->set_order($order_info); $result = $this->set_order($order_info);
break; break;
default: default:
exit('accident order data'); exit('accident order data');
break; break;

@ -7,6 +7,7 @@ use Org\SwiftpassSDK\Swiftpass;
use Think\Log; use Think\Log;
use Qiniu\json_decode; use Qiniu\json_decode;
use Sdk\Controller\Ipa365Controller; use Sdk\Controller\Ipa365Controller;
use Base\Tool\Redis;
/** /**
@ -278,21 +279,46 @@ class NotifyController extends BaseController
public function wxpay_callback() public function wxpay_callback()
{ {
Log::write("timeout".time(), Log::DEBUG);
$key = "sdk:paycallback_wx";
$ret = Redis::get($key);
if ($ret) {
Log::write("sdk:paycallback_wx 请求太频繁", Log::DEBUG);
exit();
}
Redis::set($key, 1, 3); // 3秒钟收一次请求
$values = array(); $values = array();
Vendor("WxPayPubHelper.WxPayPubHelper"); Vendor("WxPayPubHelper.WxPayPubHelper");
$weixin = A("WeiXin", "Event"); $weixin = A("WeiXin", "Event");
$request = file_get_contents("php://input"); $request = file_get_contents("php://input");
$reqdata = $weixin->xmlstr_to_array($request); $reqdata = $weixin->xmlstr_to_array($request);
Log::write(serialize($reqdata), Log::DEBUG);
if ($reqdata['return_code'] != 'SUCCESS') { if ($reqdata['return_code'] != 'SUCCESS') {
$this->record_logs("return_code返回数据错误"); $this->record_logs("return_code返回数据错误");
exit(); exit();
} else { } else {
$merchant = M('payment_merchant', 'tab_')->where([
'identifier' => $reqdata['mch_id']
])->find();
if (!$merchant) {
$this->record_logs("找不到商户!".$reqdata['mch_id']);
echo 'fail';
exit();
}
$payConf = json_decode($merchant['config'], true);
if ($_REQUEST['method'] == "notify2") {//sdk if ($_REQUEST['method'] == "notify2") {//sdk
$Common_util_pub = new \Common_util_pub(C('wei_xin_app.email'), C('wei_xin_app.partner'), C('wei_xin_app.key')); $Common_util_pub = new \Common_util_pub(C('wei_xin_app.email'), C('wei_xin_app.partner'), C('wei_xin_app.key'));
} elseif ($_REQUEST['method'] == "notify3") { //app } elseif ($_REQUEST['method'] == "notify3") { //app
$Common_util_pub = new \Common_util_pub(C('wei_xin_apps.email'), C('wei_xin_apps.partner'), C('wei_xin_apps.key')); $Common_util_pub = new \Common_util_pub(C('wei_xin_apps.email'), C('wei_xin_apps.partner'), C('wei_xin_apps.key'));
} elseif ($_REQUEST['method'] == "notify") {//扫码 } elseif ($_REQUEST['method'] == "notify") {//扫码
$Common_util_pub = new \Common_util_pub(C('wei_xin.email'), C('wei_xin.partner'), C('wei_xin.key')); // $Common_util_pub = new \Common_util_pub(C('wei_xin.email'), C('wei_xin.partner'), C('wei_xin.key'));
$Common_util_pub = new \Common_util_pub($payConf['appid'], $payConf['partner'], $payConf['key']);
} }
if ($Common_util_pub->getSign($reqdata) == $reqdata['sign']) { if ($Common_util_pub->getSign($reqdata) == $reqdata['sign']) {
$pay_where = substr($reqdata['out_trade_no'], 0, 2); $pay_where = substr($reqdata['out_trade_no'], 0, 2);
@ -460,8 +486,17 @@ class NotifyController extends BaseController
Log::write(serialize($_REQUEST), Log::DEBUG); Log::write(serialize($_REQUEST), Log::DEBUG);
// pp(C('sqpay.key')); $merchant = M('payment_merchant', 'tab_')->where([
$secret = strtoupper(md5(C('sqpay.key')));//支付秘钥 'identifier' => $merNo
])->find();
if (!$merchant) {
$this->record_logs("找不到商户!".$notify['auth_app_id']);
echo 'fail';
exit();
}
$payConf = json_decode($merchant['config'], true);
$secret = strtoupper(md5($payConf['secret']));//支付秘钥
// 参与校验 // 参与校验
$sign = strtoupper(md5("Amount={$amount}&BillNo={$billNo}&MerNo={$merNo}&Succeed={$succed}&{$secret}")); $sign = strtoupper(md5("Amount={$amount}&BillNo={$billNo}&MerNo={$merNo}&Succeed={$succed}&{$secret}"));
@ -861,10 +896,26 @@ class NotifyController extends BaseController
public function yeepay_callback() { public function yeepay_callback() {
require_once("ThinkPHP/Library/Org/YeepaySDK/lib/Util/YopSignUtils.php"); require_once("ThinkPHP/Library/Org/YeepaySDK/lib/Util/YopSignUtils.php");
Log::write(serialize($_REQUEST), Log::DEBUG); Log::write(serialize($_REQUEST), Log::DEBUG);
$yop_public_key = C('yeepay.yop_public_key'); // $yop_public_key = C('yeepay.yop_public_key');
$private_key = C('yeepay.private_key'); // $private_key = C('yeepay.private_key');
$source = $_REQUEST['response']; $source = $_REQUEST['response'];
$identifier = $_REQUEST['customerIdentification'];
if (substr($identifier, 0, 4) == "OPR:") {
$identifier = substr($identifier, 4);
}
$merchant = M('payment_merchant', 'tab_')->where([
'identifier' => $identifier
])->find();
if (!$merchant) {
$this->record_logs("找不到商户!".$identifier);
echo 'fail';
exit();
}
$payConf = json_decode($merchant['config'], true);
$private_key = $payConf['private_key'];
$yop_public_key = $payConf['public_key'];
$sourceData = \YopSignUtils::decrypt($source, $private_key, $yop_public_key); $sourceData = \YopSignUtils::decrypt($source, $private_key, $yop_public_key);
$sourceData = json_decode($sourceData, true); $sourceData = json_decode($sourceData, true);
if ($sourceData['status'] != 'SUCCESS') { if ($sourceData['status'] != 'SUCCESS') {

@ -1968,11 +1968,211 @@ function get_shortcut_pay_type(){
} }
} }
function get_promote_company($user_id) {
if (!$user_id) return 0;
$promote_id = M('user', 'tab_')->where(['id' => $user_id])->getField('promote_id');
if (!$promote_id) return 0;
$promote = M('promote', 'tab_')->field(['company_id', 'id'])->where(['id' => $promote_id])->find();
if (!$promote) return 0;
$company = M('promote_company', 'tab_')->field(['company_belong', 'id'])->where(['id' => $promote['company_id']])->find();
if (!$company) return 0;
return $company;
}
// 0 默认 -^Euo2fM
function get_default_payment_config($way=1) {
$merchant = M('payment_merchant', 'tab_')->where(['_string' => 'ways&' . $way . '=' . $way . ' and is_default&' . $way . '=' . $way])->find();
if (is_null($merchant)) {
return -1;
// $merchant = M('payment_merchant', 'tab_')->where(['_string' => 'ways&' . $way . '=' . $way])->find();
}
return ['code' => 0, 'msg' => '', 'data' => $merchant];
}
// 获取支付配置 way 1 支付宝 2微信 3快捷
function get_payment_config($way=1, $game=0, $user_id=0) {
$time = time();
$company = get_promote_company($user_id);
$where = [];
$map = [];
$where['start_time'] = array('lt', $time);
$where['end_time'] = array('gt', $time);
$where['_logic'] = 'and';
$map['_complex'] = $where;
$map['end_time'] = 0;
$map['_logic'] = 'or';
$baseGameId = M('base_game', 'tab_')->where([
'android_game_id|ios_game_id' => $game['id']
])->getField('id');
if (!$baseGameId) {
return ['code' => -3, 'msg' => '找不到游戏ID'.$game['id'], 'data' => []];
}
$payment_rule = M('payment_rule', 'tab_')->where($map)->select();
$find_rule = false;
$rule = array();
if (!$company['id']) {
foreach ($payment_rule as $v) {
if ($v['game_id'] == $baseGameId && $v['game_type_id'] ==0 && $v['company_id'] == 0 && $v['company_belong'] == -1) {
$rule = $v;
$find_rule = true;
break;
}
}
if (!$find_rule) {
foreach ($payment_rule as $v) {
if ($v['game_type_id'] == $game['game_type_id'] && $v['game_id'] == 0 && $v['company_id'] == 0 && $v['company_belong'] == -1) {
$rule = $v;
$find_rule = true;
break;
}
}
}
if ($find_rule) {
$merchant_id = $rule['alipay_merchant_id'];
if ($way == 2)
$merchant_id = $rule['weixin_merchant_id'];
if ($way == 4)
$merchant_id = $rule['express_merchant_id'];
if ($merchant_id == 0) {
return get_default_payment_config($way);
}
$pay_conf = M('payment_merchant', 'tab_')->where([
'id' => $merchant_id
])->find();
if (!$pay_conf) {
return ['code' => -2, 'msg' => '找不到对应的支付配置'.$merchant_id, 'data' => []];
}
return ['code' => 0, 'msg' => '', 'data' => $pay_conf];
}
return get_default_payment_config($way);
} else {
// 最优先推广公司 游戏
foreach ($payment_rule as $v) {
if ($v['company_id'] == $company['id'] && $v['game_id'] == $baseGameId && $v['game_type_id'] == 0 && $v['company_belong'] == -1) {
$rule = $v;
$find_rule = true;
// echo '1';
break;
}
}
// 2 推广公司 所有游戏
if (!$find_rule) {
foreach ($payment_rule as $v) {
if ($v['company_id'] == $company['id'] && $v['game_id'] == 0 && $v['game_type_id'] == 0 && $v['company_belong'] == -1) {
$rule = $v;
$find_rule = true;
// echo '2';
break;
}
}
}
// 3 0-内团1-外团 2-分发联盟 3 无 === 游戏
if (!$find_rule) {
foreach ($payment_rule as $v) {
if ($v['company_id'] == 0 && $v['company_belong'] == $company['company_belong'] && $v['game_id'] == $baseGameId && $v['game_type_id'] == 0) {
$rule = $v;
$find_rule = true;
// echo '3';
break;
}
}
}
// 3.1 内外团 游戏类型 所有游戏
if (!$find_rule) {
foreach ($payment_rule as $v) {
if ($v['company_id'] == 0 && $v['company_belong'] == $company['company_belong'] && $v['game_id'] == 0 && $game['game_type_id'] == $v['game_type_id']) {
$rule = $v;
$find_rule = true;
// echo '4';
break;
}
}
}
// 4 内外团 所有游戏
if (!$find_rule) {
foreach ($payment_rule as $v) {
if ($v['company_id'] == 0 && $v['company_belong'] == $company['company_belong'] && $v['game_id'] == 0 && $v['game_type_id'] == 0) {
$rule = $v;
$find_rule = true;
// echo '5';
break;
}
}
}
// 5 游戏
if (!$find_rule) {
foreach ($payment_rule as $v) {
if ($v['company_id'] == 0 && $v['company_belong'] == -1 && $v['game_id'] == $baseGameId && $v['game_type_id'] == 0) {
$rule = $v;
$find_rule = true;
// echo '6';
break;
}
}
}
// 6 游戏类型
if (!$find_rule) {
foreach ($payment_rule as $v) {
if ($v['company_id'] == 0 && $v['company_belong'] == -1 && $v['game_id'] == 0 && $v['game_type_id'] == $game['game_type_id']) {
$rule = $v;
$find_rule = true;
// echo '7';
break;
}
}
}
if ($find_rule) {
// var_dump($rule);
$merchant_id = $rule['alipay_merchant_id'];
if ($way == 2)
$merchant_id = $rule['weixin_merchant_id'];
if ($way == 4)
$merchant_id = $rule['express_merchant_id'];
if ($merchant_id == 0) {
return get_default_payment_config($way);
}
$pay_conf = M('payment_merchant', 'tab_')->where([
'id' => $merchant_id
])->find();
if (!$pay_conf) {
return ['code' => -2, 'msg' => '找不到对应的支付配置'.$merchant_id, 'data' => []];
}
return ['code' => 0, 'msg' => '', 'data' => $pay_conf];
}
return get_default_payment_config($way);
}
}
//获取微信支付类型 0官方 1金猪wap 2双乾 //获取微信支付类型 0官方 1金猪wap 2双乾
function get_zfb_type($game_id=0, $user_id=0){ function get_zfb_type($game_id=0, $user_id=0){
if ($game_id) { /* if ($game_id) {
$game = M('game', 'tab_')->where(['id' => $game_id])->find(); $game = M('game', 'tab_')->where(['id' => $game_id])->find();
if ($game && $game['pay_config']) { if ($game && $game['pay_config']) {
$payConf = json_decode($game['pay_config'], true); $payConf = json_decode($game['pay_config'], true);
@ -1994,7 +2194,7 @@ function get_zfb_type($game_id=0, $user_id=0){
return -1; return -1;
} }
} }
} } */ // 取消按游戏区分商户20200716
if(C('alipay.status') == 1) {return 0;} if(C('alipay.status') == 1) {return 0;}
$map['name']='goldpig'; $map['name']='goldpig';

@ -563,6 +563,9 @@ class BaseController extends RestController{
$data_spned['pay_url'] = $param["pay_url"]; $data_spned['pay_url'] = $param["pay_url"];
} }
$data_spned['merchant_id'] = isset($param['merchant_id']) ? $param['merchant_id'] : 0 ;
$data_spned['merchant_way'] = isset($param['merchant_way']) ? $param['merchant_way'] : 0;
return $data_spned; return $data_spned;
} }
@ -591,6 +594,10 @@ class BaseController extends RestController{
$data_deposit['pay_url'] = $param["pay_url"]; $data_deposit['pay_url'] = $param["pay_url"];
} }
$data_deposit['create_time'] = NOW_TIME; $data_deposit['create_time'] = NOW_TIME;
$data_deposit['merchant_id'] = isset($param['merchant_id']) ? $param['merchant_id'] : 0 ;
$data_deposit['merchant_way'] = isset($param['merchant_way']) ? $param['merchant_way'] : 0;
return $data_deposit; return $data_deposit;
} }

File diff suppressed because it is too large Load Diff

@ -489,7 +489,7 @@ class ShortcutController extends BaseController{
exit; exit;
} }
$game = M('Game','tab_')->where(['id'=>$request['game_id']])->field('pay_status')->find(); $game = M('Game','tab_')->where(['id'=>$request['game_id']])->field('id, game_type_id, pay_status')->find();
if($game['pay_status'] == 0){ if($game['pay_status'] == 0){
echo json_encode(['code'=>0, 'msg'=> "该游戏暂时无法充值,请联系客服!"]); echo json_encode(['code'=>0, 'msg'=> "该游戏暂时无法充值,请联系客服!"]);
exit; exit;
@ -585,11 +585,22 @@ class ShortcutController extends BaseController{
} }
} }
$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;
}
$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(); $yeepay = new Yeepay();
$data['appKey'] = C('yeepay.key'); $data['appKey'] = $pay_conf['key'];//C('yeepay.key');
$data['privateKey'] = C('yeepay.private_key'); $data['privateKey'] = $pay_conf['private_key'];//C('yeepay.private_key');
$data['parentMerchantNo'] = C('yeepay.parent_merchant'); $data['parentMerchantNo'] = $pay_conf['parent_merchant'];//C('yeepay.parent_merchant');
$data['merchantNo'] = C('yeepay.partner'); $data['merchantNo'] = $pay_conf['partner'];//C('yeepay.partner');
$data['orderId'] = $request['pay_order_number']; $data['orderId'] = $request['pay_order_number'];
$data['orderAmount'] = $request['price']; $data['orderAmount'] = $request['price'];
$data['notifyUrl'] = C('PAY_DOMAIN')."/callback.php/Notify/yeepay_callback"; $data['notifyUrl'] = C('PAY_DOMAIN')."/callback.php/Notify/yeepay_callback";

@ -50,6 +50,7 @@ class SpendController extends Controller {
public function pay_way() { public function pay_way() {
$user_id = I ('user_id'); $user_id = I ('user_id');
$game_id = I ('game_id'); $game_id = I ('game_id');
$user_token = I('user_token'); $user_token = I('user_token');
if (!$user_token) { if (!$user_token) {
echo "access deny!"; echo "access deny!";

@ -80,6 +80,7 @@ class UserHController extends Controller
public function platform_pay() public function platform_pay()
{ {
C(BaseController::get_tool()); C(BaseController::get_tool());
$u = M('user', 'tab_')->where(['id' => $this->userId])->find(); $u = M('user', 'tab_')->where(['id' => $this->userId])->find();
$money = I('money', 0); $money = I('money', 0);
$api_ver = I('api_ver', 0); $api_ver = I('api_ver', 0);

@ -29,6 +29,7 @@
</div> </div>
<div class="containner"> <div class="containner">
<div class="documents"> <div class="documents">
<div class="documents_box"> <div class="documents_box">
<div><span>充值账号:</span> <span>{$account}</span> </div> <div><span>充值账号:</span> <span>{$account}</span> </div>

@ -7,187 +7,188 @@ use Think\Exception;
class Weixin class Weixin
{ {
public function weixin_pay($title, $order_no, $pay_amount, $trade_type = "NATIVE", $tt = 1) public function weixin_pay($title, $order_no, $pay_amount, $trade_type = "NATIVE", $tt = 1, $payConf=array())
{ {
//官方 //官方
header("Content-type:text/html;charset=utf-8"); header("Content-type:text/html;charset=utf-8");
Vendor("WxPayPubHelper.WxPayPubHelper"); Vendor("WxPayPubHelper.WxPayPubHelper");
// $data['pay_type'] = "weixin"; // $data['pay_type'] = "weixin";
//使用统一支付接口 //使用统一支付接口
if ($tt == 1 || $tt == 4) { //扫码 || 超级签h5 if ($tt == 1 || $tt == 4) { //扫码 || 超级签h5
$notifyy="notify"; $notifyy="notify";
$unifiedOrder = new \UnifiedOrder_pub(C('wei_xin.email'), C('wei_xin.partner'), C('wei_xin.key')); // $unifiedOrder = new \UnifiedOrder_pub(C('wei_xin.email'), C('wei_xin.partner'), C('wei_xin.key'));
$unifiedOrder = new \UnifiedOrder_pub($payConf['appid'], $payConf['partner'], $payConf['key']);
} else if($tt==2) { //sdk,公众号 } else if($tt==2) { //sdk,公众号
$notifyy="notify2"; $notifyy="notify2";
$unifiedOrder = new \UnifiedOrder_pub(C('wei_xin_app.email'), C('wei_xin_app.partner'), C('wei_xin_app.key')); $unifiedOrder = new \UnifiedOrder_pub(C('wei_xin_app.email'), C('wei_xin_app.partner'), C('wei_xin_app.key'));
}else{ }else{
$notifyy="notify3";//3 app支付 $notifyy="notify3";//3 app支付
$unifiedOrder = new \UnifiedOrder_pub(C('wei_xin_apps.email'), C('wei_xin_apps.partner'), C('wei_xin_apps.key')); $unifiedOrder = new \UnifiedOrder_pub(C('wei_xin_apps.email'), C('wei_xin_apps.partner'), C('wei_xin_apps.key'));
} }
// $des='平台币充值'; // $des='平台币充值';
$unifiedOrder->setParameter("body", $title);//商品描述 $unifiedOrder->setParameter("body", $title);//商品描述
//自定义订单号,此处仅作举例 //自定义订单号,此处仅作举例
$timeStamp = time(); $timeStamp = time();
$unifiedOrder->setParameter("out_trade_no", $order_no);//商户订单号 $unifiedOrder->setParameter("out_trade_no", $order_no);//商户订单号
$unifiedOrder->setParameter("total_fee", $pay_amount * 100);//总金额 $unifiedOrder->setParameter("total_fee", $pay_amount * 100);//总金额
if($tt==4){ if($tt==4){
$unifiedOrder->setParameter("notify_url", "http://" . $_SERVER['HTTP_HOST'] . "/callback.php/Notify/supersign_wxpay_notify");//通知地址 $unifiedOrder->setParameter("notify_url", "http://" . $_SERVER['HTTP_HOST'] . "/callback.php/Notify/supersign_wxpay_notify");//通知地址
}else{ }else{
$unifiedOrder->setParameter("notify_url", "http://" . $_SERVER['HTTP_HOST'] . "/callback.php/Notify/wxpay_callback/method/".$notifyy);//通知地址 $unifiedOrder->setParameter("notify_url", "http://" . $_SERVER['HTTP_HOST'] . "/callback.php/Notify/wxpay_callback/method/".$notifyy);//通知地址
} }
$unifiedOrder->setParameter("trade_type", $trade_type);//交易类型 $unifiedOrder->setParameter("trade_type", $trade_type);//交易类型
$unifiedOrder->setParameter("product_id", $order_no);//商品ID $unifiedOrder->setParameter("product_id", $order_no);//商品ID
if($trade_type=="MWEB"){ if($trade_type=="MWEB"){
$scene_info['h5_info']=['type'=>'Wap','wap_url'=>"http://" . $_SERVER['HTTP_HOST'],'wap_name'=>'充值']; $scene_info['h5_info']=['type'=>'Wap','wap_url'=>"http://" . $_SERVER['HTTP_HOST'],'wap_name'=>'充值'];
$unifiedOrder->setParameter("scene_info", json_encode($scene_info));//场景信息 $unifiedOrder->setParameter("scene_info", json_encode($scene_info));//场景信息
} }
//获取统一支付接口结果 //获取统一支付接口结果
$unifiedOrderResult = $unifiedOrder->getResult($tt); $unifiedOrderResult = $unifiedOrder->getResult($tt);
//商户根据实际情况设置相应的处理流程 //商户根据实际情况设置相应的处理流程
if ($unifiedOrderResult["return_code"] == "FAIL") { if ($unifiedOrderResult["return_code"] == "FAIL") {
//商户自行增加处理流程 //商户自行增加处理流程
// echo base64_encode(json_encode(array('status' => 0, 'return_msg' => $unifiedOrderResult['return_msg']))); // echo base64_encode(json_encode(array('status' => 0, 'return_msg' => $unifiedOrderResult['return_msg'])));
return json_encode(array('status' => 0, 'return_msg' => $unifiedOrderResult['return_msg'])); return json_encode(array('status' => 0, 'return_msg' => $unifiedOrderResult['return_msg']));
} elseif ($unifiedOrderResult["result_code"] == "FAIL") { } elseif ($unifiedOrderResult["result_code"] == "FAIL") {
//商户自行增加处理流程 //商户自行增加处理流程
// echo "错误代码:".$unifiedOrderResult['err_code']."<br>"; // echo "错误代码:".$unifiedOrderResult['err_code']."<br>";
// echo base64_encode(json_encode(array('status' => 0, 'return_msg' => $unifiedOrderResult['err_code_des']))); // echo base64_encode(json_encode(array('status' => 0, 'return_msg' => $unifiedOrderResult['err_code_des'])));
return json_encode(array('status' => 0, 'return_msg' => $unifiedOrderResult['err_code_des'])); return json_encode(array('status' => 0, 'return_msg' => $unifiedOrderResult['err_code_des']));
} elseif ($unifiedOrderResult["code_url"] != NULL) { } elseif ($unifiedOrderResult["code_url"] != NULL) {
//从统一支付接口获取到code_url //从统一支付接口获取到code_url
$code_url = $unifiedOrderResult["code_url"]; $code_url = $unifiedOrderResult["code_url"];
//商户自行增加处理流程 //商户自行增加处理流程
if ($unifiedOrderResult['return_code'] !== "SUCCESS") { if ($unifiedOrderResult['return_code'] !== "SUCCESS") {
\Think\Log::record($unifiedOrderResult['msg']); \Think\Log::record($unifiedOrderResult['msg']);
$html = '<div class="d_body" style="height:px;"> $html = '<div class="d_body" style="height:px;">
<div class="d_content"> <div class="d_content">
<div class="text_center">' . $unifiedOrderResult["return_code"] . '</div> <div class="text_center">' . $unifiedOrderResult["return_code"] . '</div>
</div> </div>
</div>'; </div>';
} else { } else {
return json_encode(array("status" => 1, 'url' => $unifiedOrderResult['code_url'])); return json_encode(array("status" => 1, 'url' => $unifiedOrderResult['code_url']));
} }
} else { } else {
file_put_contents(dirname(__FILE__).'/$unifiedOrderResult.txt',json_encode($unifiedOrderResult)); file_put_contents(dirname(__FILE__).'/$unifiedOrderResult.txt',json_encode($unifiedOrderResult));
if ($trade_type == "APP") { if ($trade_type == "APP") {
$app_data['appid'] = $unifiedOrderResult['appid']; $app_data['appid'] = $unifiedOrderResult['appid'];
$app_data['partnerid'] = $unifiedOrderResult['mch_id']; $app_data['partnerid'] = $unifiedOrderResult['mch_id'];
$app_data['prepayid'] = $unifiedOrderResult['prepay_id']; $app_data['prepayid'] = $unifiedOrderResult['prepay_id'];
$app_data['noncestr'] = $unifiedOrder->createNoncestr(); $app_data['noncestr'] = $unifiedOrder->createNoncestr();
$app_data['timestamp'] = time(); $app_data['timestamp'] = time();
$app_data['package'] = "Sign=WXPay"; $app_data['package'] = "Sign=WXPay";
$sign = $unifiedOrder->getSign($app_data); $sign = $unifiedOrder->getSign($app_data);
return json_encode(array("status" => 1, 'appid' => $unifiedOrderResult['appid'], 'mch_id' => $unifiedOrderResult['mch_id'], 'prepay_id' => $unifiedOrderResult['prepay_id'], 'time' => $app_data['timestamp'], 'noncestr' => $app_data['noncestr'], 'sign' => $sign)); return json_encode(array("status" => 1, 'appid' => $unifiedOrderResult['appid'], 'mch_id' => $unifiedOrderResult['mch_id'], 'prepay_id' => $unifiedOrderResult['prepay_id'], 'time' => $app_data['timestamp'], 'noncestr' => $app_data['noncestr'], 'sign' => $sign));
} else if ($trade_type == "MWEB") { } else if ($trade_type == "MWEB") {
return json_encode(array("status" => 1, 'mweb_url' => $unifiedOrderResult['mweb_url'])); return json_encode(array("status" => 1, 'mweb_url' => $unifiedOrderResult['mweb_url']));
} }
} }
} }
public function weixin_jsapi($title, $order_no, $pay_amount, $jsApi, $openid = "") public function weixin_jsapi($title, $order_no, $pay_amount, $jsApi, $openid = "")
{ {
//官方 //官方
header("Content-type:text/html;charset=utf-8"); header("Content-type:text/html;charset=utf-8");
Vendor("WxPayPubHelper.WxPayPubHelper"); Vendor("WxPayPubHelper.WxPayPubHelper");
$unifiedOrder = new \UnifiedOrder_pub(C('wei_xin.email'), C('wei_xin.partner'), C('wei_xin.key')); $unifiedOrder = new \UnifiedOrder_pub(C('wei_xin.email'), C('wei_xin.partner'), C('wei_xin.key'));
// $des='平台币充值'; // $des='平台币充值';
$unifiedOrder->setParameter("body", $title);//商品描述 $unifiedOrder->setParameter("body", $title);//商品描述
//自定义订单号,此处仅作举例 //自定义订单号,此处仅作举例
$timeStamp = time(); $timeStamp = time();
$unifiedOrder->setParameter("openid", $openid);//商品描述 $unifiedOrder->setParameter("openid", $openid);//商品描述
$unifiedOrder->setParameter("out_trade_no", $order_no);//商户订单号 $unifiedOrder->setParameter("out_trade_no", $order_no);//商户订单号
$unifiedOrder->setParameter("total_fee", $pay_amount * 100);//总金额 $unifiedOrder->setParameter("total_fee", $pay_amount * 100);//总金额
$unifiedOrder->setParameter("notify_url", "http://" . $_SERVER['HTTP_HOST'] . "/callback.php/Notify/wxpay_callback/method/notify");//通知地址 $unifiedOrder->setParameter("notify_url", "http://" . $_SERVER['HTTP_HOST'] . "/callback.php/Notify/wxpay_callback/method/notify");//通知地址
$unifiedOrder->setParameter("trade_type", "JSAPI");//交易类型 $unifiedOrder->setParameter("trade_type", "JSAPI");//交易类型
$unifiedOrder->setParameter("product_id", $order_no);//商品ID $unifiedOrder->setParameter("product_id", $order_no);//商品ID
$prepay_id = $unifiedOrder->getPrepayId(); $prepay_id = $unifiedOrder->getPrepayId();
//=========步骤3使用jsapi调起支付============ //=========步骤3使用jsapi调起支付============
$jsApi->setPrepayId($prepay_id); $jsApi->setPrepayId($prepay_id);
$jsApiParameters = $jsApi->getParameters(); $jsApiParameters = $jsApi->getParameters();
return $jsApiParameters; return $jsApiParameters;
} }
/** /**
* 微信退款接口 * 微信退款接口
* @param $out_trade_no 商户订单号 * @param $out_trade_no 商户订单号
@ -203,7 +204,7 @@ class Weixin
Vendor("WxPayPubHelper.WxPayPubHelper"); Vendor("WxPayPubHelper.WxPayPubHelper");
// $unifiedOrder = new \Refund_pub(C('wei_xin_app.email'), C('wei_xin_app.partner'), C('wei_xin_app.key')); // $unifiedOrder = new \Refund_pub(C('wei_xin_app.email'), C('wei_xin_app.partner'), C('wei_xin_app.key'));
$unifiedOrder = new \Refund_pub(C('wei_xin.email'), C('wei_xin.partner'), C('wei_xin.key')); $unifiedOrder = new \Refund_pub(C('wei_xin.email'), C('wei_xin.partner'), C('wei_xin.key'));
$unifiedOrder->setParameter("out_trade_no", $out_trade_no);//商户订单号 $unifiedOrder->setParameter("out_trade_no", $out_trade_no);//商户订单号
$unifiedOrder->setParameter("out_refund_no", $out_refund_no);//商户退款单号 $unifiedOrder->setParameter("out_refund_no", $out_refund_no);//商户退款单号
$unifiedOrder->setParameter("total_fee", $total_fee * 100);//通知地址 $unifiedOrder->setParameter("total_fee", $total_fee * 100);//通知地址
@ -218,7 +219,7 @@ class Weixin
//商户自行增加处理流程 //商户自行增加处理流程
// echo "错误代码:".$unifiedOrderResult['err_code']."<br>"; // echo "错误代码:".$unifiedOrderResult['err_code']."<br>";
return json_encode(array('status' => 0, 'msg' => $unifiedOrderResult['err_code_des'])); return json_encode(array('status' => 0, 'msg' => $unifiedOrderResult['err_code_des']));
} else { } else {
//商户自行增加处理流程 //商户自行增加处理流程
if ($unifiedOrderResult['return_code'] !== "SUCCESS") { if ($unifiedOrderResult['return_code'] !== "SUCCESS") {
@ -228,10 +229,10 @@ class Weixin
return json_encode(array("status" => 1, 'msg' => '成功')); return json_encode(array("status" => 1, 'msg' => '成功'));
} }
} }
} }
/** /**
* 微信退款查询接口 * 微信退款查询接口
* @param $out_trade_no 商户订单号 * @param $out_trade_no 商户订单号
@ -247,7 +248,7 @@ class Weixin
Vendor("WxPayPubHelper.WxPayPubHelper"); Vendor("WxPayPubHelper.WxPayPubHelper");
// $unifiedOrder = new \RefundQuery_pub(C('wei_xin_app.email'), C('wei_xin_app.partner'), C('wei_xin_app.key')); // $unifiedOrder = new \RefundQuery_pub(C('wei_xin_app.email'), C('wei_xin_app.partner'), C('wei_xin_app.key'));
$unifiedOrder = new \RefundQuery_pub(C('wei_xin.email'), C('wei_xin.partner'), C('wei_xin.key')); $unifiedOrder = new \RefundQuery_pub(C('wei_xin.email'), C('wei_xin.partner'), C('wei_xin.key'));
$unifiedOrder->setParameter("out_trade_no", $out_trade_no);//商户订单号 $unifiedOrder->setParameter("out_trade_no", $out_trade_no);//商户订单号
//获取退款接口结果 //获取退款接口结果
$unifiedOrderResult = $unifiedOrder->getResult(); $unifiedOrderResult = $unifiedOrder->getResult();
@ -257,41 +258,41 @@ class Weixin
} elseif ($unifiedOrderResult["result_code"] == "FAIL") { } elseif ($unifiedOrderResult["result_code"] == "FAIL") {
//商户自行增加处理流程 //商户自行增加处理流程
return $unifiedOrderResult['err_code_des']; return $unifiedOrderResult['err_code_des'];
} else { } else {
return $unifiedOrderResult['return_code']; return $unifiedOrderResult['return_code'];
} }
} }
/** /**
* 微信查询接口 * 微信查询接口
* @param $out_trade_no 商户订单号 * @param $out_trade_no 商户订单号
* @return string * @return string
* @author 鹿文学 * @author 鹿文学
*/ */
public function weixin_orderquery($out_trade_no) { public function weixin_orderquery($out_trade_no) {
header("Content-type:text/html;charset=utf-8"); header("Content-type:text/html;charset=utf-8");
Vendor("WxPayPubHelper.WxPayPubHelper"); Vendor("WxPayPubHelper.WxPayPubHelper");
$orderquery = new \OrderQuery_pub(C('wei_xin.email'), C('wei_xin.partner'),C('wei_xin.key')); $orderquery = new \OrderQuery_pub(C('wei_xin.email'), C('wei_xin.partner'),C('wei_xin.key'));
$orderquery->setParameter('out_trade_no',$out_trade_no);//商户订单号 $orderquery->setParameter('out_trade_no',$out_trade_no);//商户订单号
$orderqueryresult = $orderquery->getResult(); $orderqueryresult = $orderquery->getResult();
if($orderqueryresult['return_code']=='FAIL') { if($orderqueryresult['return_code']=='FAIL') {
return $orderqueryresult['return_msg']; return $orderqueryresult['return_msg'];
} elseif ($orderqueryresult["result_code"] == "FAIL") { } elseif ($orderqueryresult["result_code"] == "FAIL") {
//商户自行增加处理流程 //商户自行增加处理流程
return $orderqueryresult['err_code_des']; return $orderqueryresult['err_code_des'];
} elseif ($orderqueryresult['trade_state'] == 'FAIL') { } elseif ($orderqueryresult['trade_state'] == 'FAIL') {
return '支付失败'; return '支付失败';
} else { } else {
if($orderqueryresult['trade_state']=='SUCCESS') { if($orderqueryresult['trade_state']=='SUCCESS') {
return $orderqueryresult['out_trade_no']; return $orderqueryresult['out_trade_no'];
} else { } else {
return $orderqueryresult['trade_state_desc']; return $orderqueryresult['trade_state_desc'];
} }
} }
} }
/** /**
* 微信查询接口 * 微信查询接口
* @param $out_trade_no 商户订单号 * @param $out_trade_no 商户订单号
@ -319,6 +320,6 @@ class Weixin
} }
} }
} }
} }

@ -12,25 +12,25 @@ use Base\Service\PromoteService;
class Pay class Pay
{ {
/** /**
* 支付驱动实例 * 支付驱动实例
* @var Object * @var Object
*/ */
private $payer; private $payer;
/** /**
* 配置参数 * 配置参数
* @var type * @var type
*/ */
private $config; private $config;
/** /**
* 支付类型 * 支付类型
* @var type * @var type
*/ */
private $apitype; private $apitype;
/** /**
* 构造方法,用于构造上传实例 * 构造方法,用于构造上传实例
* @param string $driver 要使用的支付驱动 * @param string $driver 要使用的支付驱动
@ -50,7 +50,7 @@ class Pay
$class = strpos($driver, '\\') ? $driver : 'Think\\Pay\\Driver\\' . ucfirst(strtolower($driver)); $class = strpos($driver, '\\') ? $driver : 'Think\\Pay\\Driver\\' . ucfirst(strtolower($driver));
$this->setDriver($class, $config); $this->setDriver($class, $config);
} }
public function isKBCPartner($promoteId) public function isKBCPartner($promoteId)
{ {
$promote = null; $promote = null;
@ -66,26 +66,25 @@ class Pay
} }
return false; return false;
} }
public function buildRequestForm(Pay\PayVo $vo, $uc = 0, $param=array()) public function buildRequestForm(Pay\PayVo $vo, $uc = 0, $param=array(), $payConf=array())
{ {
$promoteId = 0; /* $promoteId = 0;
if ($vo->getPromoteId()) { if ($vo->getPromoteId()) {
$promoteId = $vo->getPromoteId(); $promoteId = $vo->getPromoteId();
} elseif (isset($param['promote_id']) && $param['promote_id']) { } elseif (isset($param['promote_id']) && $param['promote_id']) {
$promoteId = $param['promote_id']; $promoteId = $param['promote_id'];
} }
$isKBCPartner = $this->isKBCPartner($promoteId); $isKBCPartner = $this->isKBCPartner($promoteId); */
$this->payer->check(); $this->payer->check();
$result = false; $result = false;
if ($uc == 0) { if ($uc == 0) {
switch ($vo->getTable()) { switch ($vo->getTable()) {
case 'spend': case 'spend':
$result = $this->add_spend($vo, $param, $isKBCPartner); $result = $this->add_spend($vo, $param, $payConf);
break; break;
case 'deposit': case 'deposit':
$result = $this->add_deposit($vo, $isKBCPartner); $result = $this->add_deposit($vo, $param, $payConf);
break; break;
case 'agent': case 'agent':
$result = $this->add_agent($vo); $result = $this->add_agent($vo);
@ -102,12 +101,12 @@ class Pay
case 'Withdraw': case 'Withdraw':
$result=1; $result=1;
break; break;
case 'order':{ case 'order':{
$result = $this->add_order($vo); $result = $this->add_order($vo);
};break; };break;
case 'supersign' : case 'supersign' :
$result=1; $result=1;
break; break;
default: default:
$result = false; $result = false;
break; break;
@ -115,7 +114,7 @@ class Pay
if ($result !== false) {//$check !== false if ($result !== false) {//$check !== false
if ($this->apitype == "alipay" && C('alipay.usenew')) { if ($this->apitype == "alipay" && C('alipay.usenew')) {
if (C('alipay.appid')) { if (C('alipay.appid')) {
return $this->newbuildRequestForm($vo, $isKBCPartner); return $this->newbuildRequestForm($vo, $payConf);
} else { } else {
E("appid未设置"); E("appid未设置");
exit('新版appid未填写'); exit('新版appid未填写');
@ -129,28 +128,25 @@ class Pay
} else { } else {
return $this->payer->buildRequestForm($vo); return $this->payer->buildRequestForm($vo);
} }
} }
/** /**
* 新版支付宝接口调用 * 新版支付宝接口调用
* */ * */
public function newbuildRequestForm(Pay\PayVo $vo, $isKBCPartner = false) public function newbuildRequestForm(Pay\PayVo $vo, $payConf=array())
{ {
if (!$payConf) return false;
Vendor('Alipay.AopSdk'); Vendor('Alipay.AopSdk');
$aop = new \AopClient(); $aop = new \AopClient();
$aop->appId = $isKBCPartner ? C('ALIPAY_KBC_APPID') : C('alipay.appid');
$aop->appId = $payConf['app_id'];
$aop->signType = 'RSA2'; $aop->signType = 'RSA2';
$aop->rsaPrivateKey = $isKBCPartner ? C('ALIPAY_KBC_PRI') : C('alipay.pri_secret'); $aop->rsaPrivateKey = $payConf['private_key'];
if (!$aop->rsaPrivateKey) { $aop->alipayrsaPublicKey = $payConf['public_key'];
$aop->rsaPrivateKey = file_get_contents("./Application/Sdk/SecretKey/alipay/rsa2_private_key.txt");
}
$aop->alipayrsaPublicKey = $isKBCPartner ? C('ALIPAY_KBC_PUB') : C('alipay.pub_secret');
if (!$aop->alipayrsaPublicKey) {
$aop->alipayrsaPublicKey = file_get_contents("./Application/Sdk/SecretKey/alipay/alipay2_public_key.txt");
}
$type = $vo->getPayMethod(); $type = $vo->getPayMethod();
//file_put_contents(dirname(__FILE__) . '/newbuildRequestForm.txt',json_encode($vo->getOrderNo())); //file_put_contents(dirname(__FILE__) . '/newbuildRequestForm.txt',json_encode($vo->getOrderNo()));
switch ($type) { switch ($type) {
case 'direct': case 'direct':
$productcode = 'FAST_INSTANT_TRADE_PAY'; $productcode = 'FAST_INSTANT_TRADE_PAY';
@ -168,29 +164,26 @@ class Pay
$request->setReturnUrl('http://' . $_SERVER ['HTTP_HOST'] . '/callback.php/Notify2/notify/apitype/alipay/methodtype/return_tb'); $request->setReturnUrl('http://' . $_SERVER ['HTTP_HOST'] . '/callback.php/Notify2/notify/apitype/alipay/methodtype/return_tb');
break; break;
case 'wap': case 'wap':
$returnurl = $vo->getCallback(); $returnurl = $vo->getCallback();
if (!$returnurl) if (!$returnurl)
$returnurl = 'http://' . $_SERVER ['HTTP_HOST'] . "/sdk.php/Spend/pay_success"; $returnurl = 'http://' . $_SERVER ['HTTP_HOST'] . "/sdk.php/Spend/pay_success";
$productcode = 'QUICK_WAP_PAY'; $productcode = 'QUICK_WAP_PAY';
$request = new \AlipayTradeWapPayRequest(); $request = new \AlipayTradeWapPayRequest();
$request->setReturnUrl($returnurl); $request->setReturnUrl($returnurl);
break; break;
case 'trade': case 'trade':
$productcode = 'QUICK_WAP_PAY'; $productcode = 'QUICK_WAP_PAY';
$request = new \AlipayTradeWapPayRequest(); $request = new \AlipayTradeWapPayRequest();
$request->setReturnUrl('http://' . $_SERVER ['HTTP_HOST'] . "/mobile.php/Trade/success"); $request->setReturnUrl('http://' . $_SERVER ['HTTP_HOST'] . "/mobile.php/Trade/success");
break; break;
case 'mobile': case 'mobile':
$aop->alipayrsaPublicKey = file_get_contents("./Application/Sdk/SecretKey/alipay/alipay2_public_key.txt");
$productcode = 'QUICK_MSECURITY_PAY'; $productcode = 'QUICK_MSECURITY_PAY';
$request = new \AlipayTradeAppPayRequest(); $request = new \AlipayTradeAppPayRequest();
break; break;
case 'refund': case 'refund':
$aop->alipayrsaPublicKey = file_get_contents("./Application/Sdk/SecretKey/alipay/alipay2_public_key.txt");
$request = new \AlipayTradeRefundRequest(); $request = new \AlipayTradeRefundRequest();
break; break;
case 'transfer': case 'transfer':
$aop->alipayrsaPublicKey = file_get_contents("./Application/Sdk/SecretKey/alipay/alipay2_public_key.txt");
$request = new \AlipayFundTransToaccountTransferRequest (); $request = new \AlipayFundTransToaccountTransferRequest ();
break; break;
default: default:
@ -200,137 +193,137 @@ class Pay
} }
$notifyurl = $vo->getNotifyUrl(); $notifyurl = $vo->getNotifyUrl();
if (!$notifyurl) if (!$notifyurl)
$notifyurl = 'http://' . $_SERVER ['HTTP_HOST'] . '/callback.php/Notify2/notify/apitype/alipay/methodtype/notify'; $notifyurl = 'http://' . $_SERVER ['HTTP_HOST'] . '/callback.php/Notify2/notify/apitype/alipay/methodtype/notify';
$request->setNotifyUrl($notifyurl); $request->setNotifyUrl($notifyurl);
switch ($type) { switch ($type) {
case 'direct': case 'direct':
$request->setBizContent('{"product_code":"' . $productcode . '","body":"' . $vo->getBody() . '","subject":"' . $vo->getTitle() . '","total_amount":"' . $vo->getFee() . '","out_trade_no":"' . $vo->getOrderNo() . '"}'); $request->setBizContent('{"product_code":"' . $productcode . '","body":"' . $vo->getBody() . '","subject":"' . $vo->getTitle() . '","total_amount":"' . $vo->getFee() . '","out_trade_no":"' . $vo->getOrderNo() . '"}');
return $aop->pageExecute($request, 'POST'); return $aop->pageExecute($request, 'POST');
break; break;
case 'direct_dc': case 'direct_dc':
$request->setBizContent('{"product_code":"' . $productcode . '","body":"' . $vo->getBody() . '","subject":"' . $vo->getTitle() . '","total_amount":"' . $vo->getFee() . '","out_trade_no":"' . $vo->getOrderNo() . '"}'); $request->setBizContent('{"product_code":"' . $productcode . '","body":"' . $vo->getBody() . '","subject":"' . $vo->getTitle() . '","total_amount":"' . $vo->getFee() . '","out_trade_no":"' . $vo->getOrderNo() . '"}');
return $aop->pageExecute($request, 'POST'); return $aop->pageExecute($request, 'POST');
break; break;
case 'direct_tb': case 'direct_tb':
$request->setBizContent('{"product_code":"' . $productcode . '","body":"' . $vo->getBody() . '","subject":"' . $vo->getTitle() . '","total_amount":"' . $vo->getFee() . '","out_trade_no":"' . $vo->getOrderNo() . '"}'); $request->setBizContent('{"product_code":"' . $productcode . '","body":"' . $vo->getBody() . '","subject":"' . $vo->getTitle() . '","total_amount":"' . $vo->getFee() . '","out_trade_no":"' . $vo->getOrderNo() . '"}');
return $aop->pageExecute($request, 'POST'); return $aop->pageExecute($request, 'POST');
break; break;
case 'wap': case 'wap':
/*参数 out_trade_no系统订单号*/ /*参数 out_trade_no系统订单号*/
$request->setBizContent('{"product_code":"' . $productcode . '","body":"' . $vo->getBody() . '","subject":"' . $vo->getTitle() . '","total_amount":"' . $vo->getFee() . '","out_trade_no":"' . $vo->getOrderNo() . '"}'); $request->setBizContent('{"product_code":"' . $productcode . '","body":"' . $vo->getBody() . '","subject":"' . $vo->getTitle() . '","total_amount":"' . $vo->getFee() . '","out_trade_no":"' . $vo->getOrderNo() . '"}');
return $aop->pageExecute($request, 'GET'); return $aop->pageExecute($request, 'GET');
break; break;
case 'trade': case 'trade':
/*参数 out_trade_no系统订单号*/ /*参数 out_trade_no系统订单号*/
$request->setBizContent('{"product_code":"' . $productcode . '","body":"' . $vo->getBody() . '","subject":"' . $vo->getTitle() . '","total_amount":"' . $vo->getFee() . '","out_trade_no":"' . $vo->getOrderNo() . '"}'); $request->setBizContent('{"product_code":"' . $productcode . '","body":"' . $vo->getBody() . '","subject":"' . $vo->getTitle() . '","total_amount":"' . $vo->getFee() . '","out_trade_no":"' . $vo->getOrderNo() . '"}');
return $aop->pageExecute($request, 'GET'); return $aop->pageExecute($request, 'GET');
break; break;
case 'mobile': case 'mobile':
/*参数 out_trade_no系统订单号*/ /*参数 out_trade_no系统订单号*/
$request->setBizContent('{"body":"' . $vo->getBody() . '","subject":"' . $vo->getTitle() . '","out_trade_no":"' . $vo->getOrderNo() . '","timeout_express":"30m","total_amount":"' . $vo->getFee() . '","product_code":"' . $productcode . '"}'); $request->setBizContent('{"body":"' . $vo->getBody() . '","subject":"' . $vo->getTitle() . '","out_trade_no":"' . $vo->getOrderNo() . '","timeout_express":"30m","total_amount":"' . $vo->getFee() . '","product_code":"' . $productcode . '"}');
$response = $aop->sdkExecute($request); $response = $aop->sdkExecute($request);
$sHtml['arg'] = $response['orderstr']; $sHtml['arg'] = $response['orderstr'];
$sHtml['sign'] = $response['sign']; $sHtml['sign'] = $response['sign'];
$sHtml['out_trade_no'] = $vo->getOrderNo(); $sHtml['out_trade_no'] = $vo->getOrderNo();
return $sHtml; return $sHtml;
break; break;
case 'refund': case 'refund':
$batch_no = $vo->getBatchNo(); $batch_no = $vo->getBatchNo();
$map['batch_no'] = $batch_no; $map['batch_no'] = $batch_no;
$refund = M('refund_record', 'tab_')->where($map)->find(); $refund = M('refund_record', 'tab_')->where($map)->find();
/*参数 out_trade_no系统订单号 trade_no支付宝订单号 refund_amount退款金额 out_request_no退款请求号 refund_reason退款原因*/ /*参数 out_trade_no系统订单号 trade_no支付宝订单号 refund_amount退款金额 out_request_no退款请求号 refund_reason退款原因*/
$request->setBizContent('{"out_trade_no":"","trade_no":"' . $vo->getOrderNo() . '","refund_amount":"' . $refund['pay_amount'] . '","out_request_no":"' . $batch_no . '","refund_reason":"调单"}'); $request->setBizContent('{"out_trade_no":"","trade_no":"' . $vo->getOrderNo() . '","refund_amount":"' . $refund['pay_amount'] . '","out_request_no":"' . $batch_no . '","refund_reason":"调单"}');
$result = $aop->execute($request); $result = $aop->execute($request);
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response"; $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
$resultCode = $result->$responseNode->code; $resultCode = $result->$responseNode->code;
if (!empty($resultCode) && $resultCode == 10000) { if (!empty($resultCode) && $resultCode == 10000) {
$date['tui_status'] = 1; $date['tui_status'] = 1;
$date['tui_time'] = time(); $date['tui_time'] = time();
M('refund_record', 'tab_')->where($map)->save($date); M('refund_record', 'tab_')->where($map)->save($date);
$map_spend['pay_order_number'] = get_refund_pay_order_number($batch_no); $map_spend['pay_order_number'] = get_refund_pay_order_number($batch_no);
$spen_date['sub_status'] = 1; $spen_date['sub_status'] = 1;
$spen_date['settle_check'] = 1; $spen_date['settle_check'] = 1;
M('spend', 'tab_')->where($map_spend)->save($spen_date); M('spend', 'tab_')->where($map_spend)->save($spen_date);
return "10000";//退款成功 return "10000";//退款成功
} else { } else {
return "退款失败"; return "退款失败";
} }
case 'transfer': case 'transfer':
$settlement_number = $vo->getOrderNo(); $settlement_number = $vo->getOrderNo();
$WidthdrawNo = $vo->getBatchNo(); $WidthdrawNo = $vo->getBatchNo();
$map['settlement_number'] = $settlement_number; $map['settlement_number'] = $settlement_number;
$widthdraw = M('withdraw', 'tab_')->where($map)->find(); $widthdraw = M('withdraw', 'tab_')->where($map)->find();
$promote = get_promote_entity($widthdraw['promote_id']); $promote = get_promote_entity($widthdraw['promote_id']);
/*参数 out_biz_no打款单号 payee_type账户类型 payee_account支付账号 amount转账金额 remark备注*/ /*参数 out_biz_no打款单号 payee_type账户类型 payee_account支付账号 amount转账金额 remark备注*/
// var_dump('{"out_biz_no":"'.$WidthdrawNo.'","payee_type":"ALIPAY_LOGONID","payee_a1ccount":"'.$promote['alipay_account'].'","amount":"'.$widthdraw['sum_money'].'","payer_show_name":"","payee_real_name":"","remark":"'.$vo->getDetailData().'"}');exit; // var_dump('{"out_biz_no":"'.$WidthdrawNo.'","payee_type":"ALIPAY_LOGONID","payee_a1ccount":"'.$promote['alipay_account'].'","amount":"'.$widthdraw['sum_money'].'","payer_show_name":"","payee_real_name":"","remark":"'.$vo->getDetailData().'"}');exit;
$request->setBizContent('{"out_biz_no":"'.$WidthdrawNo.'","payee_type":"ALIPAY_LOGONID","payee_account":"'.$promote['alipay_account'].'","amount":"'.$widthdraw['sum_money'].'","payer_show_name":"","payee_real_name":"","remark":"'.$vo->getDetailData().'"}'); $request->setBizContent('{"out_biz_no":"'.$WidthdrawNo.'","payee_type":"ALIPAY_LOGONID","payee_account":"'.$promote['alipay_account'].'","amount":"'.$widthdraw['sum_money'].'","payer_show_name":"","payee_real_name":"","remark":"'.$vo->getDetailData().'"}');
$result = $aop->execute($request); $result = $aop->execute($request);
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response"; $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
$resultCode = $result->$responseNode->code; $resultCode = $result->$responseNode->code;
$remark = date('Y-m-d H:i:s')." 提现单号:".$WidthdrawNo.", 提现"; $remark = date('Y-m-d H:i:s')." 提现单号:".$WidthdrawNo.", 提现";
if(!empty($resultCode)&&$resultCode == 10000){ if(!empty($resultCode)&&$resultCode == 10000){
$data['status'] = 1; $data['status'] = 1;
$data['end_time'] = time(); $data['end_time'] = time();
$data['widthdraw_number'] = $WidthdrawNo; $data['widthdraw_number'] = $WidthdrawNo;
$data['tx_account'] = $promote['alipay_account']; $data['tx_account'] = $promote['alipay_account'];
$data['respond'] = $remark."成功<br/>".$widthdraw['respond']; $data['respond'] = $remark."成功<br/>".$widthdraw['respond'];
M('withdraw', 'tab_')->where($map)->save($data); M('withdraw', 'tab_')->where($map)->save($data);
$se_data['ti_status']=1; $se_data['ti_status']=1;
M('settlement','tab_')->where($map)->save($se_data); M('settlement','tab_')->where($map)->save($se_data);
return "10000";//提现成功 return "10000";//提现成功
} else { } else {
$msg = $result->$responseNode->sub_msg; $msg = $result->$responseNode->sub_msg;
$data['respond'] = $remark."失败:".$msg."<br/>".$widthdraw['respond']; $data['respond'] = $remark."失败:".$msg."<br/>".$widthdraw['respond'];
M('withdraw', 'tab_')->where($map)->save($data); M('withdraw', 'tab_')->where($map)->save($data);
return $msg; return $msg;
} }
break; break;
break; break;
} }
} }
/** /**
* 商品订单表添加数据 * 商品订单表添加数据
* @param PayVo $vo * @param PayVo $vo
* @author 鹿文学 * @author 鹿文学
*/ */
private function add_order(Pay\PayVo $vo) { private function add_order(Pay\PayVo $vo) {
$order=M('order','tab_'); $order=M('order','tab_');
$da = $order->where(['merchandise_id'=>$vo->getParam(),'buyer_id'=>$vo->getBuyerId()])->find(); $da = $order->where(['merchandise_id'=>$vo->getParam(),'buyer_id'=>$vo->getBuyerId()])->find();
if(is_array($da)) { if(is_array($da)) {
if($da['pay_status']==1) {return false;} if($da['pay_status']==1) {return false;}
$vo->setOrderNo($da['order_number']); $vo->setOrderNo($da['order_number']);
return $da['id']; return $da['id'];
}
$order_data['order_number']=$vo->getOrderNo();
$order_data['buyer_id']=$vo->getBuyerId();
$order_data['buyer_account']=$vo->getBuyerAccount();
$order_data['seller_id']=$vo->getSellerId();
$order_data['seller_account']=$vo->getSellerAccount();
$order_data['seller_account']=$vo->getSellerAccount();
$order_data['order_small_id']=$vo->getSmallId();
$order_data['order_small_account']=$vo->getSmallAccount();
$order_data['merchandise_id']=$vo->getParam();
$order_data['order_price']=$vo->getFee();
$order_data['poundage']=$vo->getPoundage();
$order_data['real_money']=$vo->getMoney();
$order_data['pay_way'] = $vo->getPayWay();
$order_data['order_time'] = NOW_TIME;
$order_data['pay_status'] = 0;
$order_data['game_id'] = $vo->getGameId();
$result = $order->add($order_data);
return $result;
} }
$order_data['order_number']=$vo->getOrderNo();
$order_data['buyer_id']=$vo->getBuyerId();
$order_data['buyer_account']=$vo->getBuyerAccount();
$order_data['seller_id']=$vo->getSellerId();
$order_data['seller_account']=$vo->getSellerAccount();
$order_data['seller_account']=$vo->getSellerAccount();
$order_data['order_small_id']=$vo->getSmallId();
$order_data['order_small_account']=$vo->getSmallAccount();
$order_data['merchandise_id']=$vo->getParam();
$order_data['order_price']=$vo->getFee();
$order_data['poundage']=$vo->getPoundage();
$order_data['real_money']=$vo->getMoney();
$order_data['pay_way'] = $vo->getPayWay();
$order_data['order_time'] = NOW_TIME;
$order_data['pay_status'] = 0;
$order_data['game_id'] = $vo->getGameId();
$result = $order->add($order_data);
return $result;
}
public function getMarketAdminId($promoteId) public function getMarketAdminId($promoteId)
{ {
$promote = M('promote', 'tab_')->field(['id', 'chain', 'level', 'admin_id'])->where(['id' => $promoteId])->find(); $promote = M('promote', 'tab_')->field(['id', 'chain', 'level', 'admin_id'])->where(['id' => $promoteId])->find();
@ -341,11 +334,11 @@ class Pay
} }
return $marketAdminId; return $marketAdminId;
} }
/** /**
*消费表添加数据 *消费表添加数据
*/ */
private function add_spend(Pay\PayVo $vo, $param=array(), $isKBCPartner = false) private function add_spend(Pay\PayVo $vo, $param=array(), $payConf = array())
{ {
$spend = M("spend", "tab_"); $spend = M("spend", "tab_");
$spend_data['user_id'] = $vo->getUserId(); $spend_data['user_id'] = $vo->getUserId();
@ -378,25 +371,27 @@ class Pay
$spend_data['spend_ip'] = get_client_ip(); $spend_data['spend_ip'] = get_client_ip();
$spend_data['sdk_version'] = $vo->getSdkVersion(); $spend_data['sdk_version'] = $vo->getSdkVersion();
$spend_data['market_admin_id'] = $this->getMarketAdminId($vo->getPromoteId()); $spend_data['market_admin_id'] = $this->getMarketAdminId($vo->getPromoteId());
if ($isKBCPartner) { /* if ($isKBCPartner) {
$spend_data['partner_type'] = 1; $spend_data['partner_type'] = 1;
} } */
if($vo->getSmallId() != $vo->getUserId()) { if($vo->getSmallId() != $vo->getUserId()) {
$spend_data['small_id'] = $vo->getSmallId(); $spend_data['small_id'] = $vo->getSmallId();
$spend_data['small_account'] = $vo->getSmallAccount(); $spend_data['small_account'] = $vo->getSmallAccount();
} }
if ($param) { if ($param) {
$spend_data['deduction_amount'] = $param['deduction_amount']; $spend_data['deduction_amount'] = $param['deduction_amount'];
$spend_data['discount_amount'] = $param['discount_amount']; $spend_data['discount_amount'] = $param['discount_amount'];
} }
$spend_data['merchant_id'] = isset($payConf['merchant_id']) ? $payConf['merchant_id'] : 0;
$spend_data['merchant_way'] = isset($payConf['merchant_way']) ? $payConf['merchant_way'] : 0;
$result = $spend->add($spend_data); $result = $spend->add($spend_data);
return $result; return $result;
} }
/** /**
*平台币充值记录 *平台币充值记录
*/ */
private function add_deposit(Pay\PayVo $vo, $isKBCPartner = false) private function add_deposit(Pay\PayVo $vo, $param=array(), $payConf=array())
{ {
if (!empty($vo->getUc())) { if (!empty($vo->getUc())) {
$uc = new Ucservice(); $uc = new Ucservice();
@ -423,14 +418,17 @@ class Pay
$deposit_data['create_time'] = NOW_TIME; $deposit_data['create_time'] = NOW_TIME;
$deposit_data['sdk_version'] = $vo->getSdkVersion(); $deposit_data['sdk_version'] = $vo->getSdkVersion();
$deposit_data['market_admin_id'] = $this->getMarketAdminId($vo->getPromoteId()); $deposit_data['market_admin_id'] = $this->getMarketAdminId($vo->getPromoteId());
if ($isKBCPartner) { /* if ($isKBCPartner) {
$deposit_data['partner_type'] = 1; $deposit_data['partner_type'] = 1;
} } */
$deposit_data['merchant_id'] = isset($payConf['merchant_id']) ? $payConf['merchant_id'] : 0;
$deposit_data['merchant_way'] = isset($payConf['merchant_way']) ? $payConf['merchant_way'] : 0;
$result = $deposit->add($deposit_data); $result = $deposit->add($deposit_data);
return $result; return $result;
} }
} }
/** /**
*添加代充记录 支付宝 /威富通 *添加代充记录 支付宝 /威富通
*/ */
@ -459,7 +457,7 @@ class Pay
$result = $agent->add(); $result = $agent->add();
return $result; return $result;
} }
/** /**
* @函数或方法说明 * @函数或方法说明
* @支付宝查询订单信息 * @支付宝查询订单信息
@ -484,17 +482,17 @@ class Pay
$data['trade_no'] = $order_no; $data['trade_no'] = $order_no;
$request->setBizContent(json_encode($data)); $request->setBizContent(json_encode($data));
$result = $aop->execute ($request); $result = $aop->execute ($request);
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response"; $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
$resultCode = $result->$responseNode->code; $resultCode = $result->$responseNode->code;
if(!empty($resultCode)&&$resultCode == 10000){ if(!empty($resultCode)&&$resultCode == 10000){
return $result->$responseNode->total_amount; return $result->$responseNode->total_amount;
} else { } else {
return $result->$responseNode->sub_msg; return $result->$responseNode->sub_msg;
} }
} }
/** /**
* 绑币充值记录 * 绑币充值记录
@ -527,8 +525,8 @@ class Pay
$result = $agent->add(); $result = $agent->add();
return $result; return $result;
} }
private function add_balance(Pay\PayVo $vo) { private function add_balance(Pay\PayVo $vo) {
$balance = M("balance", "tab_"); $balance = M("balance", "tab_");
$balance_data['order_number'] = ""; $balance_data['order_number'] = "";
$balance_data['pay_order_number'] = $vo->getOrderNo(); $balance_data['pay_order_number'] = $vo->getOrderNo();
@ -545,7 +543,7 @@ class Pay
$result = $balance->add(); $result = $balance->add();
return $result; return $result;
} }
/** /**
* 设置支付驱动 * 设置支付驱动
* @param string $class 驱动类名称 * @param string $class 驱动类名称
@ -557,7 +555,7 @@ class Pay
E("不存在支付驱动:{$class}"); E("不存在支付驱动:{$class}");
} }
} }
public function __call($method, $arguments) public function __call($method, $arguments)
{ {
if (method_exists($this, $method)) { if (method_exists($this, $method)) {
@ -566,5 +564,5 @@ class Pay
return call_user_func_array(array(&$this->payer, $method), $arguments); return call_user_func_array(array(&$this->payer, $method), $arguments);
} }
} }
} }

Loading…
Cancel
Save