header("Content-Type:text/html;charset=utf-8");
date_default_timezone_set(‘PRC‘);
require_once ‘config.php‘;
require_once WX_CLASS;
require_once ‘api/‘.UGL_CLASS;
require_once ‘api/‘.SESSION_CLASS;
require_once ‘api/libs/WxPay.Api.php‘;
require_once ‘api/libs/WxPay.JsApiPay.php‘;
error_reporting(0);
$get = $_GET;
$strArr = explode(‘x‘,$get[‘n‘]);
// http://meng.qiankk.com/demo/getOpenid.php?n=99x1x29191xyzd 贷款网站的支付格式
$type = (int)$strArr[0];
$num = (int)$strArr[1];
$wx=new WX_LC(ID,WX_APPID,WX_SECRET);
$code=$_GET[‘code‘];
if($code==‘‘){
$wx->getCode(‘snsapi_base‘);
exit(‘code empty‘);
}else{
$data=$wx->getOpenid($code);
if($data->errcode == 40029 || $data->errcode == 40163) {
$wx->getCode();
return;
}
if($type != 99){
$s = new S(ID);
$user = $s->getUser();
// echo ‘<pre>‘;
// print_r($user);
// die;
$user->openid = $data->openid;
$s->setUser($user);
}else {
$user = new stdClass();
$user->id = mt_rand(1000,99999);
$user->openid = $data->openid;
}
}
$feeArr1 = array(
array(‘day‘=>30,‘money‘=>48000),
array(‘day‘=>1,‘money‘=>3300),
array(‘day‘=>30,‘money‘=>48000),
array(‘day‘=>90,‘money‘=>99900),
array(‘day‘=>180,‘money‘=>180000),
array(‘day‘=>365,‘money‘=>320000)
);
$feeArr2 = array(
array(‘day‘=>30,‘money‘=>12000),
array(‘day‘=>1,‘money‘=>2300),
array(‘day‘=>30,‘money‘=>15000),
array(‘day‘=>90,‘money‘=>30000),
array(‘day‘=>180,‘money‘=>55000),
array(‘day‘=>365,‘money‘=>98000)
);
if($user && $user->id>0) {
$uid = $user->id;
} else {
exit(json_encode(array(‘result‘=>0, ‘msg‘=>‘user error!‘)));
}
if($type == 99){ //如果是贷款网站 重点在这里,,,,如果是从外站跳转过来的支付,,,,这里重新定义一些支付参数,发起微信支付,,,在回调页面,也做同样的判断就可以了
$order = (int)$strArr[2];
$dai = $strArr[3];//来源
$orderId = $dai.‘_‘.date(‘ymdHis‘).‘_‘.$order;
$fee = $num * 1;
$pid = $orderId;
pay($orderId,$fee,$user,$uid,$order ,$dai);
die;
}
$orderId = WxPayConfig::MCHID.date("YmdHis").rand(10, 99);
$now = time();
$arr=array(
‘p_id‘=>null,
‘p_uid‘=>$uid,
‘p_type‘=>$type,
‘p_num‘=>$num,
‘p_trade_no‘=>$orderId,
‘p_transaction_id‘=>‘‘,
‘p_buy‘=>‘‘,
‘p_create‘=>$now,
‘p_update‘=>$now,
‘p_more‘=>‘‘
);
$pid = $ugl->insert(DB_PREFIX.‘pay_log‘,$arr);
if($pid>0) {
if($type==1) {
$fee = $feeArr1[$num][‘money‘];
} else {
$fee = $feeArr2[$num][‘money‘];
}
//$fee = 10000;//($fee/1000)<0.01?0.1:($fee/1000);
pay($orderId,$fee,$user,$uid,$pid );
}else{
exit(‘pid error‘);
}
function pay($orderId,$fee,$user,$uid = 0,$pid = 0,$dai = ‘‘){
$ugl = new UGL_v2();
$tools = new JsApiPay();
$input = new WxPayUnifiedOrder();
$input->SetBody("12");
$input->SetAttach("123");
$input->SetOut_trade_no($orderId);
$input->SetTotal_fee($fee);
$input->SetTime_start(date("YmdHis"));
$input->SetTime_expire(date("YmdHis", time() + 600));
$input->SetGoods_tag("test");
$input->SetNotify_url(SHAREURL."demo/api/notify_b.php");
$input->SetTrade_type("JSAPI");
$input->SetOpenid($user->openid);
$order = WxPayApi::unifiedOrder($input);
$jsApiParameters = $tools->GetJsApiParameters($order);
$str = json_encode($order);
$ugl->addLog($uid,‘201‘,$str,‘下单‘.$pid);
$ec = "var jsApiParameters=$jsApiParameters; var myPid=$pid;";
echo "<script>$ec</script>";
include_once ‘callpay_b.html‘;
}