chengkun
2025-04-30 6ab292fb7415be124651e312ec4f21c594568f17
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
 
//---------------------------------------------------------
//财付通即时到帐支付请求示例,商户按照此文档进行开发即可
//---------------------------------------------------------
error_reporting(0);
 
require_once ("classes/PayRequestHandler.class.php");
 
require_once(dirname(dirname(dirname(__FILE__)))."/data/api/tenpay/tenpay_data.php");
require_once(dirname(dirname(dirname(__FILE__)))."/config/db.config.php");
require_once(dirname(dirname(dirname(__FILE__)))."/config/db.safety.php");
if (substr(PHP_VERSION, 0, 1) == '7') {
    require_once(dirname(dirname(dirname(__FILE__)))."/app/include/mysqli.class.php");
}else{
    require_once(dirname(dirname(dirname(__FILE__)))."/app/include/mysql.class.php");
}
require_once(dirname(dirname(dirname(__FILE__)))."/data/plus/config.php");
 
$db = new mysql($db_config['dbhost'], $db_config['dbuser'], $db_config['dbpass'], $db_config['dbname'], ALL_PS, $db_config['charset']);
if(!is_numeric($_POST['dingdan']))
{
    die;
}
 
$_COOKIE['uid']=(int)$_COOKIE['uid'];
$_POST['is_invoice']=(int)$_POST['is_invoice'];
$_POST['coupon']=(int)$_POST['coupon'];
$invoice_title=trim($_POST['invoice_title']);
$member_sql=$db->query("SELECT * FROM `".$db_config["def"]."member` WHERE `uid`='".$_COOKIE['uid']."' limit 1");
$member=$db->fetch_array($member_sql);
if($member['usertype'] != $_COOKIE['usertype']||md5($member['username'].$member['password'].$member['salt'])!=$_COOKIE['shell']){
    echo '登录信息验证错误,请重新登录!';die;
}
$sql=$db->query("select * from `".$db_config["def"]."company_order` where `order_id`='$_POST[dingdan]' AND `order_price`>=0");
$row=$db->fetch_array($sql);
if(!$row['uid'] || $row['uid']!=$_COOKIE['uid'])
{
    die;
}
if($_POST['coupon'] && $row['coupon']==""){
    $where="`uid`='".$_COOKIE['uid']."' and `id`='".$_POST['coupon']."' and `validity`>'".time()."'  and `status`='1' and `coupon_scope`<='".$row['order_price']."'";
    $cousql=$db->query("select * from `".$db_config["def"]."coupon_list` where ".$where);
    $coupon=$db->fetch_array($cousql);
    $row['order_price']=sprintf("%.2f", $row['order_price']-$coupon['coupon_amount']);
    if($row['order_price']<0){$row['order_price']='0.01';}
    if($coupon['id']&&$row['coupon']<'1'){
        $db->query("update `".$db_config[def]."coupon_list` set `status`='2',`xf_time`='".time()."' where `id`='".$coupon['id']."'");
        $db->query("update `".$db_config[def]."company_order` set `coupon`='".$_POST['coupon']."',`order_price`='".$row['order_price']."' where `id`='".$row['id']."'");
    }
}
 
 
if($invoice_title){
    $up_order=$db->query("update `".$db_config["def"]."company_order` set `is_invoice`='".$_POST['is_invoice']."',`order_bank`='bank' where `order_id`='".$row['order_id']."'");
    $db->fetch_array($up_order);//更改订单发票信息
}
/* 商户号 */
$bargainor_id = $tenpaydata[sy_tenpayid];
 
/* 密钥 */
$key = $tenpaydata[sy_tenpaycode];
 
/* 返回处理地址 */
$return_url = $tenpaydata[sy_weburl]."/api/tenpay/return_url.php";
 
//date_default_timezone_set(PRC);
$strDate = date("Ymd");
$strTime = date("His");
 
//4位随机数
$randNum = rand(1000, 9999);
 
$attach=$_POST[pay_type];
 
//10位序列号,可以自行调整。
$strReq = $strTime . $randNum;
 
/* 商家订单号,长度若超过32位,取前32位。财付通只记录商家订单号,不保证唯一。 */
$sp_billno = $_POST[dingdan];
 
/* 财付通交易单号,规则为:10位商户号+8位时间(YYYYmmdd)+10位流水号 */
$transaction_id =trim($bargainor_id.$strDate.$strReq);
 
/* 商品价格(包含运费),以分为单位 */
$total_fee = $row[order_price]*100;
//$total_fee = 1;
 
/* 商品名称 */
$desc = "订单号:" . $transaction_id;
 
/* 创建支付请求对象 */
$reqHandler = new PayRequestHandler();
$reqHandler->init();
$reqHandler->setKey($key);
//----------------------------------------
//设置支付参数
//----------------------------------------
$reqHandler->setParameter("bargainor_id", $bargainor_id);            //商户号
$reqHandler->setParameter("transaction_id", $transaction_id);        //财付通交易单号
$reqHandler->setParameter("sp_billno", $sp_billno);                    //商户订单号
$reqHandler->setParameter("total_fee", $total_fee);                    //商品总金额,以分为单位
$reqHandler->setParameter("return_url", $return_url);                //返回处理地址
$reqHandler->setParameter("desc", "订单号:" . $transaction_id);        //商品名称
$reqHandler->setParameter("attach", $attach);                        //自定义参数
//用户ip,测试环境时不要加这个ip参数,正式环境再加此参数
//$reqHandler->setParameter("spbill_create_ip", $_SERVER['REMOTE_ADDR']);
 
 
 
//请求的URL
$reqUrl = $reqHandler->getRequestURL();
 
 
//debug信息
//$debugInfo = $reqHandler->getDebugInfo();
 
//echo "<br/>" . $reqUrl . "<br/>";
//echo "<br/>" . $debugInfo . "<br/>";
 
//重定向到财付通支付
//$reqHandler->doSend();
Header("Location:$reqUrl");
?>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>财付通即时到帐程序</title>
</head>
<body>
<script>//location.href='<?php echo $reqUrl;?>';</script>
</body>
</html>