1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yansongda\Pay; |
6
|
|
|
|
7
|
|
|
use Closure; |
8
|
|
|
use Psr\Container\ContainerInterface; |
9
|
|
|
use Yansongda\Artful\Artful; |
10
|
|
|
use Yansongda\Artful\Exception\ContainerException; |
11
|
|
|
use Yansongda\Artful\Exception\ServiceNotFoundException; |
12
|
|
|
use Yansongda\Pay\Provider\Alipay; |
13
|
|
|
use Yansongda\Pay\Provider\Douyin; |
14
|
|
|
use Yansongda\Pay\Provider\Jsb; |
15
|
|
|
use Yansongda\Pay\Provider\Unipay; |
16
|
|
|
use Yansongda\Pay\Provider\Wechat; |
17
|
|
|
use Yansongda\Pay\Service\AlipayServiceProvider; |
18
|
|
|
use Yansongda\Pay\Service\DouyinServiceProvider; |
19
|
|
|
use Yansongda\Pay\Service\JsbServiceProvider; |
20
|
|
|
use Yansongda\Pay\Service\UnipayServiceProvider; |
21
|
|
|
use Yansongda\Pay\Service\WechatServiceProvider; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @method static Alipay alipay(array $config = [], $container = null) |
25
|
|
|
* @method static Wechat wechat(array $config = [], $container = null) |
26
|
|
|
* @method static Unipay unipay(array $config = [], $container = null) |
27
|
|
|
* @method static Jsb jsb(array $config = [], $container = null) |
28
|
|
|
* @method static Douyin douyin(array $config = [], $container = null) |
29
|
|
|
*/ |
30
|
|
|
class Pay |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* 正常模式. |
34
|
|
|
*/ |
35
|
|
|
public const MODE_NORMAL = 0; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* 沙箱模式. |
39
|
|
|
*/ |
40
|
|
|
public const MODE_SANDBOX = 1; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* 服务商模式. |
44
|
|
|
*/ |
45
|
|
|
public const MODE_SERVICE = 2; |
46
|
|
|
|
47
|
|
|
protected static array $providers = [ |
48
|
|
|
AlipayServiceProvider::class, |
49
|
|
|
WechatServiceProvider::class, |
50
|
|
|
UnipayServiceProvider::class, |
51
|
|
|
JsbServiceProvider::class, |
52
|
|
|
DouyinServiceProvider::class, |
53
|
|
|
]; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @throws ContainerException |
57
|
|
|
* @throws ServiceNotFoundException |
58
|
|
|
*/ |
59
|
|
|
public static function __callStatic(string $service, array $config = []) |
60
|
|
|
{ |
61
|
|
|
if (!empty($config)) { |
62
|
|
|
self::config(...$config); |
|
|
|
|
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
return Artful::get($service); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @throws ContainerException |
70
|
|
|
*/ |
71
|
|
|
public static function config(array $config = [], null|Closure|ContainerInterface $container = null): bool |
72
|
|
|
{ |
73
|
|
|
$result = Artful::config($config, $container); |
74
|
|
|
|
75
|
|
|
foreach (self::$providers as $provider) { |
76
|
|
|
Artful::load($provider); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
return $result; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @throws ContainerException |
84
|
|
|
*/ |
85
|
|
|
public static function set(string $name, mixed $value): void |
86
|
|
|
{ |
87
|
|
|
Artful::set($name, $value); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @throws ContainerException |
92
|
|
|
* @throws ServiceNotFoundException |
93
|
|
|
*/ |
94
|
|
|
public static function get(string $service): mixed |
95
|
|
|
{ |
96
|
|
|
return Artful::get($service); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public static function setContainer(null|Closure|ContainerInterface $container): void |
100
|
|
|
{ |
101
|
|
|
Artful::setContainer($container); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public static function clear(): void |
105
|
|
|
{ |
106
|
|
|
Artful::clear(); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|