12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- <?php
- /**
- * Created by PhpStorm.
- * User: JZ
- * Date: 2019/7/18
- * Time: 21:26
- */
- class HttpConnection {
- const SSL_CHECK = false; // 忽略SSL检查
- const RENNECT_TIMES = 2; // 连接重试次数
- /**
- *
- * 构建http请求参数
- *
- */
- public static function buildHttpRequest($curl, $url, $heads){
- curl_setopt($curl, CURLOPT_TIMEOUT, SDKClient::readTimeout);
- curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, SDKClient::connectTimeout);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, self::SSL_CHECK);
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, self::SSL_CHECK);
- //设定是否显示头信息
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($curl, CURLOPT_URL, $url);
- curl_setopt($curl, CURLOPT_HTTPHEADER, $heads);
- return $curl;
- }
- /**
- *
- * 数组转字符串,拼接GET请求参数
- *
- */
- public static function buildGetUrlParams($url, $data){
- $url = $url.'?';
- if($data && is_array($data)){
- $paramers = http_build_query($data);
- $url = $url.$paramers;
- }
- return $url;
- }
- }
|