Initial commit

This commit is contained in:
net909
2023-09-28 16:21:06 +08:00
parent 498772eb04
commit ba7be004c0
640 changed files with 87745 additions and 0 deletions
+151
View File
@@ -0,0 +1,151 @@
<?php
/**
* ICP备案查询
*/
namespace plugin\web\icp;
use app\Plugin;
use Exception;
use think\facade\Db;
class App extends Plugin
{
const CACHE_TIME = 604800;
public function index()
{
return $this->view();
}
public function query(){
$domain = input('post.domain', null, 'trim');
if(!$domain) return msg('error','no domain');
if(strpos($domain,'.') && !checkdomain($domain)){
return msg('error', '域名格式不正确!');
}
$captcha_result = verify_captcha4();
if($captcha_result !== true){
return msg('error', '验证失败,请重新验证');
}
$cache = Db::name('querycache')->where('type', 'icplist')->where('key|subkey', $domain)->find();
if($cache && time() - strtotime($cache['uptime']) <= self::CACHE_TIME){
$array = json_decode($cache['content'], true);
$data = Db::name('querycache')->where('type', 'icpitem')->whereIn('id', implode(',',$array['list']))->select();
$list = [];
foreach($data as $row){
$list[] = json_decode($row['content'], true);
}
return msg('ok','success',['total'=>$array['total'], 'list'=>$list]);
}
$cache = Db::name('querycache')->where('type', 'icpitem')->where('key|subkey', $domain)->find();
if($cache && time() - strtotime($cache['uptime']) <= self::CACHE_TIME){
$array = json_decode($cache['content'], true);
return msg('ok','success',['total'=>1, 'list'=>[$array]]);
}
try{
$result = $this->execapi($domain);
}catch(Exception $e){
return msg('error', $e->getMessage());
}
if($result['total'] > 1 && count($result['data']) > 1){
$i = 0;
foreach($result['data'] as $row){
$id = Db::name('querycache')->duplicate([
'subkey' => $row['webLicence'],
'content' => json_encode($row),
'uptime' => date('Y-m-d H:i:s')
])->insertGetId([
'type' => 'icpitem',
'key' => $row['domain'],
'subkey' => $row['webLicence'],
'content' => json_encode($row),
'uptime' => date('Y-m-d H:i:s')
]);
$result['data'][$i++]['id'] = $id;
$ids[] = $id;
}
Db::name('querycache')->duplicate([
'subkey' => $result['data'][0]['mainLicence'],
'content' => json_encode(['total'=>$result['total'], 'list'=>$ids]),
'uptime' => date('Y-m-d H:i:s')
])->insert([
'type' => 'icplist',
'key' => $result['data'][0]['unitName'],
'subkey' => $result['data'][0]['mainLicence'],
'content' => json_encode(['total'=>$result['total'], 'list'=>$ids]),
'uptime' => date('Y-m-d H:i:s')
]);
}elseif($result['total'] == 1 && count($result['data']) > 0){
$id = Db::name('querycache')->duplicate([
'subkey' => $result['data'][0]['webLicence'],
'content' => json_encode($result['data'][0]),
'uptime' => date('Y-m-d H:i:s')
])->insertGetId([
'type' => 'icpitem',
'key' => $result['data'][0]['domain'],
'subkey' => $result['data'][0]['webLicence'],
'content' => json_encode($result['data'][0]),
'uptime' => date('Y-m-d H:i:s')
]);
$result['data'][0]['id'] = $id;
}
return msg('ok','success',['total'=>$result['total'], 'list'=>$result['data']]);
}
public function item(){
$id = input('post.id');
if(!$id) return msg('error','no id');
$cache = Db::name('querycache')->where('id', $id)->find();
if($cache){
$array = json_decode($cache['content'], true);
return msg('ok','success',['total'=>1, 'list'=>[$array]]);
}else{
return msg('ok','success',['total'=>0, 'list'=>[]]);
}
}
private function execapi($domain){
$timeStamp = time();
$authKey = md5("testtest" . $timeStamp);
$referer = 'https://beian.miit.gov.cn/';
$headers = ['Origin: https://beian.miit.gov.cn'];
$url = 'https://hlwicpfwc.miit.gov.cn/icpproject_query/api/auth';
$post = 'authKey='.$authKey.'&timeStamp='.$timeStamp;
$response = get_curl($url, $post, $referer, 0, 0, 0, 0, $headers);
$arr = json_decode($response, true);
if(isset($arr['code']) && $arr['code']==200){
$token = $arr['params']['bussiness'];
$url = 'https://hlwicpfwc.miit.gov.cn/icpproject_query/api/icpAbbreviateInfo/queryByCondition';
$post = json_encode(['pageNum'=>'','pageSize'=>'','unitName'=>$domain,'serviceType'=>1]);
$headers[] = 'Content-Type: application/json; charset=UTF-8';
$headers[] = 'token: '.$token;
$response = get_curl($url, $post, $referer, 0, 0, 0, 0, $headers);
$arr = json_decode($response, true);
if(isset($arr['code']) && $arr['code']==200){
$list = [];
foreach($arr['params']['list'] as $row){
$list[] = ['domain'=>$row['domain'], 'mainLicence'=>$row['mainLicence'], 'webLicence'=>$row['serviceLicence'], 'unitName'=>$row['unitName'], 'unitType'=>$row['natureName'], 'updateTime'=>$row['updateRecordTime'], 'limitAccess'=>$row['limitAccess'], 'contentTypeName'=>$row['contentTypeName']];
}
return ['code'=>0, 'total'=>$arr['params']['total'], 'data'=>$list];
}elseif(isset($arr['msg'])){
throw new Exception($arr['msg']);
}else{
throw new Exception('查询接口(query)请求失败');
}
}elseif(isset($arr['msg'])){
throw new Exception($arr['msg']);
}else{
throw new Exception('查询接口(auth)请求失败');
}
}
}
+200
View File
@@ -0,0 +1,200 @@
{extend name="common/plugin_layout" /}
{block name="title"}{$plugin.title} - {:config_get('title')}{/block}
{block name="main"}
<style>
.query-title {
text-align: right;
}
.table-title th{word-break: keep-all;}
</style>
<div class="container-xl" id="app">
<div class="col-md-12 col-xl-10 center-block">
<div class="card card-preview">
<div class="card-inner mt-3">
<div class="nya-title nk-ibx-action-item progress-rating">
<span class="nk-menu-text font-weight-bold">ICP备案查询</span>
</div>
<div class="form-group">
<label class="form-label">输入域名/备案号/单位名称:</label>
<div class="form-control-wrap">
<input type="text" v-model="input" placeholder="请输入域名或备案号或单位名称查询,请勿使用子域名或者带http://www等字符的网址查询" class="form-control form-control-lg" @keyup.enter="query" ref="input" autocomplete="off">
</div>
</div>
<button class="btn btn-dim btn-outline-primary btn-block card-link mb-3" @click="query" :disabled="query_disabled">
查询
</button>
</div>
</div>
<div class="card card-preview" v-show="showresult" style="display:none">
<div class="card-inner mt-3">
<div class="nya-title nk-ibx-action-item progress-rating">
<span class="nk-menu-text font-weight-bold">查询结果</span>
</div>
<div class="alert alert-warning text-center" v-if="result_total==0"><h6><em class="icon ni ni-info"></em> 没有查询到备案记录</h6></div>
<div v-if="result_total==1">
<h6>域名 <span class="text-primary">{{result_info.domain}}</span> 的信息:</h6>
<div class="table-responsive">
<table class="table table-hover table-bordered">
<tbody>
<tr><td class="query-title">网站域名</td><td>{{result_info.domain}}</td></tr>
<tr><td class="query-title">ICP备案/许可证号</td><td>{{result_info.webLicence}}</td></tr>
<tr><td class="query-title">主办单位名称</td><td>{{result_info.unitName}}</td></tr>
<tr><td class="query-title">主办单位性质</td><td>{{result_info.unitType}}</td></tr>
<tr><td class="query-title">审核日期</td><td>{{result_info.updateTime}}</td></tr>
<tr><td class="query-title">是否限制接入</td><td>{{result_info.limitAccess}}</td></tr>
<tr><td class="query-title">网站前置审批项</td><td>{{result_info.contentTypeName}}</td></tr>
</tbody>
</table>
</div>
</div>
<div v-if="result_total>1">
<h6><span class="text-primary">{{result_input}}</span> 共查询到 <span class="text-primary">{{result_total}}</span> 条备案信息:</h6>
<div class="table-responsive">
<table class="table table-hover table-bordered">
<thead class="table-title">
<th>网站域名</th><th>网站备案号</th><th>主办单位名称</th><th>审核日期</th><th>操作</th>
</thead>
<tbody>
<tr v-for="(item,index) in result_list" :key="index">
<td>{{item.domain}}</td><td>{{item.webLicence}}</td><td>{{item.unitName}}</td><td>{{item.updateTime}}</td><td><button class="btn btn-dim btn-outline-info btn-xs" @click="show_item(index)">详情</button></td>
</tr>
</tbody>
</table>
</div>
<p v-if="result_total>10" class="text-info">当前只支持查询最新10条记录,剩余记录请使用域名或网站备案号进行精确查询。</p>
</div>
</div>
</div>
<div class="card card-preview">
<div class="card-inner">
<h6><em class="icon ni ni-info"></em> 简介</h6>
<div class="accordion-inner">
<p>支持输入域名、网站备案号、主体备案号、单位名称(个人姓名、企业名称)进行查询</p>
<p>此ICP查询工具直接对接工信部官网,非第三方接口。<a href="https://blog.cccyun.cn/post-445.html" target="_blank">查询源码下载</a>,请勿对本站进行恶意抓取</p>
</div>
</div>
</div>
</div>
</div>
{/block}
{block name="script"}
<script src="{$cdn_cdnjs}vue/2.6.14/vue.min.js"></script>
<script src="https://static.geetest.com/v4/gt4.js"></script>
<script>
new Vue({
el: '#app',
data: {
query_disabled: true,
input: '',
result_input: '',
showresult: false,
result_info: {
id: '',
domain: '',
mainLicence: '',
webLicence: '',
unitName: '',
unitType: '',
updateTime: '',
limitAccess: '',
contentTypeName: '',
},
result_list: [],
result_total: 0,
captcha: null
},
mounted() {
this.$refs.input.focus();
var that=this;
initGeetest4({
captchaId: "99b142aaece96330d0f3ffb565ffb3ef",
product: 'bind',
protocol: 'https://',
riskType: 'ai',
},function (captcha) {
captcha.onReady(function(){
that.query_disabled=false;
that.captcha = captcha;
var searchdomain = getQueryString('domain');
if(searchdomain!=null){
that.input = searchdomain;
that.query()
}
}).onSuccess(function(){
var result = captcha.getValidate();
if (!result) {
layer.closeAll();
return alert('请先完成验证');
}
var data = {domain: that.input};
$.ajax({
url: '/api/{$plugin.alias}/query',
type: 'post',
dataType: 'json',
data: Object.assign(data, result),
cache: false,
success: function (data) {
layer.closeAll();
if(data.status=='ok'){
var data = data.data;
that.result_input = that.input;
that.showresult = true;
that.result_total = data.total;
that.result_list = data.list;
if(data.list.length > 0){
that.result_info = data.list[0];
}
captcha.reset();
}else{
alert(data.message);
captcha.reset();
}
},
error: function () {
layer.closeAll();
layer.msg('服务器错误', {icon: 5});
captcha.reset();
}
});
}).onError(function(){
alert('验证码加载失败,请刷新页面重试');
})
});
},
methods: {
checkURL()
{
var url = this.input.trim();
if (url.indexOf(" ")>=0){
url = url.replace(/ /g,"");
}
if (url.toLowerCase().indexOf("http://")==0){
url = url.slice(7);
}
if (url.toLowerCase().indexOf("https://")==0){
url = url.slice(8);
}
if (url.slice(url.length-1)=="/"){
url = url.slice(0,url.length-1);
}
if (url.toLowerCase().indexOf("www.")==0){
url = url.slice(4);
}
this.input = url;
},
query() {
this.checkURL();
if(this.input == ''){
alert('查询内容不能为空');return;
}
layer.load(0, {shade:0.1});
this.captcha.showCaptcha();
},
show_item(index){
this.result_info = this.result_list[index];
this.result_total = 1;
}
},
})
</script>
{/block}
+12
View File
@@ -0,0 +1,12 @@
yum -y install python3
yum -y install mesa-libGL
python3 -m pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --upgrade pip
pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
pip3 install opencv-python==4.3.0.38
pip3 install requests
pip3 install flask
pip3 install gevent
nohup python3 ./server.py >> ./server.log 2>&1 &
+165
View File
@@ -0,0 +1,165 @@
# -*- coding: utf-8 -*-
import requests,hashlib,time,base64,cv2,os
def icpquery(info):
if(info == None or len(info) == 0):
return {'code':-1,'msg':'no domain'}
info_data = {
'pageNum':'',
'pageSize':'',
'unitName':info,
'serviceType':1
}
#构造AuthKey
timeStamp = int(round(time.time()*1000))
authSecret = 'testtest' + str(timeStamp)
authKey = hashlib.md5(authSecret.encode(encoding='UTF-8')).hexdigest()
#获取Cookie
cookie_headers = {
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.72 Safari/537.36 Edg/90.0.818.42'
}
cookie = requests.utils.dict_from_cookiejar(requests.get('https://beian.miit.gov.cn/',headers=cookie_headers,verify=False).cookies)['__jsluid_s']
#请求获取Token
t_url = 'https://hlwicpfwc.miit.gov.cn/icpproject_query/api/auth'
t_headers = {
'Host': 'hlwicpfwc.miit.gov.cn',
'Connection': 'keep-alive',
'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="90", "Microsoft Edge";v="90"',
'Accept': '*/*',
'DNT': '1',
'sec-ch-ua-mobile': '?0',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36 Edg/90.0.818.46',
'Origin': 'https://beian.miit.gov.cn',
'Sec-Fetch-Site': 'same-site',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Dest': 'empty',
'Referer': 'https://beian.miit.gov.cn/',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
'Cookie': '__jsluid_s=' + cookie
}
data = {
'authKey': authKey,
'timeStamp': timeStamp
}
t_response = requests.post(t_url,data=data,headers=t_headers,verify=False)
try:
get_token = t_response.json()['params']['bussiness']
except:
return {'code':-1,'msg':'请求被禁止,请稍后或更换头部与IP后再试('+t_response.status_code+')'}
#获取验证图像、UUID
p_url = 'https://hlwicpfwc.miit.gov.cn/icpproject_query/api/image/getCheckImage'
p_headers = {
'Host': 'hlwicpfwc.miit.gov.cn',
'Connection': 'keep-alive',
'Content-Length': '0',
'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="90", "Microsoft Edge";v="90"',
'Accept': 'application/json, text/plain, */*',
'DNT': '1',
'sec-ch-ua-mobile': '?0',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36 Edg/90.0.818.46',
'token': get_token,
'Origin': 'https://beian.miit.gov.cn',
'Sec-Fetch-Site': 'same-site',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Dest': 'empty',
'Referer': 'https://beian.miit.gov.cn/',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
'Cookie': '__jsluid_s=' + cookie
}
p_request = requests.post(p_url,data='',headers=p_headers,verify=False)
try:
p_uuid = p_request.json()['params']['uuid']
big_image = p_request.json()['params']['bigImage']
small_image = p_request.json()['params']['smallImage']
except KeyError:
return {'code':-1,'msg':'获取验证图像失败,请重试('+p_request.status_code+')'}
#解码图片,写入并计算图片缺口位置
with open('bigImage.jpg','wb') as f:
f.write(base64.b64decode(big_image))
f.close()
with open('smallImage.jpg','wb') as f:
f.write(base64.b64decode(small_image))
f.close()
background_image = cv2.imread('bigImage.jpg',cv2.COLOR_GRAY2RGB)
fill_image = cv2.imread('smallImage.jpg',cv2.COLOR_GRAY2RGB)
background_image_canny = cv2.Canny(background_image, 100, 200)
fill_image_canny = cv2.Canny(fill_image, 100, 300)
position_match = cv2.matchTemplate(background_image, fill_image, cv2.TM_CCOEFF_NORMED)
min_val,max_val,min_loc,max_loc = cv2.minMaxLoc(position_match)
position = max_loc
mouse_length = position[0]+1
os.remove('bigImage.jpg')
os.remove('smallImage.jpg')
#通过拼图验证,获取sign
check_url = 'https://hlwicpfwc.miit.gov.cn/icpproject_query/api/image/checkImage'
check_headers = {
'Host': 'hlwicpfwc.miit.gov.cn',
'Accept': 'application/json, text/plain, */*',
'Connection': 'keep-alive',
'Content-Length': '60',
'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="90", "Microsoft Edge";v="90"',
'DNT': '1',
'sec-ch-ua-mobile': '?0',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.72 Safari/537.36 Edg/90.0.818.42',
'token': get_token,
'Content-Type': 'application/json',
'Origin': 'https://beian.miit.gov.cn',
'Sec-Fetch-Site': 'same-site',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Dest': 'empty',
'Referer': 'https://beian.miit.gov.cn/',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
'Cookie': '__jsluid_s=' + cookie
}
check_data = {
'key':p_uuid,
'value':mouse_length
}
check_request = requests.post(check_url,json=check_data,headers=check_headers,verify=False)
try:
sign = check_request.json()['params']
except Exception:
return {'code':-1,'msg':'校验图片信息失败,请重试('+check_request.status_code+')'}
#获取备案信息
info_url = 'https://hlwicpfwc.miit.gov.cn/icpproject_query/api/icpAbbreviateInfo/queryByCondition'
info_headers = {
'Host': 'hlwicpfwc.miit.gov.cn',
'Connection': 'keep-alive',
'Content-Length': '78',
'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="90", "Microsoft Edge";v="90"',
'DNT': '1',
'sec-ch-ua-mobile': '?0',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.72 Safari/537.36 Edg/90.0.818.42',
'Content-Type': 'application/json',
'Accept': 'application/json, text/plain, */*',
'uuid': p_uuid,
'token': get_token,
'sign': sign,
'Origin': 'https://beian.miit.gov.cn',
'Sec-Fetch-Site': 'same-site',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Dest': 'empty',
'Referer': 'https://beian.miit.gov.cn/',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
'Cookie': '__jsluid_s=' + cookie
}
info_request = requests.post(info_url,json=info_data,headers=info_headers,verify=False)
domain_total = info_request.json()['params']['total']
result_list = []
for info_base in info_request.json()['params']['list']:
result_list.append({'domain':info_base['domain'], 'mainLicence':info_base['mainLicence'], 'webLicence':info_base['serviceLicence'], 'unitName':info_base['unitName'], 'unitType':info_base['natureName'], 'updateTime':info_base['updateRecordTime'], 'limitAccess':info_base['limitAccess'], 'contentTypeName':info_base['contentTypeName']})
return {'code':0,'msg':'success','data':result_list, 'total':domain_total}
+34
View File
@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
import icp,json,flask
HOST='127.0.0.1'
PORT=9088
app = flask.Flask(__name__)
json_header = {'Content-Type':'application/json; charset=utf-8'}
@app.route('/',methods=['GET'])
def home():
domain = flask.request.args.get('domain')
result = icp.icpquery(domain)
return flask.Response(json.dumps(result),headers=json_header)
@app.errorhandler(404)
def notfound(e):
errorStr = '''<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>server</center>
</body>
</html>'''
headers = {
"Content-Type":"text/html"
}
return flask.Response(errorStr,status=404,headers=headers)
if __name__ == '__main__':
from gevent.pywsgi import WSGIServer
http_server = WSGIServer((HOST, PORT), app)
http_server.serve_forever()
#app.run(port=PORT,host=HOST)