@@ -19,11 +19,11 @@ |
||
| 19 | 19 | public static function getIp(){ |
| 20 | 20 | if(!empty($_SERVER["HTTP_CLIENT_IP"])){ |
| 21 | 21 | $cip = $_SERVER["HTTP_CLIENT_IP"]; |
| 22 | - }else if(!empty($_SERVER["HTTP_X_FORWARDED_FOR"])){ |
|
| 22 | + } else if(!empty($_SERVER["HTTP_X_FORWARDED_FOR"])){ |
|
| 23 | 23 | $cip = $_SERVER["HTTP_X_FORWARDED_FOR"]; |
| 24 | - }else if(!empty($_SERVER["REMOTE_ADDR"])){ |
|
| 24 | + } else if(!empty($_SERVER["REMOTE_ADDR"])){ |
|
| 25 | 25 | $cip = $_SERVER["REMOTE_ADDR"]; |
| 26 | - }else{ |
|
| 26 | + } else{ |
|
| 27 | 27 | $cip = ''; |
| 28 | 28 | } |
| 29 | 29 | preg_match("/[\d\.]{7,15}/", $cip, $cips); |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | * Description: Tool.php. |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | -class Tool{ |
|
| 11 | +class Tool { |
|
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | 14 | * Description: 获取ip |
@@ -16,14 +16,14 @@ discard block |
||
| 16 | 16 | * Updater: |
| 17 | 17 | * @return string |
| 18 | 18 | */ |
| 19 | - public static function getIp(){ |
|
| 20 | - if(!empty($_SERVER["HTTP_CLIENT_IP"])){ |
|
| 19 | + public static function getIp() { |
|
| 20 | + if (!empty($_SERVER["HTTP_CLIENT_IP"])) { |
|
| 21 | 21 | $cip = $_SERVER["HTTP_CLIENT_IP"]; |
| 22 | - }else if(!empty($_SERVER["HTTP_X_FORWARDED_FOR"])){ |
|
| 22 | + } else if (!empty($_SERVER["HTTP_X_FORWARDED_FOR"])) { |
|
| 23 | 23 | $cip = $_SERVER["HTTP_X_FORWARDED_FOR"]; |
| 24 | - }else if(!empty($_SERVER["REMOTE_ADDR"])){ |
|
| 24 | + } else if (!empty($_SERVER["REMOTE_ADDR"])) { |
|
| 25 | 25 | $cip = $_SERVER["REMOTE_ADDR"]; |
| 26 | - }else{ |
|
| 26 | + } else { |
|
| 27 | 27 | $cip = ''; |
| 28 | 28 | } |
| 29 | 29 | preg_match("/[\d\.]{7,15}/", $cip, $cips); |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | * Updater: |
| 40 | 40 | * @return string |
| 41 | 41 | */ |
| 42 | - public static function getOrigin(){ |
|
| 42 | + public static function getOrigin() { |
|
| 43 | 43 | $origin = ''; |
| 44 | 44 | if (isset($_SERVER['HTTP_X_ORIGINAL_FOR'])) { |
| 45 | 45 | $origin = $_SERVER['HTTP_X_ORIGINAL_FOR']; |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | 'mobile' |
| 105 | 105 | ); |
| 106 | 106 | // 从HTTP_USER_AGENT中查找手机浏览器的关键字 |
| 107 | - if (preg_match("/(" . implode('|', $clientKeyWords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT']))) { |
|
| 107 | + if (preg_match("/(".implode('|', $clientKeyWords).")/i", strtolower($_SERVER['HTTP_USER_AGENT']))) { |
|
| 108 | 108 | return true; |
| 109 | 109 | } |
| 110 | 110 | } |
@@ -19,10 +19,10 @@ discard block |
||
| 19 | 19 | */ |
| 20 | 20 | public $client; |
| 21 | 21 | |
| 22 | - static public function init(){ |
|
| 22 | + static public function init() { |
|
| 23 | 23 | $gateway = new self(); |
| 24 | 24 | |
| 25 | - $gateway->client = new ZipArchive(); |
|
| 25 | + $gateway->client = new ZipArchive(); |
|
| 26 | 26 | return $gateway; |
| 27 | 27 | } |
| 28 | 28 | |
@@ -33,29 +33,29 @@ discard block |
||
| 33 | 33 | * @author: Tinymeng <[email protected]> |
| 34 | 34 | * @time: 2022/4/27 9:26 |
| 35 | 35 | */ |
| 36 | - public function open($filename,$Fromfilename=null){ |
|
| 37 | - if (!empty($filename)){ |
|
| 36 | + public function open($filename, $Fromfilename = null) { |
|
| 37 | + if (!empty($filename)) { |
|
| 38 | 38 | $this->setFileName($filename); |
| 39 | - if(!$this->client->open($this->fileName, ZipArchive::CREATE)) |
|
| 39 | + if (!$this->client->open($this->fileName, ZipArchive::CREATE)) |
|
| 40 | 40 | return 'File open failed'; |
| 41 | 41 | } |
| 42 | - if(!empty($Fromfilename)){ |
|
| 43 | - if(is_dir($Fromfilename)){ |
|
| 42 | + if (!empty($Fromfilename)) { |
|
| 43 | + if (is_dir($Fromfilename)) { |
|
| 44 | 44 | $list_dir = scandir($Fromfilename); |
| 45 | - for($i=2;$i<count($list_dir);$i++){ |
|
| 46 | - if(is_dir($Fromfilename.'/'.$list_dir[$i])){ |
|
| 45 | + for ($i = 2; $i < count($list_dir); $i++) { |
|
| 46 | + if (is_dir($Fromfilename.'/'.$list_dir[$i])) { |
|
| 47 | 47 | $this->client->addGlob($Fromfilename.'/'.$list_dir[$i].'/*.*', 0, array('add_path' => $Fromfilename.'/'.$list_dir[$i].'/', 'remove_path' => $Fromfilename.'/'.$list_dir[$i])); |
| 48 | 48 | $list_chr = scandir($Fromfilename.'/'.$list_dir[$i]); |
| 49 | - for($j=2;$j<count($list_chr);$j++){ |
|
| 50 | - if(is_dir($Fromfilename.'/'.$list_dir[$i].'/'.$list_chr[$j])){ |
|
| 49 | + for ($j = 2; $j < count($list_chr); $j++) { |
|
| 50 | + if (is_dir($Fromfilename.'/'.$list_dir[$i].'/'.$list_chr[$j])) { |
|
| 51 | 51 | echo $list_chr[$j]; |
| 52 | - $this->open('',$Fromfilename.'/'.$list_dir[$i].'/'.$list_chr[$j]); |
|
| 52 | + $this->open('', $Fromfilename.'/'.$list_dir[$i].'/'.$list_chr[$j]); |
|
| 53 | 53 | } |
| 54 | 54 | } |
| 55 | 55 | } |
| 56 | 56 | } |
| 57 | - }else{ |
|
| 58 | - $this->client->addFile ($Fromfilename); |
|
| 57 | + } else { |
|
| 58 | + $this->client->addFile($Fromfilename); |
|
| 59 | 59 | } |
| 60 | 60 | } |
| 61 | 61 | return $this; |
@@ -68,9 +68,9 @@ discard block |
||
| 68 | 68 | * @author: Tinymeng <[email protected]> |
| 69 | 69 | * @time: 2022/4/27 9:26 |
| 70 | 70 | */ |
| 71 | - private function setFileName($filename){ |
|
| 72 | - if(!preg_match('/zip/m', $filename)){ |
|
| 73 | - $filename = $filename.'-'.date('Ymd').rand(111,999).'.zip'; |
|
| 71 | + private function setFileName($filename) { |
|
| 72 | + if (!preg_match('/zip/m', $filename)) { |
|
| 73 | + $filename = $filename.'-'.date('Ymd').rand(111, 999).'.zip'; |
|
| 74 | 74 | } |
| 75 | 75 | $this->fileName = $filename; |
| 76 | 76 | return $filename; |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | * @author: Tinymeng <[email protected]> |
| 83 | 83 | * @time: 2022/4/27 9:50 |
| 84 | 84 | */ |
| 85 | - public function getFileName(){ |
|
| 85 | + public function getFileName() { |
|
| 86 | 86 | return $this->fileName; |
| 87 | 87 | } |
| 88 | 88 | |
@@ -94,8 +94,8 @@ discard block |
||
| 94 | 94 | * @author: Tinymeng <[email protected]> |
| 95 | 95 | * @time: 2022/4/27 9:31 |
| 96 | 96 | */ |
| 97 | - public function addFileContent($file_name,$content){ |
|
| 98 | - $this->client->addFromString($file_name,$content); |
|
| 97 | + public function addFileContent($file_name, $content) { |
|
| 98 | + $this->client->addFromString($file_name, $content); |
|
| 99 | 99 | return $this; |
| 100 | 100 | } |
| 101 | 101 | |
@@ -107,8 +107,8 @@ discard block |
||
| 107 | 107 | * @author: Tinymeng <[email protected]> |
| 108 | 108 | * @time: 2022/4/27 9:31 |
| 109 | 109 | */ |
| 110 | - public function addFile($file_name,$content){ |
|
| 111 | - $this->client->addFromString($file_name,$content); |
|
| 110 | + public function addFile($file_name, $content) { |
|
| 111 | + $this->client->addFromString($file_name, $content); |
|
| 112 | 112 | return $this; |
| 113 | 113 | } |
| 114 | 114 | |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | * 文件下载 |
| 117 | 117 | * @return void |
| 118 | 118 | */ |
| 119 | - public function download(){ |
|
| 119 | + public function download() { |
|
| 120 | 120 | $this->client->finish(); |
| 121 | 121 | } |
| 122 | 122 | |
@@ -128,17 +128,17 @@ discard block |
||
| 128 | 128 | * @author: Tinymeng <[email protected]> |
| 129 | 129 | * @time: 2022/4/27 9:38 |
| 130 | 130 | */ |
| 131 | - public function unzip($filename,$dir){ |
|
| 132 | - if(!file_exists($filename)) |
|
| 131 | + public function unzip($filename, $dir) { |
|
| 132 | + if (!file_exists($filename)) |
|
| 133 | 133 | return 'File does not exist'; |
| 134 | - if(!$this->client->open($filename)) |
|
| 134 | + if (!$this->client->open($filename)) |
|
| 135 | 135 | return 'File open failed'; |
| 136 | - if(!is_dir($dir)){ |
|
| 137 | - mkdir($dir,775); |
|
| 138 | - }else{ |
|
| 136 | + if (!is_dir($dir)) { |
|
| 137 | + mkdir($dir, 775); |
|
| 138 | + } else { |
|
| 139 | 139 | return 'Dir mk failed'; |
| 140 | 140 | } |
| 141 | - if(!$this->client->extractTo($dir)) |
|
| 141 | + if (!$this->client->extractTo($dir)) |
|
| 142 | 142 | return 'File unzip failed'; |
| 143 | 143 | return $this; |
| 144 | 144 | } |
@@ -36,8 +36,9 @@ discard block |
||
| 36 | 36 | public function open($filename,$Fromfilename=null){ |
| 37 | 37 | if (!empty($filename)){ |
| 38 | 38 | $this->setFileName($filename); |
| 39 | - if(!$this->client->open($this->fileName, ZipArchive::CREATE)) |
|
| 40 | - return 'File open failed'; |
|
| 39 | + if(!$this->client->open($this->fileName, ZipArchive::CREATE)) { |
|
| 40 | + return 'File open failed'; |
|
| 41 | + } |
|
| 41 | 42 | } |
| 42 | 43 | if(!empty($Fromfilename)){ |
| 43 | 44 | if(is_dir($Fromfilename)){ |
@@ -54,7 +55,7 @@ discard block |
||
| 54 | 55 | } |
| 55 | 56 | } |
| 56 | 57 | } |
| 57 | - }else{ |
|
| 58 | + } else{ |
|
| 58 | 59 | $this->client->addFile ($Fromfilename); |
| 59 | 60 | } |
| 60 | 61 | } |
@@ -129,17 +130,20 @@ discard block |
||
| 129 | 130 | * @time: 2022/4/27 9:38 |
| 130 | 131 | */ |
| 131 | 132 | public function unzip($filename,$dir){ |
| 132 | - if(!file_exists($filename)) |
|
| 133 | - return 'File does not exist'; |
|
| 134 | - if(!$this->client->open($filename)) |
|
| 135 | - return 'File open failed'; |
|
| 133 | + if(!file_exists($filename)) { |
|
| 134 | + return 'File does not exist'; |
|
| 135 | + } |
|
| 136 | + if(!$this->client->open($filename)) { |
|
| 137 | + return 'File open failed'; |
|
| 138 | + } |
|
| 136 | 139 | if(!is_dir($dir)){ |
| 137 | 140 | mkdir($dir,775); |
| 138 | - }else{ |
|
| 141 | + } else{ |
|
| 139 | 142 | return 'Dir mk failed'; |
| 140 | 143 | } |
| 141 | - if(!$this->client->extractTo($dir)) |
|
| 142 | - return 'File unzip failed'; |
|
| 144 | + if(!$this->client->extractTo($dir)) { |
|
| 145 | + return 'File unzip failed'; |
|
| 146 | + } |
|
| 143 | 147 | return $this; |
| 144 | 148 | } |
| 145 | 149 | |
@@ -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 | } |
@@ -18,10 +18,10 @@ |
||
| 18 | 18 | |
| 19 | 19 | public function __construct(int $statusCode, string $message = '', Exception $previous = null, array $headers = [], $code = 0) |
| 20 | 20 | { |
| 21 | - $this->headers = $headers; |
|
| 21 | + $this->headers = $headers; |
|
| 22 | 22 | |
| 23 | 23 | /** message */ |
| 24 | - if(empty($message)) $message = isset(StatusCode::$status_code[$statusCode]) ? StatusCode::$status_code[$statusCode] :StatusCode::$status_code[StatusCode::COMMON_UNKNOWN]; |
|
| 24 | + if (empty($message)) $message = isset(StatusCode::$status_code[$statusCode]) ? StatusCode::$status_code[$statusCode] : StatusCode::$status_code[StatusCode::COMMON_UNKNOWN]; |
|
| 25 | 25 | parent::__construct('ERROR_TINYMENG_TOOL: '.$message, $code, $previous); |
| 26 | 26 | } |
| 27 | 27 | |
@@ -21,7 +21,9 @@ |
||
| 21 | 21 | $this->headers = $headers; |
| 22 | 22 | |
| 23 | 23 | /** message */ |
| 24 | - if(empty($message)) $message = isset(StatusCode::$status_code[$statusCode]) ? StatusCode::$status_code[$statusCode] :StatusCode::$status_code[StatusCode::COMMON_UNKNOWN]; |
|
| 24 | + if(empty($message)) { |
|
| 25 | + $message = isset(StatusCode::$status_code[$statusCode]) ? StatusCode::$status_code[$statusCode] :StatusCode::$status_code[StatusCode::COMMON_UNKNOWN]; |
|
| 26 | + } |
|
| 25 | 27 | parent::__construct('ERROR_TINYMENG_TOOL: '.$message, $code, $previous); |
| 26 | 28 | } |
| 27 | 29 | |
@@ -33,19 +33,19 @@ discard block |
||
| 33 | 33 | * @return mixed |
| 34 | 34 | * @throws \Exception |
| 35 | 35 | */ |
| 36 | - static public function httpPost($url, $param = array(), $httpHeaders = array(),$proxy='', $http_code = null) |
|
| 36 | + static public function httpPost($url, $param = array(), $httpHeaders = array(), $proxy = '', $http_code = null) |
|
| 37 | 37 | { |
| 38 | 38 | /** 参数检测,object或者array进行http_build_query */ |
| 39 | - if(!empty($param) && is_array($param)){ |
|
| 39 | + if (!empty($param) && is_array($param)) { |
|
| 40 | 40 | $flag = false; |
| 41 | - foreach ($param as $value){ |
|
| 41 | + foreach ($param as $value) { |
|
| 42 | 42 | //判断参数是否是一个对象 或者 是一个数组 |
| 43 | - if(is_array($value) || (is_string($value) && is_object($value))){ |
|
| 43 | + if (is_array($value) || (is_string($value) && is_object($value))) { |
|
| 44 | 44 | $flag = true; |
| 45 | 45 | break; |
| 46 | 46 | } |
| 47 | 47 | } |
| 48 | - if($flag == true){ |
|
| 48 | + if ($flag == true) { |
|
| 49 | 49 | $param = http_build_query($param); |
| 50 | 50 | } |
| 51 | 51 | } |
@@ -62,12 +62,12 @@ discard block |
||
| 62 | 62 | curl_setopt($curl, CURLOPT_POSTFIELDS, $param); |
| 63 | 63 | |
| 64 | 64 | /** 设置请求headers */ |
| 65 | - if(empty($httpHeaders)){ |
|
| 65 | + if (empty($httpHeaders)) { |
|
| 66 | 66 | $httpHeaders = array( |
| 67 | 67 | "user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36" |
| 68 | 68 | ); |
| 69 | 69 | } |
| 70 | - if (is_array($httpHeaders)){ |
|
| 70 | + if (is_array($httpHeaders)) { |
|
| 71 | 71 | curl_setopt($curl, CURLOPT_HTTPHEADER, $httpHeaders); |
| 72 | 72 | } |
| 73 | 73 | /** gzip压缩 */ |
@@ -81,11 +81,11 @@ discard block |
||
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | /** http代理 */ |
| 84 | - if(!empty($proxy)){ |
|
| 85 | - $proxy = explode(':',$proxy); |
|
| 84 | + if (!empty($proxy)) { |
|
| 85 | + $proxy = explode(':', $proxy); |
|
| 86 | 86 | curl_setopt($curl, CURLOPT_PROXYAUTH, CURLAUTH_BASIC); //代理认证模式 |
| 87 | 87 | curl_setopt($curl, CURLOPT_PROXY, "$proxy[0]"); //代理服务器地址 |
| 88 | - curl_setopt($curl, CURLOPT_PROXYPORT,$proxy[1]); //代理服务器端口 |
|
| 88 | + curl_setopt($curl, CURLOPT_PROXYPORT, $proxy[1]); //代理服务器端口 |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | /** 请求 */ |
@@ -95,20 +95,20 @@ discard block |
||
| 95 | 95 | /** 关闭请求资源 */ |
| 96 | 96 | curl_close($curl); |
| 97 | 97 | |
| 98 | - if($http_code != null){ |
|
| 98 | + if ($http_code != null) { |
|
| 99 | 99 | /** 验证网络请求状态 */ |
| 100 | 100 | if (intval($info["http_code"]) === 0) { |
| 101 | 101 | throw new TException(StatusCode::COMMON_TINYMENG_REQUEST_METHOD, |
| 102 | - '[httpPost]: POST request was aborted ! Request url :' . $url . ' , post request data : ' . var_export($param,true) |
|
| 102 | + '[httpPost]: POST request was aborted ! Request url :'.$url.' , post request data : '.var_export($param, true) |
|
| 103 | 103 | ); |
| 104 | - }elseif(intval($info["http_code"]) != $http_code){ |
|
| 104 | + }elseif (intval($info["http_code"]) != $http_code) { |
|
| 105 | 105 | throw new TException(StatusCode::COMMON_TINYMENG_REQUEST_METHOD, |
| 106 | - '[httpPost]: POST request was aborted ! Request url :' . $url . ' , post request data : ' . var_export($param,true).' ,return code : '.$info["http_code"] .' ,return content : '.$content |
|
| 106 | + '[httpPost]: POST request was aborted ! Request url :'.$url.' , post request data : '.var_export($param, true).' ,return code : '.$info["http_code"].' ,return content : '.$content |
|
| 107 | 107 | ); |
| 108 | 108 | } else { |
| 109 | 109 | return $content; |
| 110 | 110 | } |
| 111 | - }else{ |
|
| 111 | + } else { |
|
| 112 | 112 | return $content; |
| 113 | 113 | } |
| 114 | 114 | } |
@@ -125,13 +125,13 @@ discard block |
||
| 125 | 125 | * @return mixed |
| 126 | 126 | * @throws \Exception |
| 127 | 127 | */ |
| 128 | - static public function httpGet($url, $param = array(), $httpHeaders = array(),$proxy= '', $http_code = 200) |
|
| 128 | + static public function httpGet($url, $param = array(), $httpHeaders = array(), $proxy = '', $http_code = 200) |
|
| 129 | 129 | { |
| 130 | 130 | $curl = curl_init(); |
| 131 | 131 | |
| 132 | 132 | /** 设置请求参数 */ |
| 133 | 133 | if (!empty($param)) { |
| 134 | - $url = $url . '?' . http_build_query($param); |
|
| 134 | + $url = $url.'?'.http_build_query($param); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | /** 设置请求链接 */ |
@@ -147,20 +147,20 @@ discard block |
||
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** http代理 */ |
| 150 | - if(!empty($proxy)){ |
|
| 151 | - $proxy = explode(':',$proxy); |
|
| 150 | + if (!empty($proxy)) { |
|
| 151 | + $proxy = explode(':', $proxy); |
|
| 152 | 152 | curl_setopt($curl, CURLOPT_PROXYAUTH, CURLAUTH_BASIC); //代理认证模式 |
| 153 | 153 | curl_setopt($curl, CURLOPT_PROXY, "$proxy[0]"); //代理服务器地址 |
| 154 | - curl_setopt($curl, CURLOPT_PROXYPORT,$proxy[1]); //代理服务器端口 |
|
| 154 | + curl_setopt($curl, CURLOPT_PROXYPORT, $proxy[1]); //代理服务器端口 |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /** 设置请求headers */ |
| 158 | - if(empty($httpHeaders)){ |
|
| 158 | + if (empty($httpHeaders)) { |
|
| 159 | 159 | $httpHeaders = array( |
| 160 | 160 | "user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36" |
| 161 | 161 | ); |
| 162 | 162 | } |
| 163 | - if (is_array($httpHeaders)){ |
|
| 163 | + if (is_array($httpHeaders)) { |
|
| 164 | 164 | curl_setopt($curl, CURLOPT_HTTPHEADER, $httpHeaders); |
| 165 | 165 | } |
| 166 | 166 | /** gzip压缩 */ |
@@ -174,19 +174,19 @@ discard block |
||
| 174 | 174 | curl_close($curl); |
| 175 | 175 | |
| 176 | 176 | /** 验证网络请求状态 */ |
| 177 | - if($http_code != null){ |
|
| 177 | + if ($http_code != null) { |
|
| 178 | 178 | if (intval($info["http_code"]) === 0) { |
| 179 | 179 | throw new TException(StatusCode::COMMON_TINYMENG_REQUEST_METHOD, |
| 180 | - '[httpGet]: GET request was aborted ! Request url :' . $url |
|
| 180 | + '[httpGet]: GET request was aborted ! Request url :'.$url |
|
| 181 | 181 | ); |
| 182 | - }elseif(intval($info["http_code"]) != $http_code){ |
|
| 182 | + }elseif (intval($info["http_code"]) != $http_code) { |
|
| 183 | 183 | throw new TException(StatusCode::COMMON_TINYMENG_REQUEST_METHOD, |
| 184 | - '[httpGet]: GET request was aborted ! Request url :' . $url .' ,return code : '.$info["http_code"] .' ,return content : '.$content |
|
| 184 | + '[httpGet]: GET request was aborted ! Request url :'.$url.' ,return code : '.$info["http_code"].' ,return content : '.$content |
|
| 185 | 185 | ); |
| 186 | 186 | } else { |
| 187 | 187 | return $content; |
| 188 | 188 | } |
| 189 | - }else{ |
|
| 189 | + } else { |
|
| 190 | 190 | return $content; |
| 191 | 191 | } |
| 192 | 192 | } |
@@ -101,14 +101,14 @@ discard block |
||
| 101 | 101 | throw new TException(StatusCode::COMMON_TINYMENG_REQUEST_METHOD, |
| 102 | 102 | '[httpPost]: POST request was aborted ! Request url :' . $url . ' , post request data : ' . var_export($param,true) |
| 103 | 103 | ); |
| 104 | - }elseif(intval($info["http_code"]) != $http_code){ |
|
| 104 | + } elseif(intval($info["http_code"]) != $http_code){ |
|
| 105 | 105 | throw new TException(StatusCode::COMMON_TINYMENG_REQUEST_METHOD, |
| 106 | 106 | '[httpPost]: POST request was aborted ! Request url :' . $url . ' , post request data : ' . var_export($param,true).' ,return code : '.$info["http_code"] .' ,return content : '.$content |
| 107 | 107 | ); |
| 108 | 108 | } else { |
| 109 | 109 | return $content; |
| 110 | 110 | } |
| 111 | - }else{ |
|
| 111 | + } else{ |
|
| 112 | 112 | return $content; |
| 113 | 113 | } |
| 114 | 114 | } |
@@ -179,14 +179,14 @@ discard block |
||
| 179 | 179 | throw new TException(StatusCode::COMMON_TINYMENG_REQUEST_METHOD, |
| 180 | 180 | '[httpGet]: GET request was aborted ! Request url :' . $url |
| 181 | 181 | ); |
| 182 | - }elseif(intval($info["http_code"]) != $http_code){ |
|
| 182 | + } elseif(intval($info["http_code"]) != $http_code){ |
|
| 183 | 183 | throw new TException(StatusCode::COMMON_TINYMENG_REQUEST_METHOD, |
| 184 | 184 | '[httpGet]: GET request was aborted ! Request url :' . $url .' ,return code : '.$info["http_code"] .' ,return content : '.$content |
| 185 | 185 | ); |
| 186 | 186 | } else { |
| 187 | 187 | return $content; |
| 188 | 188 | } |
| 189 | - }else{ |
|
| 189 | + } else{ |
|
| 190 | 190 | return $content; |
| 191 | 191 | } |
| 192 | 192 | } |