-
Notifications
You must be signed in to change notification settings - Fork 0
/
recharge.php
77 lines (61 loc) · 2.35 KB
/
recharge.php
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
<?php
/**
* 首页
* Created by PhpStorm.
* User: apple
* Date: 15/8/14
* Time: 下午10:11
*/
include 'library/init.inc.php';
$operation = 'wechat|alipay';
$opera = check_action($operation, getPOST('opera'));
//支付方式变更时生成支付代码
if('wechat' == $opera)
{
$amount = getPOST('amount');
$amount = floatval($amount);
$mch_id = '1259544101';//商户编号
$mch_key = 'WinsenCeciliaWrhLtx2015KWANSONCC';//商户API密钥
$response = array('error'=>1, 'msg'=>'');
$_SESSION['payment'] = 'wechat';
if($amount <= 0)
{
$response['msg'] = '充值金额必须大于0';
} else {
$total_fee = $amount;
$recharge_sn = add_recharge($_SESSION['account'], $total_fee);
if($recharge_sn) {
$response['price'] = '¥' . sprintf('%.2f', $total_fee);
$detail = '充值流水号:' . $recharge_sn;
$body = $config['site_name'] . '充值';
$body = $detail;
$out_trade_no = $recharge_sn;
$res = create_prepay($config['appid'], $mch_id, $mch_key, $_SESSION['openid'], $total_fee, $body, $detail, $out_trade_no);
$res = simplexml_load_string($res);
if ($res->prepay_id) {
$response['error'] = 0;
} else {
$response['msg'] = $res->return_code . ',' . $res->return_msg;
}
$nonce_str = get_nonce_str();
$response['nonce_str'] = $nonce_str;
$time_stamp = time();
//最后参与签名的参数有appId, timeStamp, nonceStr, package, signType。
$sign = 'appId=' . $config['appid'] . '&nonceStr=' . $nonce_str . '&package=prepay_id=' . $res->prepay_id . '&signType=MD5&timeStamp=' . $time_stamp . '&key=' . $mch_key;
$sign = md5($sign);
$sign = strtoupper($sign);
$response['timestamp'] = $time_stamp;
$response['sign'] = $sign;
$response['prepay_id'] = "" . $res->prepay_id;
} else {
$response['msg'] = '系统繁忙,请稍后再试';
}
}
echo json_encode($response);
exit;
}
//获取用户信息
$get_user_info = 'select * from '.$db->table('member').' where `account`=\''.$_SESSION['account'].'\'';
$user_info = $db->fetchRow($get_user_info);
assign('user_info', $user_info);
$smarty->display('recharge.phtml');