Browse Source

feat: database of tld info

master
Dnomd343 3 years ago
parent
commit
0ffda27698
  1. BIN
      db/allTlds.db
  2. BIN
      db/icpTlds.db
  3. BIN
      db/tldInfo.db
  4. 22
      functions/ExtractDomain.php
  5. 2
      functions/Punycode.php
  6. 6
      functions/RedisCache.php
  7. 2
      functions/TgInterface.php
  8. 4
      models/icpQuery.php

BIN
db/allTlds.db

Binary file not shown.

BIN
db/icpTlds.db

Binary file not shown.

BIN
db/tldInfo.db

Binary file not shown.

22
functions/ExtractDomain.php

@ -1,29 +1,13 @@
<?php <?php
class extractDomain { class extractDomain {
private $tldDB = './db/allTlds.db'; // 顶级域名数据库 private $tldDB = './db/tldInfo.db'; // 顶级域名数据库
private $icpDB = './db/icpTlds.db'; // ICP备案数据库
private function getAllTlds() { // 获取所有顶级域 含次级域 private function getAllTlds() { // 获取所有顶级域 含次级域
$db = new SqliteDB($this->tldDB); $db = new SqliteDB($this->tldDB);
$res = $db->query('SELECT tld FROM `tlds`;'); $res = $db->query('SELECT record FROM `list`;');
while ($row = $res->fetchArray(SQLITE3_ASSOC)) { while ($row = $res->fetchArray(SQLITE3_ASSOC)) {
$tlds[] = $row['tld']; $tlds[] = $row['record'];
}
$tlds = array_merge($tlds, $this->getIcpTlds());
$tlds = array_unique($tlds);
foreach ($tlds as $tld) {
echo $tld . PHP_EOL;
}
return $tlds; // Unicode字符使用Punycode编码
}
private function getIcpTlds() { // 获取所有可ICP备案的顶级域
$db = new SqliteDB($this->icpDB);
$punycode = new Punycode();
$res = $db->query('SELECT tld FROM `tlds`;');
while ($row = $res->fetchArray(SQLITE3_ASSOC)) {
$tlds[] = $punycode->encode($row['tld']); // 转为Punycode编码
} }
return $tlds; // Unicode字符使用Punycode编码 return $tlds; // Unicode字符使用Punycode编码
} }

2
functions/Punycode.php

@ -359,3 +359,5 @@ class Punycode {
} }
} }
} }
?>

6
functions/RedisCache.php

@ -1,9 +1,9 @@
<?php <?php
class redisCache { class redisCache {
private $redisSetting = array(); // redis接口参数 private $redisSetting = array(); // Redis接口参数
public function __construct($prefix) { // 初始化 public function __construct($prefix) { // 初始化
global $env; global $env;
$this->redisSetting = array( $this->redisSetting = array(
'host' => $env['REDIS_HOST'], 'host' => $env['REDIS_HOST'],
@ -32,7 +32,7 @@ class redisCache {
} }
$redisKey = $this->redisSetting['prefix'] . $key; $redisKey = $this->redisSetting['prefix'] . $key;
$status = $redis->set($redisKey, $data); // 写入数据库 $status = $redis->set($redisKey, $data); // 写入数据库
$redis->pexpire($redisKey, $cacheTTL * 1000); // 设置过期时间 单位ms $redis->pexpire($redisKey, $cacheTTL * 1000); // 设置过期时间 单位 ms = s * 1000
return $status; return $status;
} }
} }

2
functions/TgInterface.php

@ -49,7 +49,7 @@ class tgApi {
return file_get_contents($url); return file_get_contents($url);
} }
function debugDump() { // 调试接口 function debug() { // 调试接口
global $webhook, $tgEnv; global $webhook, $tgEnv;
$msg .= 'isCallback: ' . ($tgEnv['isCallback'] ? 'true' : 'false') . PHP_EOL; $msg .= 'isCallback: ' . ($tgEnv['isCallback'] ? 'true' : 'false') . PHP_EOL;
$msg .= 'isGroup: ' . ($tgEnv['isGroup'] ? 'true' : 'false') . PHP_EOL; $msg .= 'isGroup: ' . ($tgEnv['isGroup'] ? 'true' : 'false') . PHP_EOL;

4
models/icpQuery.php

@ -64,9 +64,9 @@ class icpQuery {
class icpQueryEntry { class icpQueryEntry {
private function getIcpTlds() { // 获取所有可ICP备案的顶级域 private function getIcpTlds() { // 获取所有可ICP备案的顶级域
$db = new icpDB; $db = new SqliteDB('./db/tldInfo.db');
$punycode = new Punycode(); $punycode = new Punycode();
$res = $db->query('SELECT tld FROM `tlds`;'); $res = $db->query('SELECT tld FROM `icp`;');
while ($row = $res->fetchArray(SQLITE3_ASSOC)) { while ($row = $res->fetchArray(SQLITE3_ASSOC)) {
$tlds[] = $punycode->encode($row['tld']); // 转为Punycode编码 $tlds[] = $punycode->encode($row['tld']); // 转为Punycode编码
} }

Loading…
Cancel
Save