1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | namespace tinymeng\WeWorkFinanceSDK\Provider; |
||
5 | |||
6 | use tinymeng\WeWorkFinanceSDK\Contract\ProviderInterface; |
||
7 | use tinymeng\WeWorkFinanceSDK\Exception\FinanceSDKException; |
||
8 | use tinymeng\WeWorkFinanceSDK\Exception\InvalidArgumentException; |
||
9 | |||
10 | /** |
||
11 | * PHPExtProvider |
||
12 | * @author: TinyMeng <[email protected]> |
||
13 | */ |
||
14 | class PHPExtProvider extends AbstractProvider |
||
15 | { |
||
16 | /** |
||
17 | * @var array |
||
18 | */ |
||
19 | protected $config = []; |
||
20 | |||
21 | /** |
||
22 | * @var \WxworkFinanceSdk |
||
0 ignored issues
–
show
|
|||
23 | */ |
||
24 | private $financeSdk; |
||
25 | |||
26 | /** |
||
27 | * {@inheritdoc} |
||
28 | */ |
||
29 | public function setConfig(array $config): ProviderInterface |
||
30 | { |
||
31 | $this->config = array_merge($this->config, $config); |
||
32 | $this->setFinanceSDK(); |
||
33 | return $this; |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * {@inheritdoc} |
||
38 | */ |
||
39 | public function getConfig(): array |
||
40 | { |
||
41 | return $this->config; |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * {@inheritdoc} |
||
46 | */ |
||
47 | public function getChatData(int $seq, int $limit): string |
||
48 | { |
||
49 | return $this->financeSdk->getChatData($seq, $limit); |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * {@inheritdoc} |
||
54 | */ |
||
55 | public function decryptData(string $randomKey, string $encryptStr): string |
||
56 | { |
||
57 | return $this->financeSdk->decryptData($randomKey, $encryptStr); |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * {@inheritdoc} |
||
62 | * @throws FinanceSDKException |
||
63 | */ |
||
64 | public function getMediaData(string $sdkFileId, string $path): \SplFileInfo |
||
65 | { |
||
66 | try { |
||
67 | $this->financeSdk->downloadMedia($sdkFileId, $path); |
||
68 | } catch (\WxworkFinanceSdkExcption $e) { |
||
0 ignored issues
–
show
The type
WxworkFinanceSdkExcption was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
69 | throw new FinanceSDKException('获取文件失败' . $e->getMessage(), $e->getCode()); |
||
70 | } |
||
71 | return new \SplFileInfo($path); |
||
72 | } |
||
73 | |||
74 | |||
75 | /** |
||
76 | * 获取php-ext-sdk. |
||
77 | * @param array $config ... |
||
78 | */ |
||
79 | protected function setFinanceSDK(array $config = []): void |
||
80 | { |
||
81 | if (! extension_loaded('wxwork_finance_sdk')) { |
||
82 | throw new FinanceSDKException('缺少ext-wxwork_finance_sdk扩展'); |
||
83 | } |
||
84 | |||
85 | $this->config = array_merge($this->config, $config); |
||
86 | if (! isset($this->config['corpid'])) { |
||
87 | throw new InvalidArgumentException('缺少配置:corpid'); |
||
88 | } |
||
89 | if (! isset($this->config['secret'])) { |
||
90 | throw new InvalidArgumentException('缺少配置:secret'); |
||
91 | } |
||
92 | $options = ['timeout' => 30]; |
||
93 | isset($this->config['proxy']) && $options['proxy_host'] = $this->config['proxy']; |
||
94 | isset($this->config['passwd']) && $options['proxy_password'] = $this->config['passwd']; |
||
95 | isset($this->config['timeout']) && $options['timeout'] = $this->config['timeout']; |
||
96 | |||
97 | $this->financeSdk = new \WxworkFinanceSdk( |
||
98 | $this->config['corpid'], |
||
99 | $this->config['secret'], |
||
100 | $options |
||
101 | ); |
||
102 | } |
||
103 | } |
||
104 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths