-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.php
83 lines (79 loc) · 2.47 KB
/
example.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
78
79
80
81
82
83
<?php
//微信支付
//初始化
include __DIR__ . '/lib/WechatPay.php';
$WechatPay = new WechatPay([
'app_id' => '', //绑定微信支付的公众号AppID
'app_secret' => '', //绑定微信支付的公众号AppSecret
'mch_id' => '', //微信支付商户号
'key' => '', //微信支付商户密钥
'cert_serial_number' => '', //微信支付证书序列号,仅调用异步通知方法时可留空
'cert_private_key' => '' //微信支付证书私钥,仅调用异步通知方法时可留空
]);
$wechatPayParam = [
'out_trade_no' => time() . rand(1000, 9999),
'description' => '测试商品',
'notify_url' => 'https://www.abc.com',
'total' => 1
];
//扫码支付
echo '<img src="qrcode.php?data=' . $WechatPay->native($wechatPayParam) . '" alt="二维码">';
//jsapi支付,调用时会跳转页面获取用户openid
echo "<script type=\"text/javascript\" src=\"https://res.wx.qq.com/open/js/jweixin-1.6.0.js\"></script>
<script type=\"text/javascript\">
function jsApiCall () {
WeixinJSBridge.invoke(
'getBrandWCPayRequest',
" . $WechatPay->jsapi($wechatPayParam) . ",
function () {
// TODO
}
);
}
if (typeof WeixinJSBridge === 'undefined') {
if (document.addEventListener) {
document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
} else if (document.attachEvent) {
document.attachEvent('WeixinJSBridgeReady', jsApiCall);
document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
}
} else {
jsApiCall();
}
</script>";
//h5支付,调用的域名须是商户平台设置的h5域名
echo '<script type="text/javascript">window.location.href="' . $this->wechatPay()->h5($wechatPayParam) . '&redirect_url=' . urlencode('https://www.abc.com') . '";</script>';
//异步通知
$notify = $WechatPay->notify();
if ($notify) {
print_r($notify);
echo '';
}
//支付宝
//初始化
include __DIR__ . '/lib/Alipay.php';
$Alipay = new Alipay([
'app_id' => '', //APPID
'merchant_private_key' => '', //应用私钥
'public_key' => '', //公钥
'method' => 'page' //page代表电脑支付,wap代表手机支付
]);
//支付
echo $Alipay->pay(
[
'body' => '测试商品',
'subject' => '测试商品',
'out_trade_no' => time() . rand(1000, 9999),
'total_amount' => 1
],
[
'return' => 'https://www.abc.com',
'notify' => 'https://www.abc.com'
]
);
//异步通知
if ($Alipay->check($_POST)) {
echo 'success';
} else {
echo 'fail';
}