@@ -15,23 +15,23 @@ |
||
15 | 15 | ], |
16 | 16 | ]; |
17 | 17 | |
18 | -$seq = $_GET['seq']??1; |
|
19 | -$limit = $_GET['limit']??10; |
|
18 | +$seq = $_GET['seq'] ?? 1; |
|
19 | +$limit = $_GET['limit'] ?? 10; |
|
20 | 20 | |
21 | 21 | try { |
22 | 22 | $wxFinanceSDK = WxFinanceSDK::init($corpConfig); |
23 | 23 | // 获取会话记录数据(解密) |
24 | - $list = $wxFinanceSDK->getDecryptChatData($seq,$limit); |
|
24 | + $list = $wxFinanceSDK->getDecryptChatData($seq, $limit); |
|
25 | 25 | |
26 | - foreach ($list as $key=>$item){ |
|
27 | - if($wxFinanceSDK->isMedia($item['msgtype'])){ |
|
26 | + foreach ($list as $key=>$item) { |
|
27 | + if ($wxFinanceSDK->isMedia($item['msgtype'])) { |
|
28 | 28 | // 下载媒体资源 |
29 | - $list[$key]['media_path'] = $wxFinanceSDK->getDownloadMediaData($item[$item['msgtype']],$item['msgtype']); |
|
29 | + $list[$key]['media_path'] = $wxFinanceSDK->getDownloadMediaData($item[$item['msgtype']], $item['msgtype']); |
|
30 | 30 | } |
31 | 31 | } |
32 | 32 | var_dump($list); |
33 | 33 | |
34 | -}catch (FinanceSDKException $exception){ |
|
35 | - echo $exception->getMessage();exit(); |
|
34 | +} catch (FinanceSDKException $exception) { |
|
35 | + echo $exception->getMessage(); exit(); |
|
36 | 36 | } |
37 | 37 |
@@ -31,7 +31,7 @@ |
||
31 | 31 | } |
32 | 32 | var_dump($list); |
33 | 33 | |
34 | -}catch (FinanceSDKException $exception){ |
|
34 | +} catch (FinanceSDKException $exception){ |
|
35 | 35 | echo $exception->getMessage();exit(); |
36 | 36 | } |
37 | 37 |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | |
141 | 141 | // buffer写入文件 |
142 | 142 | $handle = fopen($path, 'ab+'); |
143 | - if (! $handle) { |
|
143 | + if (!$handle) { |
|
144 | 144 | throw new \RuntimeException(sprintf('打开文件失败:%s', $path)); |
145 | 145 | } |
146 | 146 | |
@@ -167,15 +167,15 @@ discard block |
||
167 | 167 | */ |
168 | 168 | protected function setFinanceSDK(array $config = []): void |
169 | 169 | { |
170 | - if (! extension_loaded('ffi')) { |
|
170 | + if (!extension_loaded('ffi')) { |
|
171 | 171 | throw new FinanceSDKException('缺少ext-ffi扩展'); |
172 | 172 | } |
173 | 173 | |
174 | 174 | $this->config = array_merge($this->config, $config); |
175 | - if (! isset($this->config['corpid'])) { |
|
175 | + if (!isset($this->config['corpid'])) { |
|
176 | 176 | throw new InvalidArgumentException('缺少配置:corpid'); |
177 | 177 | } |
178 | - if (! isset($this->config['secret'])) { |
|
178 | + if (!isset($this->config['secret'])) { |
|
179 | 179 | throw new InvalidArgumentException('缺少配置:secret'); |
180 | 180 | } |
181 | 181 |
@@ -75,11 +75,11 @@ discard block |
||
75 | 75 | * @return Object SplFileInfo |
76 | 76 | * @throws FinanceSDKException |
77 | 77 | */ |
78 | - public function getDownloadMediaData($object,$msgType) |
|
78 | + public function getDownloadMediaData($object, $msgType) |
|
79 | 79 | { |
80 | 80 | try { |
81 | - $filePath = $this->getFilePath($object,$msgType); |
|
82 | - return $this->getMediaData($object['sdkfileid'],$filePath); |
|
81 | + $filePath = $this->getFilePath($object, $msgType); |
|
82 | + return $this->getMediaData($object['sdkfileid'], $filePath); |
|
83 | 83 | } catch (\Exception $e) { |
84 | 84 | throw new FinanceSDKException($e->getMessage(), $e->getCode()); |
85 | 85 | } |
@@ -92,9 +92,9 @@ discard block |
||
92 | 92 | */ |
93 | 93 | public function isMedia($msgType): bool |
94 | 94 | { |
95 | - if(in_array($msgType,['image','voice','video','file','emotion'])){ |
|
95 | + if (in_array($msgType, ['image', 'voice', 'video', 'file', 'emotion'])) { |
|
96 | 96 | return true; |
97 | - }else{ |
|
97 | + }else { |
|
98 | 98 | return false; |
99 | 99 | } |
100 | 100 | } |
@@ -105,36 +105,36 @@ discard block |
||
105 | 105 | * @param $megType |
106 | 106 | * @return string |
107 | 107 | */ |
108 | - protected function getFilePath($object,$megType) |
|
108 | + protected function getFilePath($object, $megType) |
|
109 | 109 | { |
110 | 110 | $config = $this->getConfig(); |
111 | - if(empty($config['path'])){ |
|
112 | - $config['path'] = sys_get_temp_dir() . '/' ; |
|
111 | + if (empty($config['path'])) { |
|
112 | + $config['path'] = sys_get_temp_dir() . '/'; |
|
113 | 113 | } |
114 | 114 | $fileName = ''; |
115 | - switch ($megType){ |
|
115 | + switch ($megType) { |
|
116 | 116 | case 'image': |
117 | - $fileName = $object['md5sum']. ".jpg"; |
|
117 | + $fileName = $object['md5sum'] . ".jpg"; |
|
118 | 118 | break; |
119 | 119 | case 'voice': |
120 | - $fileName = $object['md5sum']. ".mp3"; |
|
120 | + $fileName = $object['md5sum'] . ".mp3"; |
|
121 | 121 | break; |
122 | 122 | case 'video': |
123 | - $fileName = $object['md5sum']. ".mp4"; |
|
123 | + $fileName = $object['md5sum'] . ".mp4"; |
|
124 | 124 | break; |
125 | 125 | case 'emotion': |
126 | 126 | // 表情类型,png或者gif.1表示gif 2表示png。Uint32类型 |
127 | - if($object['type'] == 1){ |
|
128 | - $fileName = $object['md5sum']. ".gif"; |
|
129 | - }else{ |
|
130 | - $fileName = $object['md5sum']. ".png"; |
|
127 | + if ($object['type'] == 1) { |
|
128 | + $fileName = $object['md5sum'] . ".gif"; |
|
129 | + }else { |
|
130 | + $fileName = $object['md5sum'] . ".png"; |
|
131 | 131 | } |
132 | 132 | break; |
133 | 133 | case 'file': |
134 | 134 | $fileName = $object['filename']; |
135 | 135 | default:break; |
136 | 136 | } |
137 | - return $config['path'].$fileName; |
|
137 | + return $config['path'] . $fileName; |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | } |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | { |
95 | 95 | if(in_array($msgType,['image','voice','video','file','emotion'])){ |
96 | 96 | return true; |
97 | - }else{ |
|
97 | + } else{ |
|
98 | 98 | return false; |
99 | 99 | } |
100 | 100 | } |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | // 表情类型,png或者gif.1表示gif 2表示png。Uint32类型 |
127 | 127 | if($object['type'] == 1){ |
128 | 128 | $fileName = $object['md5sum']. ".gif"; |
129 | - }else{ |
|
129 | + } else{ |
|
130 | 130 | $fileName = $object['md5sum']. ".png"; |
131 | 131 | } |
132 | 132 | break; |
@@ -78,15 +78,15 @@ |
||
78 | 78 | */ |
79 | 79 | protected function setFinanceSDK(array $config = []): void |
80 | 80 | { |
81 | - if (! extension_loaded('wxwork_finance_sdk')) { |
|
81 | + if (!extension_loaded('wxwork_finance_sdk')) { |
|
82 | 82 | throw new FinanceSDKException('缺少ext-wxwork_finance_sdk扩展'); |
83 | 83 | } |
84 | 84 | |
85 | 85 | $this->config = array_merge($this->config, $config); |
86 | - if (! isset($this->config['corpid'])) { |
|
86 | + if (!isset($this->config['corpid'])) { |
|
87 | 87 | throw new InvalidArgumentException('缺少配置:corpid'); |
88 | 88 | } |
89 | - if (! isset($this->config['secret'])) { |
|
89 | + if (!isset($this->config['secret'])) { |
|
90 | 90 | throw new InvalidArgumentException('缺少配置:secret'); |
91 | 91 | } |
92 | 92 | $options = ['timeout' => 30]; |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | protected $wxConfig; |
26 | 26 | |
27 | 27 | |
28 | - public function __construct(array $config = [],array $wxConfig = []) |
|
28 | + public function __construct(array $config = [], array $wxConfig = []) |
|
29 | 29 | { |
30 | 30 | $default = [ |
31 | 31 | 'default' => 'php-ext', |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | */ |
64 | 64 | public function provider($providerName): ProviderInterface |
65 | 65 | { |
66 | - if (! $this->config['providers'] || ! $this->config['providers'][$providerName]) { |
|
66 | + if (!$this->config['providers'] || !$this->config['providers'][$providerName]) { |
|
67 | 67 | throw new InvalidArgumentException("file configurations are missing {$providerName} options"); |
68 | 68 | } |
69 | 69 | return (new $this->config['providers'][$providerName]['driver']())->setConfig($this->wxConfig); |