@@ 433-479 (lines=47) @@ | ||
430 | } |
|
431 | ||
432 | //token 刷新后重试 post |
|
433 | public static function post_retry($apiUrl, $data) |
|
434 | { |
|
435 | $urlarr = parse_url($apiUrl); |
|
436 | parse_str($urlarr['query'], $parr); |
|
437 | ||
438 | usleep(500000); |
|
439 | ||
440 | $parr['access_token'] = self::getAccessToken(); |
|
441 | ||
442 | $apiUrl = $urlarr['scheme'] . '://' . $urlarr['host'] . $urlarr['path']; |
|
443 | $apiUrl .= '?' . http_build_query($parr); |
|
444 | ||
445 | $ch = curl_init(); |
|
446 | curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false); |
|
447 | curl_setopt($ch, CURLOPT_URL, $apiUrl); |
|
448 | curl_setopt($ch, CURLOPT_TIMEOUT, 60); |
|
449 | curl_setopt($ch, CURLOPT_HEADER, true); |
|
450 | curl_setopt($ch, CURLOPT_NOBODY, false); |
|
451 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
|
452 | curl_setopt($ch, CURLOPT_POST, 1); |
|
453 | curl_setopt($ch, CURLOPT_POSTFIELDS, $data); |
|
454 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); |
|
455 | ||
456 | $res = trim(curl_exec($ch)); |
|
457 | $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
458 | curl_close($ch); |
|
459 | ||
460 | $header = ''; |
|
461 | $body = $res; |
|
462 | if ($httpcode == 200) { |
|
463 | list($header, $body) = explode("\r\n\r\n", $res, 2); |
|
464 | //list($header, $body) = explode("keep-alive", $res, 2); |
|
465 | $header = self::http_parse_headers($header); |
|
466 | } |
|
467 | ||
468 | $result = []; |
|
469 | $result['info'] = $body; |
|
470 | $result['header'] = $header; |
|
471 | $result['status'] = $httpcode; |
|
472 | ||
473 | $rest_retry = self::packData($result); |
|
474 | if ($rest_retry === 'retry') { |
|
475 | return false; |
|
476 | } |
|
477 | ||
478 | return $rest_retry; |
|
479 | } |
|
480 | ||
481 | //token 刷新后重试 get |
|
482 | public static function get_retry($apiUrl) |
@@ 616-662 (lines=47) @@ | ||
613 | } |
|
614 | ||
615 | //token 刷新后重试 post |
|
616 | public static function post_retry($apiUrl, $data) |
|
617 | { |
|
618 | $urlarr = parse_url($apiUrl); |
|
619 | parse_str($urlarr['query'], $parr); |
|
620 | ||
621 | usleep(500000); |
|
622 | ||
623 | $parr['access_token'] = self::getAccessToken(); |
|
624 | ||
625 | $apiUrl = $urlarr['scheme'] . '://' . $urlarr['host'] . $urlarr['path']; |
|
626 | $apiUrl .= '?' . http_build_query($parr); |
|
627 | ||
628 | $ch = curl_init(); |
|
629 | curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false); |
|
630 | curl_setopt($ch, CURLOPT_URL, $apiUrl); |
|
631 | curl_setopt($ch, CURLOPT_TIMEOUT, 60); |
|
632 | curl_setopt($ch, CURLOPT_HEADER, true); |
|
633 | curl_setopt($ch, CURLOPT_NOBODY, false); |
|
634 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
|
635 | curl_setopt($ch, CURLOPT_POST, 1); |
|
636 | curl_setopt($ch, CURLOPT_POSTFIELDS, $data); |
|
637 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); |
|
638 | ||
639 | $res = trim(curl_exec($ch)); |
|
640 | $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
641 | curl_close($ch); |
|
642 | ||
643 | $header = ''; |
|
644 | $body = $res; |
|
645 | if ($httpcode == 200) { |
|
646 | list($header, $body) = explode("\r\n\r\n", $res, 2); |
|
647 | //list($header, $body) = explode("keep-alive", $res, 2); |
|
648 | $header = self::http_parse_headers($header); |
|
649 | } |
|
650 | ||
651 | $result = []; |
|
652 | $result['info'] = $body; |
|
653 | $result['header'] = $header; |
|
654 | $result['status'] = $httpcode; |
|
655 | ||
656 | $rest_retry = self::packData($result); |
|
657 | if ($rest_retry === 'retry') { |
|
658 | return false; |
|
659 | } |
|
660 | ||
661 | return $rest_retry; |
|
662 | } |
|
663 | ||
664 | //token 刷新后重试 get |
|
665 | public static function get_retry($apiUrl) |