域名备案信息查询

1.【新增】域名备案信息查询
This commit is contained in:
阿九 2025-07-07 14:00:41 +08:00
parent 933f98a909
commit fdd8395420
5 changed files with 172 additions and 1 deletions

View File

@ -6,8 +6,10 @@ use app\BaseController;
use think\facade\Db;
use think\facade\View;
use think\facade\Cache;
use think\facade\Request;
use app\lib\DnsHelper;
use app\service\ExpireNoticeService;
use app\service\RecordCheckService;
use Exception;
class Domain extends BaseController
@ -1094,4 +1096,35 @@ class Domain extends BaseController
$result = (new ExpireNoticeService())->updateDomainDate($id, $drow['name']);
return json($result);
}
public function refreshRecord()
{
$id = input('param.id/d');
$drow = Db::name('domain')->where('id', $id)->find();
if (!$drow) {
return json(['code' => 1, 'msg' => '域名不存在']);
}
try {
$service = new RecordCheckService();
$result = $service->checkDomainRecord($drow['name'], $id);
if ($result['code'] === 0 && isset($result['data'])) {
Db::name('domain')
->where('id', $id)
->strict(false)
->update([
'record_status' => $result['data']['record_status'],
'record_number' => $result['data']['record_number']
]);
return json(['code' => 0, 'msg' => '刷新成功', 'data' => $result['data']]);
} else {
return json(['code' => 1, 'msg' => '查询失败']);
}
} catch (\Exception $e) {
return json(['code' => 1, 'msg' => '发生异常: ' . $e->getMessage()]);
}
}
}

View File

@ -0,0 +1,94 @@
<?php
namespace app\service;
use Exception;
use think\facade\Db;
use GuzzleHttp\Client;
class RecordCheckService
{
private $apiUrl = "https://api.makuo.cc/api/get.other.icp";
private $token = "6cx92OAIcm8yd29Kmpoc7w";
public function checkDomainRecord(string $domain, int $id): array
{
$exists = Db::name('domain')->where('id', $id)->value('id');
if (!$exists) {
return ['code' => -1, 'msg' => '域名不存在'];
}
try {
$client = new Client();
$response = $client->get($this->apiUrl, [
'query' => [
'token' => $this->token,
'url' => $domain
]
]);
$rawBody = $response->getBody()->getContents();
$encoding = mb_detect_encoding($rawBody, ['UTF-8', 'GBK', 'ASCII', 'ISO-8859-1'], true);
if ($encoding !== 'UTF-8') {
$rawBody = mb_convert_encoding($rawBody, 'UTF-8', $encoding);
}
$result = json_decode($rawBody, true);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new Exception('JSON 解码失败: ' . json_last_error_msg());
}
if (isset($result['code']) && $result['code'] == 200 && !empty($result['data'])) {
$data = $result['data'];
Db::name('domain')
->where('id', $id)
->strict(false)
->update([
'record_status' => 1,
'record_number' => $data['icp'],
]);
return [
'code' => 0,
'data' => [
'record_status' => 1,
'record_number' => $data['icp']
],
'msg' => '备案查询成功'
];
}
Db::name('domain')
->where('id', $id)
->strict(false)
->update([
'record_status' => 2,
'record_number' => null,
]);
return [
'code' => 0,
'data' => [
'record_status' => 2,
'record_number' => null
],
'msg' => '该域名暂未备案'
];
} catch (Exception $e) {
Db::name('domain')
->where('id', $id)
->strict(false)
->update([
'record_status' => 3,
]);
return [
'code' => -1,
'msg' => '备案查询失败,请稍后再试'
];
}
}
}

View File

@ -163,4 +163,8 @@ ADD COLUMN `regtime` datetime DEFAULT NULL,
ADD COLUMN `expiretime` datetime DEFAULT NULL,
ADD COLUMN `checktime` datetime DEFAULT NULL,
ADD COLUMN `noticetime` datetime DEFAULT NULL,
ADD COLUMN `checkstatus` tinyint(1) NOT NULL DEFAULT '0';
ADD COLUMN `checkstatus` tinyint(1) NOT NULL DEFAULT '0';
ALTER TABLE `dnsmgr_domain`
ADD COLUMN `record_status` tinyint(1) NOT NULL DEFAULT '0',
ADD COLUMN `record_number` varchar(255) DEFAULT NULL;

View File

@ -279,6 +279,23 @@ $(document).ready(function(){
return value==1?'<font color="green"></font>':'<font color="red"></font>';
}
},
{
field: 'record_number',
title: '备案信息',
formatter: function(value, row, index) {
if (row.record_status == 1) {
html = '<font color="green">' + value + '</font>';
} else if (row.record_status == 2) {
html = '<font color="red">暂无备案</font>';
} else if (row.record_status == 3) {
html = '<font color="info">查询失败</font>';
} else {
html = '<font color="#bdbdbd">待查询</font>';
}
html += '&nbsp;<a href="javascript:refreshRecord('+row.id+')" title="由于API问题有时可能检测不到请 换个时间段重新检测" data-toggle="tooltip" data-placement="bottom" class="text-info"><i class="fa fa-refresh"></i></a>';
return html;
}
},
{
field: 'remark',
title: '备注'
@ -603,6 +620,28 @@ function updateDate(id){
}
});
}
function refreshRecord(id) {
var ii = layer.load(2);
$.ajax({
type: 'POST',
url: '/domain/refresh-record',
data: { id: id },
dataType: 'json',
success: function (res) {
layer.close(ii);
if (res.code === 0) {
layer.msg('备案信息已更新', { icon: 1 });
searchRefresh();
} else {
layer.alert(res.msg || '刷新失败', { icon: 2 });
}
},
error: function () {
layer.close(ii);
layer.alert('请求失败,请重试', { icon: 2 });
}
});
}
function loading(){
layer.load(2);
}

View File

@ -73,6 +73,7 @@ Route::group(function () {
Route::post('/record/weight/data/:id', 'domain/weight_data');
Route::any('/record/weight/:id', 'domain/weight');
Route::get('/record/:id', 'domain/record');
Route::post('domain/refresh-record', 'domain/refreshRecord');
Route::get('/dmonitor/overview', 'dmonitor/overview');
Route::post('/dmonitor/task/data', 'dmonitor/task_data');