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