@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * |
| 35 | 35 | * php -r 'echo dechex( 0b00111111 );' |
| 36 | 36 | */ |
| 37 | -class UniqueId{ |
|
| 37 | +class UniqueId { |
|
| 38 | 38 | |
| 39 | 39 | |
| 40 | 40 | protected static $g_cInstanceDId; |
@@ -50,12 +50,12 @@ discard block |
||
| 50 | 50 | /** |
| 51 | 51 | * __construct |
| 52 | 52 | */ |
| 53 | - public function __construct(){} |
|
| 53 | + public function __construct() {} |
|
| 54 | 54 | |
| 55 | 55 | /** |
| 56 | 56 | * __destruct |
| 57 | 57 | */ |
| 58 | - public function __destruct(){} |
|
| 58 | + public function __destruct() {} |
|
| 59 | 59 | |
| 60 | 60 | /** |
| 61 | 61 | * getInstance |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | */ |
| 64 | 64 | static function getInstance() |
| 65 | 65 | { |
| 66 | - if ( is_null( self::$g_cInstanceDId ) || ! isset( self::$g_cInstanceDId ) ) |
|
| 66 | + if (is_null(self::$g_cInstanceDId) || !isset(self::$g_cInstanceDId)) |
|
| 67 | 67 | { |
| 68 | 68 | self::$g_cInstanceDId = new self(); |
| 69 | 69 | } |
@@ -80,42 +80,42 @@ discard block |
||
| 80 | 80 | * @param $arrData &array details about the id |
| 81 | 81 | * @return int(64) id |
| 82 | 82 | */ |
| 83 | - public function createId( $nCenter, $nNode, $sSource = null, & $arrData = null ) |
|
| 83 | + public function createId($nCenter, $nNode, $sSource = null, & $arrData = null) |
|
| 84 | 84 | { |
| 85 | - if ( ! $this->isValidCenterId( $nCenter ) ) |
|
| 85 | + if (!$this->isValidCenterId($nCenter)) |
|
| 86 | 86 | { |
| 87 | 87 | return null; |
| 88 | 88 | } |
| 89 | - if ( ! $this->isValidNodeId( $nNode ) ) |
|
| 89 | + if (!$this->isValidNodeId($nNode)) |
|
| 90 | 90 | { |
| 91 | 91 | return null; |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | // ... |
| 95 | - $nRet = 0; |
|
| 96 | - $nTime = $this->getEscapedTime(); |
|
| 95 | + $nRet = 0; |
|
| 96 | + $nTime = $this->getEscapedTime(); |
|
| 97 | 97 | |
| 98 | - if ( is_string( $sSource ) && strlen( $sSource ) > 0 ) |
|
| 98 | + if (is_string($sSource) && strlen($sSource) > 0) |
|
| 99 | 99 | { |
| 100 | 100 | // use crc32 hash value instead of rand |
| 101 | - $nRand = crc32( $sSource ); |
|
| 101 | + $nRand = crc32($sSource); |
|
| 102 | 102 | } |
| 103 | 103 | else |
| 104 | 104 | { |
| 105 | 105 | // 0 ~ 4095 |
| 106 | - $nRand = rand( 0, 0xFFF ); |
|
| 106 | + $nRand = rand(0, 0xFFF); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | // ... |
| 110 | - $nCenterV = ( ( $nCenter << 17 ) & 0x00000000003E0000 ); |
|
| 111 | - $nNodeV = ( ( $nNode << 12 ) & 0x000000000001F000 ); |
|
| 112 | - $nTimeV = ( ( $nTime << 22 ) & 0x7FFFFFFFFFC00000 ); |
|
| 113 | - $nRandV = ( ( $nRand << 0 ) & 0x0000000000000FFF ); |
|
| 110 | + $nCenterV = (($nCenter << 17) & 0x00000000003E0000); |
|
| 111 | + $nNodeV = (($nNode << 12) & 0x000000000001F000); |
|
| 112 | + $nTimeV = (($nTime << 22) & 0x7FFFFFFFFFC00000); |
|
| 113 | + $nRandV = (($nRand << 0) & 0x0000000000000FFF); |
|
| 114 | 114 | |
| 115 | - $nRet = ( $nCenterV + $nNodeV + $nTimeV + $nRandV ); |
|
| 115 | + $nRet = ($nCenterV + $nNodeV + $nTimeV + $nRandV); |
|
| 116 | 116 | |
| 117 | 117 | // ... |
| 118 | - if ( ! is_null( $arrData ) ) |
|
| 118 | + if (!is_null($arrData)) |
|
| 119 | 119 | { |
| 120 | 120 | $arrData = |
| 121 | 121 | [ |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | ]; |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | - return intval( $nRet ); |
|
| 129 | + return intval($nRet); |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | /** |
@@ -135,18 +135,18 @@ discard block |
||
| 135 | 135 | * @param $nId int 64 bits unique id |
| 136 | 136 | * @return array details about the id |
| 137 | 137 | */ |
| 138 | - public function parseId( $nId ) |
|
| 138 | + public function parseId($nId) |
|
| 139 | 139 | { |
| 140 | - if ( ! is_numeric( $nId ) || $nId <= 0 ) |
|
| 140 | + if (!is_numeric($nId) || $nId <= 0) |
|
| 141 | 141 | { |
| 142 | 142 | return null; |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | // ... |
| 146 | - $nCenter = ( ( $nId & 0x00000000003E0000 ) >> 17 ); |
|
| 147 | - $nNode = ( ( $nId & 0x000000000001F000 ) >> 12 ); |
|
| 148 | - $nTime = ( ( $nId & 0x7FFFFFFFFFC00000 ) >> 22 ); |
|
| 149 | - $nRand = ( ( $nId & 0x0000000000000FFF ) >> 0 ); |
|
| 146 | + $nCenter = (($nId & 0x00000000003E0000) >> 17); |
|
| 147 | + $nNode = (($nId & 0x000000000001F000) >> 12); |
|
| 148 | + $nTime = (($nId & 0x7FFFFFFFFFC00000) >> 22); |
|
| 149 | + $nRand = (($nId & 0x0000000000000FFF) >> 0); |
|
| 150 | 150 | |
| 151 | 151 | return |
| 152 | 152 | [ |
@@ -163,20 +163,20 @@ discard block |
||
| 163 | 163 | * @param $nVal int 64 bits unique id |
| 164 | 164 | * @return boolean true or false |
| 165 | 165 | */ |
| 166 | - public function isValidId( $nVal ) |
|
| 166 | + public function isValidId($nVal) |
|
| 167 | 167 | { |
| 168 | 168 | $bRet = false; |
| 169 | - $arrD = $this->parseId( $nVal ); |
|
| 170 | - if ( is_array( $arrD ) && |
|
| 171 | - array_key_exists( 'center', $arrD ) && |
|
| 172 | - array_key_exists( 'node', $arrD ) && |
|
| 173 | - array_key_exists( 'time', $arrD ) && |
|
| 174 | - array_key_exists( 'rand', $arrD ) ) |
|
| 169 | + $arrD = $this->parseId($nVal); |
|
| 170 | + if (is_array($arrD) && |
|
| 171 | + array_key_exists('center', $arrD) && |
|
| 172 | + array_key_exists('node', $arrD) && |
|
| 173 | + array_key_exists('time', $arrD) && |
|
| 174 | + array_key_exists('rand', $arrD)) |
|
| 175 | 175 | { |
| 176 | - if ( $this->isValidCenterId( $arrD[ 'center' ] ) && |
|
| 177 | - $this->isValidNodeId( $arrD[ 'node' ] ) && |
|
| 178 | - $this->isValidTime( $arrD[ 'time' ] ) && |
|
| 179 | - $this->isValidRand( $arrD[ 'rand' ] ) ) |
|
| 176 | + if ($this->isValidCenterId($arrD['center']) && |
|
| 177 | + $this->isValidNodeId($arrD['node']) && |
|
| 178 | + $this->isValidTime($arrD['time']) && |
|
| 179 | + $this->isValidRand($arrD['rand'])) |
|
| 180 | 180 | { |
| 181 | 181 | $bRet = true; |
| 182 | 182 | } |
@@ -190,36 +190,36 @@ discard block |
||
| 190 | 190 | * @param $nVal |
| 191 | 191 | * @return bool |
| 192 | 192 | */ |
| 193 | - public function isValidCenterId( $nVal ) |
|
| 193 | + public function isValidCenterId($nVal) |
|
| 194 | 194 | { |
| 195 | - return is_numeric( $nVal ) && ( $nVal >= 0 ) && ( $nVal <= 31 ); |
|
| 195 | + return is_numeric($nVal) && ($nVal >= 0) && ($nVal <= 31); |
|
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | /** |
| 199 | 199 | * @param $nVal |
| 200 | 200 | * @return bool |
| 201 | 201 | */ |
| 202 | - public function isValidNodeId( $nVal ) |
|
| 202 | + public function isValidNodeId($nVal) |
|
| 203 | 203 | { |
| 204 | - return is_numeric( $nVal ) && ( $nVal >= 0 ) && ( $nVal <= 31 ); |
|
| 204 | + return is_numeric($nVal) && ($nVal >= 0) && ($nVal <= 31); |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | /** |
| 208 | 208 | * @param $nVal |
| 209 | 209 | * @return bool |
| 210 | 210 | */ |
| 211 | - public function isValidTime( $nVal ) |
|
| 211 | + public function isValidTime($nVal) |
|
| 212 | 212 | { |
| 213 | - return is_numeric( $nVal ) && ( $nVal >= 0 ); |
|
| 213 | + return is_numeric($nVal) && ($nVal >= 0); |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | /** |
| 217 | 217 | * @param $nVal |
| 218 | 218 | * @return bool |
| 219 | 219 | */ |
| 220 | - public function isValidRand( $nVal ) |
|
| 220 | + public function isValidRand($nVal) |
|
| 221 | 221 | { |
| 222 | - return is_numeric( $nVal ) && ( $nVal >= 0 ) && ( $nVal <= 0xFFF ); |
|
| 222 | + return is_numeric($nVal) && ($nVal >= 0) && ($nVal <= 0xFFF); |
|
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | */ |
| 231 | 231 | public function getUnixTimestamp() |
| 232 | 232 | { |
| 233 | - return floor( microtime( true ) * 1000 ); |
|
| 233 | + return floor(microtime(true) * 1000); |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | /** |
@@ -240,6 +240,6 @@ discard block |
||
| 240 | 240 | */ |
| 241 | 241 | public function getEscapedTime() |
| 242 | 242 | { |
| 243 | - return intval( $this->getUnixTimestamp() - self::EPOCH_OFFSET ); |
|
| 243 | + return intval($this->getUnixTimestamp() - self::EPOCH_OFFSET); |
|
| 244 | 244 | } |
| 245 | 245 | } |
@@ -99,8 +99,7 @@ |
||
| 99 | 99 | { |
| 100 | 100 | // use crc32 hash value instead of rand |
| 101 | 101 | $nRand = crc32( $sSource ); |
| 102 | - } |
|
| 103 | - else |
|
| 102 | + } else |
|
| 104 | 103 | { |
| 105 | 104 | // 0 ~ 4095 |
| 106 | 105 | $nRand = rand( 0, 0xFFF ); |
@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | /** |
| 4 | 4 | * Url |
| 5 | 5 | */ |
| 6 | -class UrlTool{ |
|
| 6 | +class UrlTool { |
|
| 7 | 7 | |
| 8 | 8 | /** |
| 9 | 9 | * 获取url中主域名 |
@@ -11,16 +11,16 @@ discard block |
||
| 11 | 11 | * @return string |
| 12 | 12 | */ |
| 13 | 13 | static public function getMainDomain($url) { |
| 14 | - $url = strtolower($url);//首先转成小写 |
|
| 14 | + $url = strtolower($url); //首先转成小写 |
|
| 15 | 15 | $host = parse_url($url, PHP_URL_HOST); // 获取host部分 |
| 16 | - if(empty($host)){ |
|
| 16 | + if (empty($host)) { |
|
| 17 | 17 | $url = "https://".$url; |
| 18 | - $host = parse_url($url,PHP_URL_HOST); |
|
| 18 | + $host = parse_url($url, PHP_URL_HOST); |
|
| 19 | 19 | } |
| 20 | 20 | if (!$host) { |
| 21 | 21 | return ''; |
| 22 | 22 | } |
| 23 | - if (in_array($host,['127.0.0.1','localhost'])) { |
|
| 23 | + if (in_array($host, ['127.0.0.1', 'localhost'])) { |
|
| 24 | 24 | return ''; |
| 25 | 25 | } |
| 26 | 26 | |
@@ -34,12 +34,12 @@ discard block |
||
| 34 | 34 | * 判断是否是双后缀aaa.com.cn |
| 35 | 35 | */ |
| 36 | 36 | $preg = '/[\w].+\.(com|net|org|gov|edu)\.cn$/'; |
| 37 | - if ($count > 2 && preg_match($preg,$host)){ |
|
| 37 | + if ($count > 2 && preg_match($preg, $host)) { |
|
| 38 | 38 | //双后缀取后3位 |
| 39 | - $host = $parts[$count-3].'.'.$parts[$count-2].'.'.$parts[$count-1]; |
|
| 40 | - } else{ |
|
| 39 | + $host = $parts[$count - 3].'.'.$parts[$count - 2].'.'.$parts[$count - 1]; |
|
| 40 | + } else { |
|
| 41 | 41 | // 如果只有两个部分,则直接返回整个host作为主域名 |
| 42 | - $host = $parts[$count-2].'.'.$parts[$count-1]; |
|
| 42 | + $host = $parts[$count - 2].'.'.$parts[$count - 1]; |
|
| 43 | 43 | } |
| 44 | 44 | return $host; |
| 45 | 45 | } |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace tinymeng\tools\async; |
| 3 | 3 | |
| 4 | -class AsyncHook{ |
|
| 4 | +class AsyncHook { |
|
| 5 | 5 | |
| 6 | 6 | /** |
| 7 | 7 | * @var array |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | public static function hook(callable $callback, $params) { |
| 22 | 22 | self::$hook_list[] = array('callback' => $callback, 'params' => $params); |
| 23 | - if(self::$hooked === false) { |
|
| 23 | + if (self::$hooked === false) { |
|
| 24 | 24 | self::$hooked = true; |
| 25 | 25 | //注册一个callback当前在脚本执行完后执行 |
| 26 | 26 | register_shutdown_function(array(__CLASS__, '__run')); |
@@ -33,10 +33,10 @@ discard block |
||
| 33 | 33 | */ |
| 34 | 34 | private static function __run() { |
| 35 | 35 | fastcgi_finish_request(); |
| 36 | - if(empty(self::$hook_list)) { |
|
| 36 | + if (empty(self::$hook_list)) { |
|
| 37 | 37 | return; |
| 38 | 38 | } |
| 39 | - foreach(self::$hook_list as $hook) { |
|
| 39 | + foreach (self::$hook_list as $hook) { |
|
| 40 | 40 | $callback = $hook['callback']; |
| 41 | 41 | $params = $hook['params']; |
| 42 | 42 | call_user_func_array($callback, $params); |
@@ -13,11 +13,11 @@ discard block |
||
| 13 | 13 | */ |
| 14 | 14 | private static $instance = null; |
| 15 | 15 | |
| 16 | - public function __construct($config=[]){ |
|
| 16 | + public function __construct($config = []) { |
|
| 17 | 17 | $this->config = $config; |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | - private function __clone(){} |
|
| 20 | + private function __clone() {} |
|
| 21 | 21 | |
| 22 | 22 | public function __sleep(): array |
| 23 | 23 | { |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | return []; |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | - protected static function init($gateway, $config=[]) |
|
| 28 | + protected static function init($gateway, $config = []) |
|
| 29 | 29 | { |
| 30 | 30 | if (!self::$instance instanceof static) { |
| 31 | 31 | self::$instance = new static($config); |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | *@author: JiaMeng <[email protected]> |
| 42 | 42 | * Updater: |
| 43 | 43 | */ |
| 44 | - public static function __callStatic($gateway, array $config=[]) |
|
| 44 | + public static function __callStatic($gateway, array $config = []) |
|
| 45 | 45 | { |
| 46 | 46 | return self::init($gateway, ...$config); |
| 47 | 47 | } |
@@ -21,7 +21,7 @@ |
||
| 21 | 21 | $this->setHeaders($headers); |
| 22 | 22 | |
| 23 | 23 | /** message */ |
| 24 | - if(empty($message)) $message = StatusCode::$status_code[$statusCode] ?? StatusCode::$status_code[StatusCode::COMMON_UNKNOWN]; |
|
| 24 | + if (empty($message)) $message = StatusCode::$status_code[$statusCode] ?? StatusCode::$status_code[StatusCode::COMMON_UNKNOWN]; |
|
| 25 | 25 | parent::__construct('ERROR tinymeng tools: '.$message, $code, $previous); |
| 26 | 26 | } |
| 27 | 27 | |
@@ -21,7 +21,9 @@ |
||
| 21 | 21 | $this->setHeaders($headers); |
| 22 | 22 | |
| 23 | 23 | /** message */ |
| 24 | - if(empty($message)) $message = StatusCode::$status_code[$statusCode] ?? StatusCode::$status_code[StatusCode::COMMON_UNKNOWN]; |
|
| 24 | + if(empty($message)) { |
|
| 25 | + $message = StatusCode::$status_code[$statusCode] ?? StatusCode::$status_code[StatusCode::COMMON_UNKNOWN]; |
|
| 26 | + } |
|
| 25 | 27 | parent::__construct('ERROR tinymeng tools: '.$message, $code, $previous); |
| 26 | 28 | } |
| 27 | 29 | |
@@ -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 | } |