HttpConnection.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: JZ
  5. * Date: 2019/7/18
  6. * Time: 21:26
  7. */
  8. class HttpConnection {
  9. const SSL_CHECK = false; // 忽略SSL检查
  10. const RENNECT_TIMES = 2; // 连接重试次数
  11. /**
  12. *
  13. * 构建http请求参数
  14. *
  15. */
  16. public static function buildHttpRequest($curl, $url, $heads){
  17. curl_setopt($curl, CURLOPT_TIMEOUT, SDKClient::readTimeout);
  18. curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, SDKClient::connectTimeout);
  19. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, self::SSL_CHECK);
  20. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, self::SSL_CHECK);
  21. //设定是否显示头信息
  22. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  23. curl_setopt($curl, CURLOPT_URL, $url);
  24. curl_setopt($curl, CURLOPT_HTTPHEADER, $heads);
  25. return $curl;
  26. }
  27. /**
  28. *
  29. * 数组转字符串,拼接GET请求参数
  30. *
  31. */
  32. public static function buildGetUrlParams($url, $data){
  33. $url = $url.'?';
  34. if($data && is_array($data)){
  35. $paramers = http_build_query($data);
  36. $url = $url.$paramers;
  37. }
  38. return $url;
  39. }
  40. }