快速上手
安装
composer require fengkui/pay
1
完善支付配置
微信支付
$wechatConfig = [
'xcxid' => '',
'appid' => '',
'mchid' => '',
'key' => '',
'appsecret' => '',
'sp_appid' => '',
'sp_mchid' => '',
'notify_url' => '',
'redirect_url' => '',
'serial_no' => '',
'cert_client' => './cert/apiclient_cert.pem',
'cert_key' => './cert/apiclient_key.pem',
'public_key' => './cert/public_key.pem',
];
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
支付宝支付
$alipayConfig = [
'app_id' => '',
'public_key' => '',
'private_key' => '',
'notify_url' => '',
'return_url' => '',
'sign_type' => 'RSA2',
'is_sandbox' => false,
];
1
2
3
4
5
6
7
8
9
10
11
百度支付
$baiduConfig = [
'deal_id' => '',
'app_key' => '',
'private_key' => '',
'public_key' => '',
'notify_url' => '',
];
1
2
3
4
5
6
7
8
字节跳动支付
$bytedanceConfig = [
'app_id' => '',
'salt' => '',
'token' => '',
'notify_url' => '',
'thirdparty_id' => '',
];
1
2
3
4
5
6
7
8
使用说明
单独使用
$pay = new \fengkui\Pay\Wechat($wechatConfig);
$pay = new \fengkui\Pay\Alipay($alipayConfig);
$pay = new \fengkui\Pay\Baidu($baiduConfig);
$pay = new \fengkui\Pay\Bytedance($bytedanceConfig);
1
2
3
4
公共使用
<?php
require_once('./vendor/autoload.php');
class Payment
{
protected static $pay = '';
protected static $type = '';
protected static $config = [];
public function _initialize()
{
self::$type = $_GET['type'] ?? 'alipay';
self::config();
}
protected static function config($type='')
{
$type = $type ?: self::$type;
$alipayConfig = [];
if (in_array($type, ['wechat', 'baidu', 'bytedance', 'alipay'])) {
$config = $type . "Config";
self::$config = $config;
} else {
die('当前类型配置不存在');
}
$type && self::$pay =(new \fengkui\Pay())::$type(self::$config);
}
public function pay()
{
$order = [
'body' => 'subject-测试',
'order_sn' => time(),
'total_amount' => 0.01,
];
$result = self::$pay->web($order);
echo $result;
}
}
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