|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yansongda\Pay\Config; |
|
6
|
|
|
|
|
7
|
|
|
use Yansongda\Pay\Pay; |
|
8
|
|
|
|
|
9
|
|
|
class WechatConfig implements ConfigInterface |
|
10
|
|
|
{ |
|
11
|
|
|
public function __construct( |
|
12
|
|
|
public string $mch_id, |
|
13
|
|
|
public string $mch_secret_key, |
|
14
|
|
|
public string $mch_secret_cert, |
|
15
|
|
|
public string $mch_public_cert_path, |
|
16
|
|
|
public string $notify_url, |
|
17
|
|
|
public string $mch_secret_key_v2 = '', |
|
18
|
|
|
public string $mp_app_id = '', |
|
19
|
|
|
public string $mini_app_id = '', |
|
20
|
|
|
public string $app_id = '', |
|
21
|
|
|
public string $sub_mp_app_id = '', |
|
22
|
|
|
public string $sub_app_id = '', |
|
23
|
|
|
public string $sub_mini_app_id = '', |
|
24
|
|
|
public string $sub_mch_id = '', |
|
25
|
|
|
public array $wechat_public_cert_path = [], |
|
26
|
|
|
public int $mode = Pay::MODE_NORMAL, |
|
27
|
|
|
) { |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function toArray(): array |
|
31
|
|
|
{ |
|
32
|
|
|
return [ |
|
33
|
|
|
'mch_id' => $this->mch_id, |
|
34
|
|
|
'mch_secret_key_v2' => $this->mch_secret_key_v2, |
|
35
|
|
|
'mch_secret_key' => $this->mch_secret_key, |
|
36
|
|
|
'mch_secret_cert' => $this->mch_secret_cert, |
|
37
|
|
|
'mch_public_cert_path' => $this->mch_public_cert_path, |
|
38
|
|
|
'notify_url' => $this->notify_url, |
|
39
|
|
|
'mp_app_id' => $this->mp_app_id, |
|
40
|
|
|
'mini_app_id' => $this->mini_app_id, |
|
41
|
|
|
'app_id' => $this->app_id, |
|
42
|
|
|
'sub_mp_app_id' => $this->sub_mp_app_id, |
|
43
|
|
|
'sub_app_id' => $this->sub_app_id, |
|
44
|
|
|
'sub_mini_app_id' => $this->sub_mini_app_id, |
|
45
|
|
|
'sub_mch_id' => $this->sub_mch_id, |
|
46
|
|
|
'wechat_public_cert_path' => $this->wechat_public_cert_path, |
|
47
|
|
|
'mode' => $this->mode, |
|
48
|
|
|
]; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public static function fromArray(array $config): self |
|
52
|
|
|
{ |
|
53
|
|
|
return new self( |
|
54
|
|
|
mch_id: $config['mch_id'] ?? '', |
|
55
|
|
|
mch_secret_key: $config['mch_secret_key'] ?? '', |
|
56
|
|
|
mch_secret_cert: $config['mch_secret_cert'] ?? '', |
|
57
|
|
|
mch_public_cert_path: $config['mch_public_cert_path'] ?? '', |
|
58
|
|
|
notify_url: $config['notify_url'] ?? '', |
|
59
|
|
|
mch_secret_key_v2: $config['mch_secret_key_v2'] ?? '', |
|
60
|
|
|
mp_app_id: $config['mp_app_id'] ?? '', |
|
61
|
|
|
mini_app_id: $config['mini_app_id'] ?? '', |
|
62
|
|
|
app_id: $config['app_id'] ?? '', |
|
63
|
|
|
sub_mp_app_id: $config['sub_mp_app_id'] ?? '', |
|
64
|
|
|
sub_app_id: $config['sub_app_id'] ?? '', |
|
65
|
|
|
sub_mini_app_id: $config['sub_mini_app_id'] ?? '', |
|
66
|
|
|
sub_mch_id: $config['sub_mch_id'] ?? '', |
|
67
|
|
|
wechat_public_cert_path: $config['wechat_public_cert_path'] ?? [], |
|
68
|
|
|
mode: $config['mode'] ?? Pay::MODE_NORMAL, |
|
69
|
|
|
); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|