1
|
|
|
<?php |
2
|
|
|
namespace tinymeng\WeWorkFinanceSDK; |
3
|
|
|
use tinymeng\WeWorkFinanceSDK\Contract\ProviderInterface; |
4
|
|
|
use tinymeng\WeWorkFinanceSDK\Exception\InvalidArgumentException; |
5
|
|
|
use tinymeng\WeWorkFinanceSDK\Provider\FFIProvider; |
6
|
|
|
use tinymeng\WeWorkFinanceSDK\Provider\PHPExtProvider; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class WxFinanceSDK. |
10
|
|
|
* @author: JiaMeng <[email protected]> |
11
|
|
|
* @method array getConfig() 获取微信配置 |
12
|
|
|
* @method string getChatData(int $seq, int $limit) 获取会话记录数据(加密) |
13
|
|
|
* @method string decryptData(string $randomKey, string $encryptStr) 解密数据 |
14
|
|
|
* @method \SplFileInfo getMediaData(string $sdkFileId, string $msgType) 获取媒体资源 |
15
|
|
|
* @method array getDecryptChatData(int $seq, int $limit) 获取会话记录数据(解密) |
16
|
|
|
* @method Object getDownloadMediaData(array $object, string $msgType) 下载媒体资源 |
17
|
|
|
* @method array isMedia(string $msgType) 获取是否是媒体资源 |
18
|
|
|
*/ |
19
|
|
|
class WxFinanceSDK |
20
|
|
|
{ |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var array |
24
|
|
|
*/ |
25
|
|
|
protected $config; |
26
|
|
|
protected $wxConfig; |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
public function __construct(array $config = [],array $wxConfig = []) |
30
|
|
|
{ |
31
|
|
|
$default = [ |
32
|
|
|
'default' => 'php-ext', |
33
|
|
|
'providers' => [ |
34
|
|
|
'php-ext' => [ |
35
|
|
|
'driver' => PHPExtProvider::class, |
36
|
|
|
], |
37
|
|
|
'php-ffi' => [ |
38
|
|
|
'driver' => FFIProvider::class, |
39
|
|
|
], |
40
|
|
|
], |
41
|
|
|
]; |
42
|
|
|
$this->config = empty($config) ? $default : array_merge($default, $config); |
43
|
|
|
$this->wxConfig = $wxConfig; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
public function __call($name, $arguments) |
48
|
|
|
{ |
49
|
|
|
$provider = $this->provider($this->config['default']); |
50
|
|
|
|
51
|
|
|
if (method_exists($provider, $name)) { |
52
|
|
|
return call_user_func_array([$provider, $name], $arguments); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
throw new InvalidArgumentException('WxFinanceSDK::Method not defined. method:' . $name); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public static function init(array $wxConfig = [], array $driverConfig = []): self |
59
|
|
|
{ |
60
|
|
|
return new self($driverConfig, $wxConfig); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param $providerName ... |
65
|
|
|
* @throws InvalidArgumentException ... |
66
|
|
|
* @return ProviderInterface ... |
67
|
|
|
*/ |
68
|
|
|
public function provider($providerName): ProviderInterface |
69
|
|
|
{ |
70
|
|
|
if (! $this->config['providers'] || ! $this->config['providers'][$providerName]) { |
71
|
|
|
throw new InvalidArgumentException("file configurations are missing {$providerName} options"); |
72
|
|
|
} |
73
|
|
|
return (new $this->config['providers'][$providerName]['driver']())->setConfig($this->wxConfig); |
74
|
|
|
} |
75
|
|
|
} |