@@ 276-337 (lines=62) @@ | ||
273 | * |
|
274 | * @return array|bool 错误时返回false |
|
275 | */ |
|
276 | public static function _get($module, $node, $queryStr = [], $arsort = true, $apitype = 'cgi-bin') |
|
277 | { |
|
278 | //不需要 token 参数 |
|
279 | $no_module = ['token', 'showqrcode']; |
|
280 | ||
281 | $no_apitye = ['sns']; |
|
282 | ||
283 | if (in_array($apitype, $no_apitye) || in_array($module, $no_module)) { |
|
284 | //$queryStr = $queryStr; |
|
285 | } elseif ($module != 'token') { |
|
286 | $info = self::getAccessToken(); |
|
287 | ||
288 | if (false == $info) { |
|
289 | return false; |
|
290 | } |
|
291 | $queryStr['access_token'] = $info; |
|
292 | } |
|
293 | ||
294 | if ($arsort) { |
|
295 | arsort($queryStr); |
|
296 | } |
|
297 | ||
298 | $queryStr = http_build_query($queryStr); |
|
299 | ||
300 | if (!empty($node)) { |
|
301 | $node = '/' . $node; |
|
302 | } |
|
303 | ||
304 | $apiUrl = rtrim(self::$API_URL . $apitype . '/' . $module . $node, '/'); |
|
305 | $apiUrl .= '?' . $queryStr; |
|
306 | ||
307 | $apiUrl = urldecode($apiUrl); |
|
308 | $ch = curl_init($apiUrl); |
|
309 | curl_setopt($ch, CURLOPT_URL, $apiUrl); |
|
310 | curl_setopt($ch, CURLOPT_TIMEOUT, 60); |
|
311 | curl_setopt($ch, CURLOPT_HEADER, true); |
|
312 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
|
313 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); |
|
314 | ||
315 | $res = curl_exec($ch); |
|
316 | $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
317 | curl_close($ch); |
|
318 | ||
319 | $header = ''; |
|
320 | $body = $res; |
|
321 | if ($httpcode == 200) { |
|
322 | list($header, $body) = explode("\r\n\r\n", $res, 2); |
|
323 | $header = self::http_parse_headers($header); |
|
324 | } |
|
325 | ||
326 | $result = []; |
|
327 | $result['info'] = $body; |
|
328 | $result['header'] = $header; |
|
329 | $result['status'] = $httpcode; |
|
330 | ||
331 | $rest = self::packData($result); |
|
332 | if ($rest == 'retry') { |
|
333 | return self::get_retry($apiUrl); |
|
334 | } else { |
|
335 | return $rest; |
|
336 | } |
|
337 | } |
|
338 | ||
339 | /** |
|
340 | * 用post的方式访问接口. |
@@ 259-320 (lines=62) @@ | ||
256 | * |
|
257 | * @return array|bool 错误时返回false |
|
258 | */ |
|
259 | public static function _get($module, $node, $queryStr = [], $arsort = true, $apitype = 'cgi-bin') |
|
260 | { |
|
261 | //不需要 token 参数 |
|
262 | $no_module = ['token', 'showqrcode']; |
|
263 | ||
264 | $no_apitye = ['sns']; |
|
265 | ||
266 | if (in_array($apitype, $no_apitye) || in_array($module, $no_module)) { |
|
267 | //$queryStr = $queryStr; |
|
268 | } elseif ($module != 'token') { |
|
269 | $info = self::getAccessToken(); |
|
270 | ||
271 | if (false == $info) { |
|
272 | return false; |
|
273 | } |
|
274 | $queryStr['access_token'] = $info; |
|
275 | } |
|
276 | ||
277 | if ($arsort) { |
|
278 | arsort($queryStr); |
|
279 | } |
|
280 | ||
281 | $queryStr = http_build_query($queryStr); |
|
282 | ||
283 | if (!empty($node)) { |
|
284 | $node = '/' . $node; |
|
285 | } |
|
286 | ||
287 | $apiUrl = rtrim(self::$API_URL . $apitype . '/' . $module . $node, '/'); |
|
288 | $apiUrl .= '?' . $queryStr; |
|
289 | ||
290 | $apiUrl = urldecode($apiUrl); |
|
291 | $ch = curl_init($apiUrl); |
|
292 | curl_setopt($ch, CURLOPT_URL, $apiUrl); |
|
293 | curl_setopt($ch, CURLOPT_TIMEOUT, 60); |
|
294 | curl_setopt($ch, CURLOPT_HEADER, true); |
|
295 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
|
296 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); |
|
297 | ||
298 | $res = curl_exec($ch); |
|
299 | $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
300 | curl_close($ch); |
|
301 | ||
302 | $header = ''; |
|
303 | $body = $res; |
|
304 | if ($httpcode == 200) { |
|
305 | list($header, $body) = explode("\r\n\r\n", $res, 2); |
|
306 | $header = self::http_parse_headers($header); |
|
307 | } |
|
308 | ||
309 | $result = []; |
|
310 | $result['info'] = $body; |
|
311 | $result['header'] = $header; |
|
312 | $result['status'] = $httpcode; |
|
313 | ||
314 | $rest = self::packData($result); |
|
315 | if ($rest == 'retry') { |
|
316 | return self::get_retry($apiUrl); |
|
317 | } else { |
|
318 | return $rest; |
|
319 | } |
|
320 | } |
|
321 | ||
322 | /** |
|
323 | * 用post的方式访问接口. |