1
0
mirror of https://gitee.com/zoujingli/ThinkAdmin.git synced 2025-04-06 03:58:04 +08:00

ComposerUpdate

This commit is contained in:
Anyon 2020-11-07 23:06:54 +08:00
parent 37bd415ddc
commit 55a6831d01
8 changed files with 134 additions and 116 deletions
app/admin/controller
vendor

@ -155,6 +155,7 @@ class Menu extends Controller
*/
public function remove()
{
$this->_applyFormToken();
$this->_delete($this->table);
}

@ -883,17 +883,17 @@
},
{
"name": "zoujingli/ip2region",
"version": "v1.0.8",
"version_normalized": "1.0.8.0",
"version": "v1.0.9",
"version_normalized": "1.0.9.0",
"source": {
"type": "git",
"url": "https://github.com/zoujingli/ip2region.git",
"reference": "d6be3ab9da1a1ab7e3cd51c4aa634a34de358ce6"
"reference": "e48f9122f50dd3b79295e35b4acdd0dcd2608ca8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/zoujingli/ip2region/zipball/d6be3ab9da1a1ab7e3cd51c4aa634a34de358ce6",
"reference": "d6be3ab9da1a1ab7e3cd51c4aa634a34de358ce6",
"url": "https://api.github.com/repos/zoujingli/ip2region/zipball/e48f9122f50dd3b79295e35b4acdd0dcd2608ca8",
"reference": "e48f9122f50dd3b79295e35b4acdd0dcd2608ca8",
"shasum": "",
"mirrors": [
{
@ -905,7 +905,7 @@
"require": {
"php": ">=5.3"
},
"time": "2020-07-06T05:33:26+00:00",
"time": "2020-11-06T07:21:55+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
@ -928,11 +928,7 @@
"homepage": "https://github.com/zoujingli/Ip2Region",
"keywords": [
"Ip2Region"
],
"support": {
"issues": "https://github.com/zoujingli/ip2region/issues",
"source": "https://github.com/zoujingli/ip2region/tree/master"
}
]
},
{
"name": "zoujingli/think-library",
@ -941,12 +937,12 @@
"source": {
"type": "git",
"url": "https://github.com/zoujingli/ThinkLibrary.git",
"reference": "6d7c8ac778d356e21222c6015260246a55433507"
"reference": "5dca339c3a9440425b5e2586c60b63ea58043835"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/6d7c8ac778d356e21222c6015260246a55433507",
"reference": "6d7c8ac778d356e21222c6015260246a55433507",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/5dca339c3a9440425b5e2586c60b63ea58043835",
"reference": "5dca339c3a9440425b5e2586c60b63ea58043835",
"shasum": "",
"mirrors": [
{
@ -963,7 +959,7 @@
"ext-mbstring": "*",
"topthink/framework": "^6.0"
},
"time": "2020-11-05T09:27:54+00:00",
"time": "2020-11-07T15:02:39+00:00",
"type": "library",
"extra": {
"think": {

2
vendor/services.php vendored

@ -1,5 +1,5 @@
<?php
// This file is automatically generated at:2020-11-05 18:36:10
// This file is automatically generated at:2020-11-07 23:06:26
declare (strict_types = 1);
return array (
0 => 'think\\admin\\Library',

@ -1,50 +1,74 @@
[![Latest Stable Version](https://poser.pugx.org/zoujingli/ip2region/v/stable)](https://packagist.org/packages/zoujingli/ip2region)
[![Total Downloads](https://poser.pugx.org/zoujingli/ip2region/downloads)](https://packagist.org/packages/zoujingli/ip2region)
[![Latest Unstable Version](https://poser.pugx.org/zoujingli/ip2region/v/unstable)](https://packagist.org/packages/zoujingli/ip2region)
[![License](https://poser.pugx.org/zoujingli/ip2region/license)](https://packagist.org/packages/zoujingli/ip2region)
本库基于 [ip2region](https://github.com/lionsoul2014/ip2region) ,简单整合方便使用`composer`来管理。
--
[ip2region](https://github.com/lionsoul2014/ip2region) - 最自由的ip地址查询库ip到地区的映射库提供Binary,B树和纯内存三种查询算法妈妈再也不用担心我的ip地址定位。
### 1. 99.9%准确率,定时更新:
数据聚合了一些知名ip到地名查询提供商的数据这些是他们官方的的准确率经测试着实比纯真啥的准确多了。<br />
每次聚合一下数据需要1-2天会不定时更新。
### 2. 标准化的数据格式:
每条ip数据段都固定了格式_城市Id|国家|区域|省份|城市|ISP_
只有中国的数据精确到了城市其他国家只能定位到国家后前的选项全部是0已经包含了全部你能查到的大大小小的国家。
请忽略前面的城市Id个人项目需求
### 3. 体积小:
数据库文件ip2region.db只有1.5M
### Composer 安装
```
composer require zoujingli/ip2region
```
### ip2region 使用
```php
$ip2region = new Ip2Region();
$ip = '101.105.35.57';
$info = $ip2region->btreeSearch($ip);
var_export($info, true);
// array (
// 'city_id' => 2163,
// 'region' => '中国|华南|广东省|深圳市|鹏博士',
// )
```
[![Latest Stable Version](https://poser.pugx.org/zoujingli/ip2region/v/stable)](https://packagist.org/packages/zoujingli/ip2region)
[![Total Downloads](https://poser.pugx.org/zoujingli/ip2region/downloads)](https://packagist.org/packages/zoujingli/ip2region)
[![Latest Unstable Version](https://poser.pugx.org/zoujingli/ip2region/v/unstable)](https://packagist.org/packages/zoujingli/ip2region)
[![License](https://poser.pugx.org/zoujingli/ip2region/license)](https://packagist.org/packages/zoujingli/ip2region)
本库基于 [ip2region](https://github.com/lionsoul2014/ip2region) ,简单整合方便使用`Composer`来管理。
## Ip2region 是什么?
[ip2region](https://github.com/lionsoul2014/ip2region) - 准确率 99.9% 的离线IP地址定位库0.0x 毫秒级查询ip2region.db 数据库只有数MB提供了查询绑定和 Binary, B 树,内存三种查询算法。
## Ip2region 特性
### 99.9%准确率
数据聚合了一些知名ip到地名查询提供商的数据这些是他们官方的的准确率经测试着实比经典的纯真IP定位准确一些。<br />
ip2region的数据聚合自以下服务商的开放API或者数据(升级程序每秒请求次数2到4次): <br />
01, &gt;80%, 淘宝IP地址库, [http://ip.taobao.com/](http://ip.taobao.com/) <br />
02, ≈10%, GeoIP, [https://geoip.com/](https://geoip.com/) <br />
03, ≈2%, 纯真IP库, [http://www.cz88.net/](http://www.cz88.net/) <br />
<b>备注:</b>如果上述开放API或者数据都不给开放数据时ip2region将停止数据的更新服务。
### 标准化的数据格式
每条ip数据段都固定了格式
```
_城市Id|国家|区域|省份|城市|ISP_
```
只有中国的数据精确到了城市其他国家有部分数据只能定位到国家后前的选项全部是0已经包含了全部你能查到的大大小小的国家请忽略前面的城市Id个人项目需求
### 体积小
包含了全部的 IP生成的数据库文件 ip2region.db 只有几MB最小的版本只有 1.5MB随着数据的详细度增加数据库的大小也慢慢增大目前还没超过8MB。
### 查询速度快
全部的查询客户端单次查询都在 0.x 毫秒级别,内置了三种查询算法
1. memory 算法:整个数据库全部载入内存,单次查询都在 0.1x 毫秒内C语言的客户端单次查询在 0.00x 毫秒级别。
2. binary 算法:基于二分查找,基于 ip2region.db 文件,不需要载入内存,单次查询在 0.x 毫秒级别。
3. b-tree 算法:基于 btree 算法,基于 ip2region.db 文件,不需要载入内存,单词查询在 0.x 毫秒级别,比 binary 算法更快。
任何客户端 b-tree 都比 binary 算法快,当然 memory 算法固然是最快的!
### Composer 安装
```
composer require zoujingli/ip2region
```
### ip2region 使用
```php
$ip2region = new Ip2Region();
$ip = '101.105.35.57';
$info = $ip2region->btreeSearch($ip);
var_export($info, true);
// array (
// 'city_id' => 2163,
// 'region' => '中国|华南|广东省|深圳市|鹏博士',
// )
```

Binary file not shown.

@ -1,20 +1,20 @@
<?php
require 'Ip2Region.php';
$ip2region = new Ip2Region();
$ip = '61.140.232.170';
echo PHP_EOL;
echo "查询IP{$ip}" . PHP_EOL;
$info = $ip2region->btreeSearch($ip);
var_export($info);
echo PHP_EOL;
$info = $ip2region->memorySearch($ip);
var_export($info);
echo PHP_EOL;
// array (
// 'city_id' => 2163,
// 'region' => '中国|华南|广东省|深圳市|鹏博士',
<?php
require 'Ip2Region.php';
$ip2region = new Ip2Region();
$ip = '61.140.232.170';
echo PHP_EOL;
echo "查询IP{$ip}" . PHP_EOL;
$info = $ip2region->btreeSearch($ip);
var_export($info);
echo PHP_EOL;
$info = $ip2region->memorySearch($ip);
var_export($info);
echo PHP_EOL;
// array (
// 'city_id' => 2163,
// 'region' => '中国|华南|广东省|深圳市|鹏博士',
// )

@ -26,31 +26,30 @@ use think\admin\Service;
*/
class TokenService extends Service
{
/**
* 缓存分组名称
* @var string
*/
private $name;
/**
* 当前缓存数据
* @var array
*/
private $cache = [];
/**
* 令牌有效时间
* @var integer
*/
private $expire = 600;
/**
* 缓存分组名称
* @var string
*/
private $cachename;
/**
* 当前缓存数据
* @var array
*/
private $cachedata = [];
/**
* 令牌服务初始化
*/
protected function initialize()
{
$this->cachename = $this->getCacheName();
$this->cachedata = $this->_getCacheList(true);
$this->name = $this->getCacheName();
$this->cache = $this->_getCacheList(true);
$this->app->event->listen('HttpEnd', function () {
TokenService::instance()->saveCacheData();
});
@ -72,7 +71,7 @@ class TokenService extends Service
public function saveCacheData()
{
$this->_clearTimeoutCache();
$this->app->cache->set($this->cachename, $this->cachedata, $this->expire);
$this->app->cache->set($this->name, $this->cache, $this->expire);
}
/**
@ -92,11 +91,9 @@ class TokenService extends Service
*/
public function checkFormToken($token = null, $node = null): bool
{
$cnode = NodeService::instance()->fullnode($node);
$cache = $this->_getCacheItem($token ?: $this->getInputToken());
if (empty($cache['node']) || empty($cache['time'])) return false;
if (strtolower($cache['node']) !== strtolower($cnode)) return false;
return true;
return $cache['node'] === NodeService::instance()->fullnode($node);
}
/**
@ -128,7 +125,7 @@ class TokenService extends Service
*/
public function clearCache()
{
$this->app->cache->delete($this->cachename);
$this->app->cache->delete($this->name);
}
/**
@ -139,7 +136,7 @@ class TokenService extends Service
*/
private function _setCacheItem(string $token, array $value)
{
$this->cachedata[$token] = $value;
$this->cache[$token] = $value;
return $this;
}
@ -149,7 +146,7 @@ class TokenService extends Service
*/
private function _delCacheItem(string $token)
{
unset($this->cachedata[$token]);
unset($this->cache[$token]);
}
/**
@ -161,7 +158,7 @@ class TokenService extends Service
private function _getCacheItem(string $token, $default = [])
{
$this->_clearTimeoutCache();
return $this->cachedata[$token] ?? $default;
return $this->cache[$token] ?? $default;
}
/**
@ -171,9 +168,9 @@ class TokenService extends Service
*/
private function _getCacheList(bool $clear = false): array
{
$this->cachedata = $this->app->cache->get($this->cachename, []);
if ($clear) $this->cachedata = $this->_clearTimeoutCache();
return $this->cachedata;
$this->cache = $this->app->cache->get($this->name, []);
if ($clear) $this->cache = $this->_clearTimeoutCache();
return $this->cache;
}
/**
@ -183,14 +180,14 @@ class TokenService extends Service
private function _clearTimeoutCache(): array
{
$time = time();
foreach ($this->cachedata as $key => $item) {
foreach ($this->cache as $key => $item) {
if (empty($item['time']) || $item['time'] + $this->expire < $time) {
unset($this->cachedata[$key]);
unset($this->cache[$key]);
}
}
if (count($this->cachedata) > 99) {
$this->cachedata = array_slice($this->cachedata, -99);
if (count($this->cache) > 999) {
$this->cache = array_slice($this->cache, -999);
}
return $this->cachedata;
return $this->cache;
}
}

@ -270,7 +270,7 @@ class TxcosStorage extends Storage
public static function region()
{
return [
'cos.ap-beijing-1.myqcloud.com' => '中国大陆 公有云地域 北京一区(已售罄)',
'cos.ap-beijing-1.myqcloud.com' => '中国大陆 公有云地域 北京一区',
'cos.ap-beijing.myqcloud.com' => '中国大陆 公有云地域 北京',
'cos.ap-nanjing.myqcloud.com' => '中国大陆 公有云地域 南京',
'cos.ap-shanghai.myqcloud.com' => '中国大陆 公有云地域 上海',