@@ -37,19 +37,19 @@ discard block |
||
| 37 | 37 | * @return bool|string |
| 38 | 38 | * @throws \Exception |
| 39 | 39 | */ |
| 40 | - static public function httpPost(string $url, array $param = array(), array $httpHeaders = array(), string $proxy='', int $http_code = 200) |
|
| 40 | + static public function httpPost(string $url, array $param = array(), array $httpHeaders = array(), string $proxy = '', int $http_code = 200) |
|
| 41 | 41 | { |
| 42 | 42 | /** 参数检测,object或者array进行http_build_query */ |
| 43 | - if(!empty($param) && is_array($param)){ |
|
| 43 | + if (!empty($param) && is_array($param)) { |
|
| 44 | 44 | $flag = false; |
| 45 | - foreach ($param as $value){ |
|
| 45 | + foreach ($param as $value) { |
|
| 46 | 46 | //判断参数是否是一个对象 或者 是一个数组 |
| 47 | - if(is_array($value) || (is_string($value) && is_object($value))){ |
|
| 47 | + if (is_array($value) || (is_string($value) && is_object($value))) { |
|
| 48 | 48 | $flag = true; |
| 49 | 49 | break; |
| 50 | 50 | } |
| 51 | 51 | } |
| 52 | - if($flag){ |
|
| 52 | + if ($flag) { |
|
| 53 | 53 | $param = http_build_query($param); |
| 54 | 54 | } |
| 55 | 55 | } |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | curl_setopt($curl, CURLOPT_POSTFIELDS, $param); |
| 67 | 67 | |
| 68 | 68 | /** 设置请求headers */ |
| 69 | - if(empty($httpHeaders)) $httpHeaders = self::$httpHeaders; |
|
| 69 | + if (empty($httpHeaders)) $httpHeaders = self::$httpHeaders; |
|
| 70 | 70 | curl_setopt($curl, CURLOPT_HTTPHEADER, $httpHeaders); |
| 71 | 71 | |
| 72 | 72 | /** gzip压缩 */ |
@@ -80,11 +80,11 @@ discard block |
||
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | /** http代理 */ |
| 83 | - if(!empty($proxy)){ |
|
| 84 | - $proxy = explode(':',$proxy); |
|
| 83 | + if (!empty($proxy)) { |
|
| 84 | + $proxy = explode(':', $proxy); |
|
| 85 | 85 | curl_setopt($curl, CURLOPT_PROXYAUTH, CURLAUTH_BASIC); //代理认证模式 |
| 86 | 86 | curl_setopt($curl, CURLOPT_PROXY, "$proxy[0]"); //代理服务器地址 |
| 87 | - curl_setopt($curl, CURLOPT_PROXYPORT,$proxy[1]); //代理服务器端口 |
|
| 87 | + curl_setopt($curl, CURLOPT_PROXYPORT, $proxy[1]); //代理服务器端口 |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | /** 请求 */ |
@@ -94,20 +94,20 @@ discard block |
||
| 94 | 94 | /** 关闭请求资源 */ |
| 95 | 95 | curl_close($curl); |
| 96 | 96 | |
| 97 | - if($http_code !== 0){ |
|
| 97 | + if ($http_code !== 0) { |
|
| 98 | 98 | /** 验证网络请求状态 */ |
| 99 | 99 | if (intval($info["http_code"]) === 0) { |
| 100 | 100 | throw new TException(StatusCode::COMMON_TINYMENG_REQUEST_METHOD, |
| 101 | - '[httpPost]: POST request was aborted ! Request url :' . $url . ' , post request data : ' . var_export($param,true) |
|
| 101 | + '[httpPost]: POST request was aborted ! Request url :'.$url.' , post request data : '.var_export($param, true) |
|
| 102 | 102 | ); |
| 103 | - }elseif(intval($info["http_code"]) != $http_code){ |
|
| 103 | + }elseif (intval($info["http_code"]) != $http_code) { |
|
| 104 | 104 | throw new TException(StatusCode::COMMON_TINYMENG_REQUEST_METHOD, |
| 105 | - '[httpPost]: POST request was aborted ! Request url :' . $url . ' , post request data : ' . var_export($param,true).' ,return code : '.$info["http_code"] .' ,return content : '.$content |
|
| 105 | + '[httpPost]: POST request was aborted ! Request url :'.$url.' , post request data : '.var_export($param, true).' ,return code : '.$info["http_code"].' ,return content : '.$content |
|
| 106 | 106 | ); |
| 107 | 107 | } else { |
| 108 | 108 | return $content; |
| 109 | 109 | } |
| 110 | - }else{ |
|
| 110 | + } else { |
|
| 111 | 111 | return $content; |
| 112 | 112 | } |
| 113 | 113 | } |
@@ -124,13 +124,13 @@ discard block |
||
| 124 | 124 | * @return bool|string |
| 125 | 125 | * @throws \Exception |
| 126 | 126 | */ |
| 127 | - static public function httpGet(string $url, array $param = array(), array $httpHeaders = array(), string $proxy= '', int $http_code = 200) |
|
| 127 | + static public function httpGet(string $url, array $param = array(), array $httpHeaders = array(), string $proxy = '', int $http_code = 200) |
|
| 128 | 128 | { |
| 129 | 129 | $curl = curl_init(); |
| 130 | 130 | |
| 131 | 131 | /** 设置请求参数 */ |
| 132 | 132 | if (!empty($param)) { |
| 133 | - $url = $url . '?' . http_build_query($param); |
|
| 133 | + $url = $url.'?'.http_build_query($param); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | /** 设置请求链接 */ |
@@ -146,15 +146,15 @@ discard block |
||
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | /** http代理 */ |
| 149 | - if(!empty($proxy)){ |
|
| 150 | - $proxy = explode(':',$proxy); |
|
| 149 | + if (!empty($proxy)) { |
|
| 150 | + $proxy = explode(':', $proxy); |
|
| 151 | 151 | curl_setopt($curl, CURLOPT_PROXYAUTH, CURLAUTH_BASIC); //代理认证模式 |
| 152 | 152 | curl_setopt($curl, CURLOPT_PROXY, "$proxy[0]"); //代理服务器地址 |
| 153 | - curl_setopt($curl, CURLOPT_PROXYPORT,$proxy[1]); //代理服务器端口 |
|
| 153 | + curl_setopt($curl, CURLOPT_PROXYPORT, $proxy[1]); //代理服务器端口 |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | /** 设置请求headers */ |
| 157 | - if(empty($httpHeaders)) $httpHeaders = self::$httpHeaders; |
|
| 157 | + if (empty($httpHeaders)) $httpHeaders = self::$httpHeaders; |
|
| 158 | 158 | curl_setopt($curl, CURLOPT_HTTPHEADER, $httpHeaders); |
| 159 | 159 | |
| 160 | 160 | /** gzip压缩 */ |
@@ -168,19 +168,19 @@ discard block |
||
| 168 | 168 | curl_close($curl); |
| 169 | 169 | |
| 170 | 170 | /** 验证网络请求状态 */ |
| 171 | - if($http_code !== 0){ |
|
| 171 | + if ($http_code !== 0) { |
|
| 172 | 172 | if (intval($info["http_code"]) === 0) { |
| 173 | 173 | throw new TException(StatusCode::COMMON_TINYMENG_REQUEST_METHOD, |
| 174 | - '[httpGet]: GET request was aborted ! Request url :' . $url |
|
| 174 | + '[httpGet]: GET request was aborted ! Request url :'.$url |
|
| 175 | 175 | ); |
| 176 | - }elseif(intval($info["http_code"]) != $http_code){ |
|
| 176 | + }elseif (intval($info["http_code"]) != $http_code) { |
|
| 177 | 177 | throw new TException(StatusCode::COMMON_TINYMENG_REQUEST_METHOD, |
| 178 | - '[httpGet]: GET request was aborted ! Request url :' . $url .' ,return code : '.$info["http_code"] .' ,return content : '.$content |
|
| 178 | + '[httpGet]: GET request was aborted ! Request url :'.$url.' ,return code : '.$info["http_code"].' ,return content : '.$content |
|
| 179 | 179 | ); |
| 180 | 180 | } else { |
| 181 | 181 | return $content; |
| 182 | 182 | } |
| 183 | - }else{ |
|
| 183 | + } else { |
|
| 184 | 184 | return $content; |
| 185 | 185 | } |
| 186 | 186 | } |
@@ -66,7 +66,9 @@ discard block |
||
| 66 | 66 | curl_setopt($curl, CURLOPT_POSTFIELDS, $param); |
| 67 | 67 | |
| 68 | 68 | /** 设置请求headers */ |
| 69 | - if(empty($httpHeaders)) $httpHeaders = self::$httpHeaders; |
|
| 69 | + if(empty($httpHeaders)) { |
|
| 70 | + $httpHeaders = self::$httpHeaders; |
|
| 71 | + } |
|
| 70 | 72 | curl_setopt($curl, CURLOPT_HTTPHEADER, $httpHeaders); |
| 71 | 73 | |
| 72 | 74 | /** gzip压缩 */ |
@@ -100,14 +102,14 @@ discard block |
||
| 100 | 102 | throw new TException(StatusCode::COMMON_TINYMENG_REQUEST_METHOD, |
| 101 | 103 | '[httpPost]: POST request was aborted ! Request url :' . $url . ' , post request data : ' . var_export($param,true) |
| 102 | 104 | ); |
| 103 | - }elseif(intval($info["http_code"]) != $http_code){ |
|
| 105 | + } elseif(intval($info["http_code"]) != $http_code){ |
|
| 104 | 106 | throw new TException(StatusCode::COMMON_TINYMENG_REQUEST_METHOD, |
| 105 | 107 | '[httpPost]: POST request was aborted ! Request url :' . $url . ' , post request data : ' . var_export($param,true).' ,return code : '.$info["http_code"] .' ,return content : '.$content |
| 106 | 108 | ); |
| 107 | 109 | } else { |
| 108 | 110 | return $content; |
| 109 | 111 | } |
| 110 | - }else{ |
|
| 112 | + } else{ |
|
| 111 | 113 | return $content; |
| 112 | 114 | } |
| 113 | 115 | } |
@@ -154,7 +156,9 @@ discard block |
||
| 154 | 156 | } |
| 155 | 157 | |
| 156 | 158 | /** 设置请求headers */ |
| 157 | - if(empty($httpHeaders)) $httpHeaders = self::$httpHeaders; |
|
| 159 | + if(empty($httpHeaders)) { |
|
| 160 | + $httpHeaders = self::$httpHeaders; |
|
| 161 | + } |
|
| 158 | 162 | curl_setopt($curl, CURLOPT_HTTPHEADER, $httpHeaders); |
| 159 | 163 | |
| 160 | 164 | /** gzip压缩 */ |
@@ -173,14 +177,14 @@ discard block |
||
| 173 | 177 | throw new TException(StatusCode::COMMON_TINYMENG_REQUEST_METHOD, |
| 174 | 178 | '[httpGet]: GET request was aborted ! Request url :' . $url |
| 175 | 179 | ); |
| 176 | - }elseif(intval($info["http_code"]) != $http_code){ |
|
| 180 | + } elseif(intval($info["http_code"]) != $http_code){ |
|
| 177 | 181 | throw new TException(StatusCode::COMMON_TINYMENG_REQUEST_METHOD, |
| 178 | 182 | '[httpGet]: GET request was aborted ! Request url :' . $url .' ,return code : '.$info["http_code"] .' ,return content : '.$content |
| 179 | 183 | ); |
| 180 | 184 | } else { |
| 181 | 185 | return $content; |
| 182 | 186 | } |
| 183 | - }else{ |
|
| 187 | + } else{ |
|
| 184 | 188 | return $content; |
| 185 | 189 | } |
| 186 | 190 | } |