@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | // | Packagist 地址 :https://packagist.org/packages/liguangchun/think-library |
| 18 | 18 | // +---------------------------------------------------------------------- |
| 19 | 19 | |
| 20 | -declare (strict_types=1); |
|
| 20 | +declare(strict_types=1); |
|
| 21 | 21 | |
| 22 | 22 | namespace DtApp\ThinkLibrary\helper; |
| 23 | 23 | |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | 'openwave', 'nexusone', 'cldc', 'midp', 'wap', 'mobile', 'alipay' |
| 130 | 130 | ]; |
| 131 | 131 | // 从HTTP_USER_AGENT中查找手机浏览器的关键字 |
| 132 | - if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower(request()->server('HTTP_USER_AGENT')))) { |
|
| 132 | + if (preg_match("/(".implode('|', $clientkeywords).")/i", strtolower(request()->server('HTTP_USER_AGENT')))) { |
|
| 133 | 133 | return true; |
| 134 | 134 | } |
| 135 | 135 | } |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | $agent = strtolower(request()->server('HTTP_USER_AGENT')); |
| 202 | 202 | if (strpos($agent, 'iphone') || strpos($agent, 'ipad') || strpos($agent, 'android')) { |
| 203 | 203 | $type = 'mobile'; |
| 204 | - } else { |
|
| 204 | + }else { |
|
| 205 | 205 | $type = 'computer'; |
| 206 | 206 | } |
| 207 | 207 | return $type; |
@@ -231,6 +231,6 @@ discard block |
||
| 231 | 231 | public function getWebsiteAddress(): string |
| 232 | 232 | { |
| 233 | 233 | $http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https')) ? 'https://' : 'http://'; |
| 234 | - return $http_type . $_SERVER['HTTP_HOST'] . "/"; |
|
| 234 | + return $http_type.$_SERVER['HTTP_HOST']."/"; |
|
| 235 | 235 | } |
| 236 | 236 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | // | Packagist 地址 :https://packagist.org/packages/liguangchun/think-library |
| 18 | 18 | // +---------------------------------------------------------------------- |
| 19 | 19 | |
| 20 | -declare (strict_types=1); |
|
| 20 | +declare(strict_types=1); |
|
| 21 | 21 | |
| 22 | 22 | namespace DtApp\ThinkLibrary\helper; |
| 23 | 23 | |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | $buff = ""; |
| 65 | 65 | foreach ($data as $k => $v) { |
| 66 | 66 | if ($k !== "sign" && $v !== "" && !is_array($v)) { |
| 67 | - $buff .= $k . "=" . $v . "&"; |
|
| 67 | + $buff .= $k."=".$v."&"; |
|
| 68 | 68 | } |
| 69 | 69 | } |
| 70 | 70 | $buff = trim($buff, "&"); |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | // | Packagist 地址 :https://packagist.org/packages/liguangchun/think-library |
| 18 | 18 | // +---------------------------------------------------------------------- |
| 19 | 19 | |
| 20 | -declare (strict_types=1); |
|
| 20 | +declare(strict_types=1); |
|
| 21 | 21 | |
| 22 | 22 | namespace DtApp\ThinkLibrary\helper; |
| 23 | 23 | |
@@ -67,10 +67,10 @@ discard block |
||
| 67 | 67 | $dh = opendir($name); |
| 68 | 68 | while ($file = readdir($dh)) { |
| 69 | 69 | if ($file !== "." && $file !== "..") { |
| 70 | - $fullpath = $name . "/" . $file; |
|
| 70 | + $fullpath = $name."/".$file; |
|
| 71 | 71 | if (!is_dir($fullpath)) { |
| 72 | 72 | unlink($fullpath); |
| 73 | - } else { |
|
| 73 | + }else { |
|
| 74 | 74 | $this->deletes($fullpath); |
| 75 | 75 | } |
| 76 | 76 | } |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | if (empty($name)) { |
| 98 | 98 | throw new DtaException('请检查需要打包的路径名称'); |
| 99 | 99 | } |
| 100 | - $list = glob($name . "{$file_name}.{$suffix_name}"); |
|
| 100 | + $list = glob($name."{$file_name}.{$suffix_name}"); |
|
| 101 | 101 | $fileList = $list; |
| 102 | 102 | $zip = new ZipArchive(); |
| 103 | 103 | // 打开压缩包 |
@@ -120,13 +120,13 @@ discard block |
||
| 120 | 120 | { |
| 121 | 121 | $files = []; |
| 122 | 122 | if (is_dir($path)) { |
| 123 | - $path = dirname($path) . '/' . basename($path) . '/'; |
|
| 123 | + $path = dirname($path).'/'.basename($path).'/'; |
|
| 124 | 124 | $file = dir($path); |
| 125 | 125 | while (false !== ($entry = $file->read())) { |
| 126 | 126 | if ($entry !== '.' && $entry !== '..') { |
| 127 | - $cur = $path . $entry; |
|
| 127 | + $cur = $path.$entry; |
|
| 128 | 128 | if (is_dir($cur)) { |
| 129 | - $subPath = $cur . '/'; |
|
| 129 | + $subPath = $cur.'/'; |
|
| 130 | 130 | $this->getFiles($subPath); |
| 131 | 131 | } |
| 132 | 132 | $files[] = $cur; |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | // | Packagist 地址 :https://packagist.org/packages/liguangchun/think-library |
| 18 | 18 | // +---------------------------------------------------------------------- |
| 19 | 19 | |
| 20 | -declare (strict_types=1); |
|
| 20 | +declare(strict_types=1); |
|
| 21 | 21 | |
| 22 | 22 | namespace DtApp\ThinkLibrary\helper; |
| 23 | 23 | |
@@ -58,13 +58,13 @@ discard block |
||
| 58 | 58 | $charset = array_merge($lowerLetter, $upperLetter); |
| 59 | 59 | } elseif ($type === 7) { |
| 60 | 60 | $charset = array_merge($number, $lowerLetter, $upperLetter); |
| 61 | - } else { |
|
| 61 | + }else { |
|
| 62 | 62 | $charset = $number; |
| 63 | 63 | } |
| 64 | 64 | $str = ''; |
| 65 | 65 | // 生成字符串 |
| 66 | 66 | for ($i = 0; $i < $length; $i++) { |
| 67 | - $str .= $charset[random_int(0, count($charset) - 1)]; |
|
| 67 | + $str .= $charset[random_int(0, count($charset)-1)]; |
|
| 68 | 68 | // 验证规则 |
| 69 | 69 | if ($type === 4 && strlen($str) >= 2) { |
| 70 | 70 | if (!preg_match('/\d+/', $str) || !preg_match('/[a-z]+/', $str)) { |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | { |
| 244 | 244 | //组织参数 |
| 245 | 245 | $strParam = $this->createStrParam(); |
| 246 | - $result = file_get_contents($this->api_url . "?{$strParam}"); |
|
| 246 | + $result = file_get_contents($this->api_url."?{$strParam}"); |
|
| 247 | 247 | $result = json_decode($result, true); |
| 248 | 248 | $this->output = $result; |
| 249 | 249 | } |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | $strParam = ''; |
| 258 | 258 | foreach ($this->param as $key => $val) { |
| 259 | 259 | if ($key !== '' && $val !== '') { |
| 260 | - $strParam .= $key . '=' . urlencode($val) . '&'; |
|
| 260 | + $strParam .= $key.'='.urlencode($val).'&'; |
|
| 261 | 261 | } |
| 262 | 262 | } |
| 263 | 263 | return $strParam; |
@@ -210,8 +210,8 @@ |
||
| 210 | 210 | //生成签名 |
| 211 | 211 | $sign = $this->createSign(); |
| 212 | 212 | //组织参数 |
| 213 | - $this->param .= '&userkey=' . $sign; |
|
| 214 | - $url = "http://" . $this->api . "/" . $this->method . ".do?{$this->param}"; |
|
| 213 | + $this->param .= '&userkey='.$sign; |
|
| 214 | + $url = "http://".$this->api."/".$this->method.".do?{$this->param}"; |
|
| 215 | 215 | $result = file_get_contents($url); |
| 216 | 216 | $result = Xmls::toArray($result); |
| 217 | 217 | $this->output = $result; |
@@ -311,7 +311,7 @@ discard block |
||
| 311 | 311 | { |
| 312 | 312 | if (is_object($object)) { |
| 313 | 313 | $arr = (array)($object); |
| 314 | - } else { |
|
| 314 | + }else { |
|
| 315 | 315 | $arr = &$object; |
| 316 | 316 | } |
| 317 | 317 | if (is_array($arr)) { |
@@ -345,8 +345,8 @@ discard block |
||
| 345 | 345 | $recToken = $auth->authorizationV2($this->url, $this->method, json_encode($this->param), $this->contentType); |
| 346 | 346 | $rtcToken['Content-Type'] = $this->contentType; |
| 347 | 347 | dump($recToken); |
| 348 | - dump($this->url . "?" . http_build_query($this->param)); |
|
| 349 | - $ret = Client::get($this->url . "?" . http_build_query($this->param), $recToken); |
|
| 348 | + dump($this->url."?".http_build_query($this->param)); |
|
| 349 | + $ret = Client::get($this->url."?".http_build_query($this->param), $recToken); |
|
| 350 | 350 | dump($ret); |
| 351 | 351 | $this->output = $ret->json(); |
| 352 | 352 | return $this; |
@@ -362,7 +362,7 @@ discard block |
||
| 362 | 362 | $url = parse_url($this->url); |
| 363 | 363 | $data = $url['path'] ?? ''; |
| 364 | 364 | if (isset($url['query'])) { |
| 365 | - $data .= '?' . $url['query']; |
|
| 365 | + $data .= '?'.$url['query']; |
|
| 366 | 366 | } |
| 367 | 367 | $data .= "\n"; |
| 368 | 368 | if (isset($this->param) && $this->contentType === 'application/x-www-form-urlencoded') { |
@@ -378,7 +378,7 @@ discard block |
||
| 378 | 378 | private function sign($data) |
| 379 | 379 | { |
| 380 | 380 | $sign = hash_hmac('sha1', $data, $this->secretKey, true); |
| 381 | - return "Qiniu " . sprintf('%s:%s', $this->accessKey, $this->encode($sign)); |
|
| 381 | + return "Qiniu ".sprintf('%s:%s', $this->accessKey, $this->encode($sign)); |
|
| 382 | 382 | } |
| 383 | 383 | |
| 384 | 384 | /** |
@@ -167,12 +167,12 @@ |
||
| 167 | 167 | //设置单元格内容 |
| 168 | 168 | foreach ($this->head as $key => $value) { |
| 169 | 169 | foreach ($value as $k => $v) { |
| 170 | - $sheet->setCellValueByColumnAndRow($v['index'], $key + 1, $v['value']); |
|
| 170 | + $sheet->setCellValueByColumnAndRow($v['index'], $key+1, $v['value']); |
|
| 171 | 171 | } |
| 172 | 172 | } |
| 173 | 173 | foreach ($this->content as $key => $value) { |
| 174 | 174 | foreach ($value as $k => $v) { |
| 175 | - $sheet->setCellValueByColumnAndRow($v['index'], $key + $this->head_length, $v['value']); |
|
| 175 | + $sheet->setCellValueByColumnAndRow($v['index'], $key+$this->head_length, $v['value']); |
|
| 176 | 176 | } |
| 177 | 177 | } |
| 178 | 178 | $writer = new Xlsx($spreadsheet); |
@@ -68,10 +68,10 @@ discard block |
||
| 68 | 68 | public function __construct(App $app) |
| 69 | 69 | { |
| 70 | 70 | $this->fp = 0; |
| 71 | - if (($this->fp = fopen(__DIR__ . '/bin/qqwry.dat', 'rb')) !== false) { |
|
| 71 | + if (($this->fp = fopen(__DIR__.'/bin/qqwry.dat', 'rb')) !== false) { |
|
| 72 | 72 | $this->firstIp = $this->getLong(); |
| 73 | 73 | $this->lastIp = $this->getLong(); |
| 74 | - $this->totalIp = ($this->lastIp - $this->firstIp) / 7; |
|
| 74 | + $this->totalIp = ($this->lastIp-$this->firstIp)/7; |
|
| 75 | 75 | } |
| 76 | 76 | parent::__construct($app); |
| 77 | 77 | } |
@@ -152,49 +152,49 @@ discard block |
||
| 152 | 152 | // 如果数据文件没有被正确打开,则直接返回错误 |
| 153 | 153 | throw new DtaException('数据库文件不存在!'); |
| 154 | 154 | } |
| 155 | - $location['ip'] = $ip; // 将输入的域名转化为IP地址 |
|
| 156 | - $ip = $this->packIp($location['ip']); // 将输入的IP地址转化为可比较的IP地址 |
|
| 155 | + $location['ip'] = $ip; // 将输入的域名转化为IP地址 |
|
| 156 | + $ip = $this->packIp($location['ip']); // 将输入的IP地址转化为可比较的IP地址 |
|
| 157 | 157 | // 不合法的IP地址会被转化为255.255.255.255 |
| 158 | 158 | // 对分搜索 |
| 159 | - $l = 0; // 搜索的下边界 |
|
| 160 | - $u = $this->totalIp; // 搜索的上边界 |
|
| 161 | - $findip = $this->lastIp; // 如果没有找到就返回最后一条IP记录(QQWry.Dat的版本信息) |
|
| 159 | + $l = 0; // 搜索的下边界 |
|
| 160 | + $u = $this->totalIp; // 搜索的上边界 |
|
| 161 | + $findip = $this->lastIp; // 如果没有找到就返回最后一条IP记录(QQWry.Dat的版本信息) |
|
| 162 | 162 | while ($l <= $u) { // 当上边界小于下边界时,查找失败 |
| 163 | - $i = floor(($l + $u) / 2); // 计算近似中间记录 |
|
| 164 | - fseek($this->fp, $this->firstIp + $i * 7); |
|
| 165 | - $beginip = strrev(fread($this->fp, 4)); // 获取中间记录的开始IP地址 |
|
| 163 | + $i = floor(($l+$u)/2); // 计算近似中间记录 |
|
| 164 | + fseek($this->fp, $this->firstIp+$i*7); |
|
| 165 | + $beginip = strrev(fread($this->fp, 4)); // 获取中间记录的开始IP地址 |
|
| 166 | 166 | // strrev函数在这里的作用是将little-endian的压缩IP地址转化为big-endian的格式 |
| 167 | 167 | // 以便用于比较,后面相同。 |
| 168 | 168 | if ($ip < $beginip) { // 用户的IP小于中间记录的开始IP地址时 |
| 169 | - $u = $i - 1; // 将搜索的上边界修改为中间记录减一 |
|
| 170 | - } else { |
|
| 169 | + $u = $i-1; // 将搜索的上边界修改为中间记录减一 |
|
| 170 | + }else { |
|
| 171 | 171 | fseek($this->fp, $this->getLong3()); |
| 172 | - $endip = strrev(fread($this->fp, 4)); // 获取中间记录的结束IP地址 |
|
| 172 | + $endip = strrev(fread($this->fp, 4)); // 获取中间记录的结束IP地址 |
|
| 173 | 173 | if ($ip > $endip) { // 用户的IP大于中间记录的结束IP地址时 |
| 174 | - $l = $i + 1; // 将搜索的下边界修改为中间记录加一 |
|
| 175 | - } else { // 用户的IP在中间记录的IP范围内时 |
|
| 176 | - $findip = $this->firstIp + $i * 7; |
|
| 177 | - break; // 则表示找到结果,退出循环 |
|
| 174 | + $l = $i+1; // 将搜索的下边界修改为中间记录加一 |
|
| 175 | + }else { // 用户的IP在中间记录的IP范围内时 |
|
| 176 | + $findip = $this->firstIp+$i*7; |
|
| 177 | + break; // 则表示找到结果,退出循环 |
|
| 178 | 178 | } |
| 179 | 179 | } |
| 180 | 180 | } |
| 181 | 181 | //获取查找到的IP地理位置信息 |
| 182 | 182 | fseek($this->fp, $findip); |
| 183 | - $location['beginip'] = long2ip($this->getLong()); // 用户IP所在范围的开始地址 |
|
| 183 | + $location['beginip'] = long2ip($this->getLong()); // 用户IP所在范围的开始地址 |
|
| 184 | 184 | $offset = $this->getLong3(); |
| 185 | 185 | fseek($this->fp, $offset); |
| 186 | - $location['endip'] = long2ip($this->getLong()); // 用户IP所在范围的结束地址 |
|
| 187 | - $byte = fread($this->fp, 1); // 标志字节 |
|
| 186 | + $location['endip'] = long2ip($this->getLong()); // 用户IP所在范围的结束地址 |
|
| 187 | + $byte = fread($this->fp, 1); // 标志字节 |
|
| 188 | 188 | switch (ord($byte)) { |
| 189 | 189 | case 1: // 标志字节为1,表示国家和区域信息都被同时重定向 |
| 190 | - $countryOffset = $this->getLong3(); // 重定向地址 |
|
| 190 | + $countryOffset = $this->getLong3(); // 重定向地址 |
|
| 191 | 191 | fseek($this->fp, $countryOffset); |
| 192 | - $byte = fread($this->fp, 1); // 标志字节 |
|
| 192 | + $byte = fread($this->fp, 1); // 标志字节 |
|
| 193 | 193 | switch (ord($byte)) { |
| 194 | 194 | case 2: // 标志字节为2,表示国家信息又被重定向 |
| 195 | 195 | fseek($this->fp, $this->getLong3()); |
| 196 | 196 | $location['all'] = $this->getString(); |
| 197 | - fseek($this->fp, $countryOffset + 4); |
|
| 197 | + fseek($this->fp, $countryOffset+4); |
|
| 198 | 198 | $location['extend'] = $this->getExtendString(); |
| 199 | 199 | break; |
| 200 | 200 | default: // 否则,表示国家信息没有被重定向 |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | case 2: // 标志字节为2,表示国家信息被重定向 |
| 207 | 207 | fseek($this->fp, $this->getLong3()); |
| 208 | 208 | $location['all'] = $this->getString(); |
| 209 | - fseek($this->fp, $offset + 8); |
|
| 209 | + fseek($this->fp, $offset+8); |
|
| 210 | 210 | $location['extend'] = $this->getExtendString(); |
| 211 | 211 | break; |
| 212 | 212 | default: // 否则,表示国家信息没有被重定向 |
@@ -264,14 +264,14 @@ discard block |
||
| 264 | 264 | if (count($preg) == 4) { //匹配 "浙江省杭州市" |
| 265 | 265 | $state = $preg[1] ? $preg[1] : ($preg[2] ? $preg[2] : $preg[3]); |
| 266 | 266 | $city = $preg[3]; |
| 267 | - } else if (count($preg) == 7) { //匹配 "浙江省杭州市江干区" |
|
| 267 | + }else if (count($preg) == 7) { //匹配 "浙江省杭州市江干区" |
|
| 268 | 268 | $state = $preg[1] ? $preg[1] : ($preg[2] ? $preg[2] : $preg[3]); |
| 269 | 269 | $city = $preg[3]; |
| 270 | 270 | $area = $preg[5]; |
| 271 | - } else if (count($preg) == 3) { //匹配 "香港" |
|
| 271 | + }else if (count($preg) == 3) { //匹配 "香港" |
|
| 272 | 272 | $state = $preg[1] ? $preg[1] : $preg[2]; |
| 273 | 273 | $city = $state; |
| 274 | - } else if (count($preg) == 2) { //匹配 "浙江省" |
|
| 274 | + }else if (count($preg) == 2) { //匹配 "浙江省" |
|
| 275 | 275 | $state = $preg[1] ? $preg[1] : $this->unknown; |
| 276 | 276 | } |
| 277 | 277 | } |
@@ -296,7 +296,7 @@ discard block |
||
| 296 | 296 | private function getLong3() |
| 297 | 297 | { |
| 298 | 298 | //将读取的little-endian编码的3个字节转化为长整型数 |
| 299 | - $result = unpack('Vlong', fread($this->fp, 3) . chr(0)); |
|
| 299 | + $result = unpack('Vlong', fread($this->fp, 3).chr(0)); |
|
| 300 | 300 | return $result['long']; |
| 301 | 301 | } |
| 302 | 302 | |
@@ -323,7 +323,7 @@ discard block |
||
| 323 | 323 | { |
| 324 | 324 | $char = fread($this->fp, 1); |
| 325 | 325 | while (ord($char) > 0) { // 字符串按照C格式保存,以\0结束 |
| 326 | - $data .= $char; // 将读取的字符连接到给定字符串之后 |
|
| 326 | + $data .= $char; // 将读取的字符连接到给定字符串之后 |
|
| 327 | 327 | $char = fread($this->fp, 1); |
| 328 | 328 | } |
| 329 | 329 | return $data; |
@@ -335,7 +335,7 @@ discard block |
||
| 335 | 335 | */ |
| 336 | 336 | private function getExtendString() |
| 337 | 337 | { |
| 338 | - $byte = fread($this->fp, 1); // 标志字节 |
|
| 338 | + $byte = fread($this->fp, 1); // 标志字节 |
|
| 339 | 339 | switch (ord($byte)) { |
| 340 | 340 | case 0: // 没有区域信息 |
| 341 | 341 | $area = ""; |
@@ -382,7 +382,7 @@ discard block |
||
| 382 | 382 | } |
| 383 | 383 | $IPParts[$i] = str_pad(decHex($IPPart), 2, '0', STR_PAD_LEFT); |
| 384 | 384 | } |
| 385 | - return '0000:0000:0000:0000:0000:ffff:' . $IPParts[1] . $IPParts[2] . ':' . $IPParts[3] . $IPParts[4]; |
|
| 385 | + return '0000:0000:0000:0000:0000:ffff:'.$IPParts[1].$IPParts[2].':'.$IPParts[3].$IPParts[4]; |
|
| 386 | 386 | } |
| 387 | 387 | return ''; |
| 388 | 388 | } |
@@ -414,7 +414,7 @@ discard block |
||
| 414 | 414 | $district['lng'] = ''; |
| 415 | 415 | |
| 416 | 416 | if (!empty($province_name)) { |
| 417 | - $json_province = json_decode(file_get_contents(__DIR__ . '/bin/province.json'), true); |
|
| 417 | + $json_province = json_decode(file_get_contents(__DIR__.'/bin/province.json'), true); |
|
| 418 | 418 | foreach ($json_province['rows'] as $key => $value) { |
| 419 | 419 | if ($value['name'] == $province_name) { |
| 420 | 420 | $province['name'] = $value['name']; |
@@ -425,7 +425,7 @@ discard block |
||
| 425 | 425 | } |
| 426 | 426 | } |
| 427 | 427 | if (!empty($city_name)) { |
| 428 | - $json_city = json_decode(file_get_contents(__DIR__ . '/bin/city.json'), true); |
|
| 428 | + $json_city = json_decode(file_get_contents(__DIR__.'/bin/city.json'), true); |
|
| 429 | 429 | foreach ($json_city['rows'] as $key => $value) { |
| 430 | 430 | if ($value['name'] == $city_name) { |
| 431 | 431 | $city['name'] = $value['name']; |
@@ -436,7 +436,7 @@ discard block |
||
| 436 | 436 | } |
| 437 | 437 | } |
| 438 | 438 | if (!empty($district_name)) { |
| 439 | - $json_district = json_decode(file_get_contents(__DIR__ . '/bin/district.json'), true); |
|
| 439 | + $json_district = json_decode(file_get_contents(__DIR__.'/bin/district.json'), true); |
|
| 440 | 440 | foreach ($json_district['rows'] as $key => $value) { |
| 441 | 441 | if ($value['name'] == $district_name) { |
| 442 | 442 | $district['name'] = $value['name']; |