1 | <?php |
||
30 | class Material extends AbstractAPI |
||
31 | { |
||
32 | /** |
||
33 | * Allow media type. |
||
34 | * |
||
35 | * @var array |
||
36 | */ |
||
37 | protected $allowTypes = ['image', 'voice', 'video', 'thumb', 'news_image']; |
||
38 | |||
39 | const API_GET = 'https://api.weixin.qq.com/cgi-bin/material/get_material'; |
||
40 | const API_UPLOAD = 'https://api.weixin.qq.com/cgi-bin/material/add_material'; |
||
41 | const API_DELETE = 'https://api.weixin.qq.com/cgi-bin/material/del_material'; |
||
42 | const API_STATS = 'https://api.weixin.qq.com/cgi-bin/material/get_materialcount'; |
||
43 | const API_LISTS = 'https://api.weixin.qq.com/cgi-bin/material/batchget_material'; |
||
44 | const API_NEWS_UPLOAD = 'https://api.weixin.qq.com/cgi-bin/material/add_news'; |
||
45 | const API_NEWS_UPDATE = 'https://api.weixin.qq.com/cgi-bin/material/update_news'; |
||
46 | const API_NEWS_IMAGE_UPLOAD = 'https://api.weixin.qq.com/cgi-bin/media/uploadimg'; |
||
47 | |||
48 | /** |
||
49 | * Upload image. |
||
50 | * |
||
51 | * @param string $path |
||
52 | * |
||
53 | * @return string |
||
54 | */ |
||
55 | 1 | public function uploadImage($path) |
|
59 | |||
60 | /** |
||
61 | * Upload voice. |
||
62 | * |
||
63 | * @param string $path |
||
64 | * |
||
65 | * @return string |
||
66 | */ |
||
67 | 1 | public function uploadVoice($path) |
|
71 | |||
72 | /** |
||
73 | * Upload thumb. |
||
74 | * |
||
75 | * @param string $path |
||
76 | * |
||
77 | * @return string |
||
78 | */ |
||
79 | 1 | public function uploadThumb($path) |
|
83 | |||
84 | /** |
||
85 | * Upload video. |
||
86 | * |
||
87 | * @param string $path |
||
88 | * @param string $title |
||
89 | * @param string $description |
||
90 | * |
||
91 | * @return string |
||
92 | */ |
||
93 | 1 | public function uploadVideo($path, $title, $description) |
|
106 | |||
107 | /** |
||
108 | * Upload articles. |
||
109 | * |
||
110 | * @param array|Article $articles |
||
111 | * |
||
112 | * @return string |
||
113 | */ |
||
114 | 1 | public function uploadArticle($articles) |
|
133 | |||
134 | /** |
||
135 | * Update article. |
||
136 | * |
||
137 | * @param string $mediaId |
||
138 | * @param array $article |
||
139 | * @param int $index |
||
140 | * |
||
141 | * @return bool |
||
142 | */ |
||
143 | 1 | public function updateArticle($mediaId, $article, $index = 0) |
|
153 | |||
154 | /** |
||
155 | * Upload image for article. |
||
156 | * |
||
157 | * @param string $path |
||
158 | * |
||
159 | * @return string |
||
160 | */ |
||
161 | 1 | public function uploadArticleImage($path) |
|
165 | |||
166 | /** |
||
167 | * Fetch material. |
||
168 | * |
||
169 | * @param string $mediaId |
||
170 | * |
||
171 | * @return mixed |
||
172 | */ |
||
173 | 1 | public function get($mediaId) |
|
194 | |||
195 | /** |
||
196 | * Delete material by media ID. |
||
197 | * |
||
198 | * @param string $mediaId |
||
199 | * |
||
200 | * @return bool |
||
201 | */ |
||
202 | 1 | public function delete($mediaId) |
|
206 | |||
207 | /** |
||
208 | * List materials. |
||
209 | * |
||
210 | * example: |
||
211 | * |
||
212 | * { |
||
213 | * "total_count": TOTAL_COUNT, |
||
214 | * "item_count": ITEM_COUNT, |
||
215 | * "item": [{ |
||
216 | * "media_id": MEDIA_ID, |
||
217 | * "name": NAME, |
||
218 | * "update_time": UPDATE_TIME |
||
219 | * }, |
||
220 | * // more... |
||
221 | * ] |
||
222 | * } |
||
223 | * |
||
224 | * @param string $type |
||
225 | * @param int $offset |
||
226 | * @param int $count |
||
227 | * |
||
228 | * @return array |
||
229 | */ |
||
230 | 1 | public function lists($type, $offset = 0, $count = 20) |
|
240 | |||
241 | /** |
||
242 | * Get stats of materials. |
||
243 | * |
||
244 | * @return array |
||
245 | */ |
||
246 | 1 | public function stats() |
|
250 | |||
251 | /** |
||
252 | * Upload material. |
||
253 | * |
||
254 | * @param string $type |
||
255 | * @param string $path |
||
256 | * @param array $form |
||
257 | * |
||
258 | * @return string |
||
259 | * |
||
260 | * @throws InvalidArgumentException |
||
261 | */ |
||
262 | 5 | protected function uploadMedia($type, $path, array $form = []) |
|
270 | |||
271 | /** |
||
272 | * Get API by type. |
||
273 | * |
||
274 | * @param string $type |
||
275 | * |
||
276 | * @return string |
||
277 | */ |
||
278 | 5 | public function getAPIByType($type) |
|
290 | } |
||
291 |