expInfo.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. declare (strict_types=1);
  3. namespace library\lib;
  4. // +----------------------------------------------------------------------
  5. // | [ WE CAN DO IT MORE SIMPLE ]
  6. // +----------------------------------------------------------------------
  7. // | Copyright (c) 2018-2020 rights reserved.
  8. // +----------------------------------------------------------------------
  9. // | Author: TABLE ME
  10. // +----------------------------------------------------------------------
  11. // | Date: 2020-12-15 16:46
  12. // +----------------------------------------------------------------------
  13. class expInfo {
  14. //host
  15. private $host = "https://ali-deliver.showapi.com/";
  16. private $appcode = '';
  17. /**
  18. * @param $code
  19. */
  20. public function showapiExpInfo($code,$com = 'auto'){
  21. $querys = "com=" . $com . "&nu=".$code;
  22. $data = $this->httpGet('showapi_expInfo',$querys);
  23. return json_decode($data,true);
  24. }
  25. /**
  26. * @param $url
  27. * @param $query
  28. * @return bool|string
  29. */
  30. private function httpGet($url,$query) {
  31. $headers = array();
  32. array_push($headers, "Authorization:APPCODE " . $this->appcode);
  33. $url = $this->host . $url . '?' . $query;
  34. $curl = curl_init();
  35. curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET');
  36. curl_setopt($curl, CURLOPT_URL, $url);
  37. curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  38. curl_setopt($curl, CURLOPT_FAILONERROR, false);
  39. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  40. curl_setopt($curl, CURLOPT_HEADER, false);
  41. if (1 == strpos("$".$this->host, "https://"))
  42. {
  43. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  44. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  45. }
  46. $res = curl_exec($curl);
  47. curl_close($curl);
  48. return $res;
  49. }
  50. function curlPost($url, $post_data = array(), $timeout = 5, $data_type = "") {
  51. //支持json数据数据提交
  52. if($data_type == 'json'){
  53. $post_string = json_encode($post_data);
  54. }elseif($data_type == 'array') {
  55. $post_string = $post_data;
  56. }elseif(is_array($post_data)){
  57. $post_string = http_build_query($post_data, '', '&');
  58. $post_string = urldecode($post_string);
  59. }
  60. $ch = curl_init(); // 启动一个CURL会话
  61. curl_setopt($ch, CURLOPT_URL, $url); // 要访问的地址
  62. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 对认证证书来源的检查 // https请求 不验证证书和hosts
  63. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在
  64. curl_setopt($ch, CURLOPT_POST, true); // 发送一个常规的Post请求
  65. curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string); // Post提交的数据包
  66. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); // 设置超时限制防止死循环
  67. curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
  68. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 获取的信息以文件流的形式返回
  69. $result = curl_exec($ch);
  70. curl_close($ch);
  71. return $result;
  72. }
  73. }