一、接口概述
随缘ICP实时备案查询API是由接口盒子提供的一项提供域名ICP备案信息查询服务的API接口。该接口能够实时查询指定域名的备案信息,包括主体备案号、网站备案号、主体名称、审核时间等关键数据。接口采用"随缘"设计理念,查询成功率受网络环境和验证码识别因素影响,综合成功率在10%-30%之间,但具有成本优势,适合对实时性要求不高的应用场景。
二、接口核心特性
2.1 查询特点
- 实时查询:直接向备案系统发起实时查询,非缓存数据
- 成功率说明:受验证码识别和网络波动影响,成功率在10%-30%之间
- 查询耗时:正常查询需要5-20秒完成,建议设置超时时间20秒以上
- 成本优势:即使只有10%的成功率,综合成本仍是全网最低
2.2 适用场景
- 批量域名备案信息检查
- 网站合规性监测
- 域名交易前的备案状态验证
- 内部管理系统集成
三、接口详细参数说明
3.1 请求基本信息
- 请求地址:
https://cn.apihz.cn/api/wangzhan/syicp.php - 请求方式:支持POST和GET两种方法
- 编码格式:UTF-8
3.2 请求参数表
参数名称 |
参数名 |
是否必填 |
说明 |
用户ID |
id |
是 |
用户中心的数字ID,如:id=10000000 |
用户KEY |
key |
是 |
用户中心通讯秘钥,如:key=15he5h15ty854j5sr152hs2 |
域名 |
domain |
是 |
要查询的主域名(非二级域名),如:domain=apihz.cn |
缓存使用 |
hctype |
否 |
0=优先使用缓存(默认),1=直接实时查询 |
3.3 返回参数详解
参数名称 |
参数名 |
说明 |
状态码 |
code |
200=成功,400=错误 |
消息内容 |
msg |
操作结果提示信息 |
域名 |
domain |
查询的域名 |
域名ID |
domainid |
域名唯一标识 |
限制状态 |
xz |
是否被限制("是"或"否") |
主体备案号ID |
mainid |
主体备案号唯一标识 |
主体备案号 |
icp |
主体备案号码 |
主体性质 |
maintype |
企业/个人/事业单位等 |
备案ID |
serviceid |
网站备案号对应ID |
网站备案号 |
icpw |
完整的网站备案号 |
主体名称 |
mainname |
备案主体全称 |
审核时间 |
uptime |
备案审核通过时间 |
缓存时间 |
hctime |
平台数据更新时间 |
四、调用示例代码
4.1 PHP调用示例
php
php
复制
<?php /** * 随缘ICP备案查询API - PHP调用示例 * 支持GET和POST两种请求方式 */ class SyIcpQuery { private $apiUrl = 'https://cn.apihz.cn/api/wangzhan/syicp.php'; private $userId = '你的用户ID'; // 替换为实际用户ID private $userKey = '你的用户KEY'; // 替换为实际用户KEY /** * GET方式查询域名备案信息 * @param string $domain 要查询的域名 * @param int $useCache 是否使用缓存 0=是 1=否 * @return array 查询结果数组 */ public function queryByGet($domain, $useCache = 0) { // 构建请求URL $url = $this->apiUrl . '?id=' . $this->userId . '&key=' . $this->userKey . '&domain=' . urlencode($domain) . '&hctype=' . intval($useCache); // 设置请求选项 $options = [ 'http' => [ 'method' => 'GET', 'timeout' => 25, // 设置25秒超时 'header' => 'Content-type: application/x-www-form-urlencoded' ] ]; $context = stream_context_create($options); // 发送请求并获取响应 $response = file_get_contents($url, false, $context); if ($response === FALSE) { return ['code' => 400, 'msg' => '请求失败']; } return json_decode($response, true); } /** * POST方式查询域名备案信息 * @param string $domain 要查询的域名 * @param int $useCache 是否使用缓存 0=是 1=否 * @return array 查询结果数组 */ public function queryByPost($domain, $useCache = 0) { // 准备POST数据 $postData = http_build_query([ 'id' => $this->userId, 'key' => $this->userKey, 'domain' => $domain, 'hctype' => $useCache ]); // 设置请求选项 $options = [ 'http' => [ 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $postData, 'timeout' => 25 ] ]; $context = stream_context_create($options); $response = file_get_contents($this->apiUrl, false, $context); if ($response === FALSE) { return ['code' => 400, 'msg' => '请求失败']; } return json_decode($response, true); } /** * 带重试机制的查询方法 * @param string $domain 域名 * @param int $retryTimes 重试次数 * @return array 最终结果 */ public function queryWithRetry($domain, $retryTimes = 3) { for ($i = 0; $i < $retryTimes; $i++) { $result = $this->queryByGet($domain, 1); // 实时查询 if ($result['code'] == 200) { return $result; } // 失败后等待2秒再重试 sleep(2); } return ['code' => 400, 'msg' => '查询失败,已重试' . $retryTimes . '次']; } } // 使用示例 $icpQuery = new SyIcpQuery(); // 单次查询示例 $result = $icpQuery->queryByGet('apihz.cn', 1); echo "查询结果:\n"; print_r($result); // 带重试的查询示例 $result = $icpQuery->queryWithRetry('example.com'); echo "重试查询结果:\n"; print_r($result); // 批量查询示例 $domains = ['baidu.com', 'taobao.com', 'qq.com']; foreach ($domains as $domain) { $result = $icpQuery->queryWithRetry($domain); echo "域名 {$domain} 的备案信息:\n"; print_r($result); echo "\n"; sleep(1); // 避免频繁请求 } ?>
4.2 Python调用示例
python
python
下载
复制
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ 随缘ICP备案查询API - Python调用示例 支持GET和POST两种请求方式 """ import requests import time import json from urllib.parse import urlencode class SyIcpQuery: def __init__(self): self.api_url = 'https://cn.apihz.cn/api/wangzhan/syicp.php' self.user_id = '你的用户ID' # 替换为实际用户ID self.user_key = '你的用户KEY' # 替换为实际用户KEY self.timeout = 25 # 25秒超时 def query_by_get(self, domain, use_cache=0): """ GET方式查询域名备案信息 :param domain: 要查询的域名 :param use_cache: 是否使用缓存 0=是 1=否 :return: 查询结果字典 """ try: # 构建请求参数 params = { 'id': self.user_id, 'key': self.user_key, 'domain': domain, 'hctype': use_cache } # 发送GET请求 response = requests.get( self.api_url, params=params, timeout=self.timeout ) if response.status_code == 200: return response.json() else: return {'code': 400, 'msg': f'HTTP错误: {response.status_code}'} except requests.exceptions.RequestException as e: return {'code': 400, 'msg': f'请求异常: {str(e)}'} except json.JSONDecodeError as e: return {'code': 400, 'msg': f'JSON解析错误: {str(e)}'} def query_by_post(self, domain, use_cache=0): """ POST方式查询域名备案信息 :param domain: 要查询的域名 :param use_cache: 是否使用缓存 0=是 1=否 :return: 查询结果字典 """ try: # 准备POST数据 data = { 'id': self.user_id, 'key': self.user_key, 'domain': domain, 'hctype': use_cache } # 设置请求头 headers = { 'Content-Type': 'application/x-www-form-urlencoded' } # 发送POST请求 response = requests.post( self.api_url, data=data, headers=headers, timeout=self.timeout ) if response.status_code == 200: return response.json() else: return {'code': 400, 'msg': f'HTTP错误: {response.status_code}'} except requests.exceptions.RequestException as e: return {'code': 400, 'msg': f'请求异常: {str(e)}'} except json.JSONDecodeError as e: return {'code': 400, 'msg': f'JSON解析错误: {str(e)}'} def query_with_retry(self, domain, retry_times=3): """ 带重试机制的查询方法 :param domain: 域名 :param retry_times: 重试次数 :return: 最终结果字典 """ for i in range(retry_times): result = self.query_by_get(domain, 1) # 使用实时查询 if result.get('code') == 200: return result print(f'第{i+1}次查询失败,准备重试...') time.sleep(2) # 等待2秒后重试 return {'code': 400, 'msg': f'查询失败,已重试{retry_times}次'} def batch_query(self, domains, delay=1): """ 批量查询多个域名 :param domains: 域名列表 :param delay: 查询间隔(秒) :return: 查询结果列表 """ results = [] for domain in domains: print(f'正在查询域名: {domain}') result = self.query_with_retry(domain) results.append({ 'domain': domain, 'result': result }) time.sleep(delay) # 避免频繁请求 return results # 使用示例 if __name__ == '__main__': icp_query = SyIcpQuery() # 单次查询示例 print("=== 单次查询示例 ===") result = icp_query.query_by_get('apihz.cn', 1) print("查询结果:") print(json.dumps(result, ensure_ascii=False, indent=2)) # 带重试的查询示例 print("\n=== 带重试查询示例 ===") result = icp_query.query_with_retry('example.com') print("重试查询结果:") print(json.dumps(result, ensure_ascii=False, indent=2)) # 批量查询示例 print("\n=== 批量查询示例 ===") domains_to_query = ['baidu.com', 'taobao.com', 'qq.com'] batch_results = icp_query.batch_query(domains_to_query) for item in batch_results: print(f"\n域名: {item['domain']}") print("备案信息:") print(json.dumps(item['result'], ensure_ascii=False, indent=2))
五、接口使用注意事项
5.1 成功率优化策略
- 重试机制:建议实现自动重试逻辑,推荐重试3-5次
- 超时设置:单次查询超时时间建议设置为20秒以上
- 请求频率:避免过高频率请求,建议间隔1-2秒
- 错误处理:完善的状态码判断和异常处理机制
5.2 数据解析要点
- 状态码200时,需检查icp字段是否为空,为空表示未备案
- 主体备案号(icp)和网站备案号(icpw)可能相同或不同
- 审核时间(uptime)格式为"YYYY-MM-DD HH:MM:SS"
- 平台缓存时间(hctime)反映数据新鲜度
5.3 账户配置说明
- 需要使用个人用户ID和KEY,避免使用示例中的公共账号
- 个人账户独享调用频次限制,公共账号共享限制
- 每日调用无上限,但需遵守合理的调用频率
六、典型返回结果分析
6.1 查询成功示例
json
json
复制
{ "code": 200, "domain": "apihz.cn", "domainid": "990004666995", "xz": "否", "mainid": "990000107041", "icp": "蜀ICP备2020030589号", "maintype": "企业", "serviceid": "990005551431", "icpw": "蜀ICP备2020030589号-10", "mainname": "绵阳耳关明皿网络科技有限公司", "uptime": "2024-08-30 10:02:20", "hctime": "2025-12-17 17:46:51" }
6.2 查询失败示例
json
json
复制
{ "code": 400, "msg": "通讯秘钥错误。" }
6.3 未备案域名示例
json
json
复制
{ "code": 200, "domain": "example.com", "icp": null, "msg": "查询成功,该域名未备案" }
七、最佳实践建议
- 生产环境部署:建议使用异步查询方式,避免阻塞主业务流程
- 结果缓存:对查询结果进行本地缓存,减少重复查询
- 监控告警:实现查询成功率监控,低于阈值时发送告警
- 降级方案:准备离线查询或缓存查询作为备用方案
- 日志记录:完整记录查询请求和结果,便于问题排查
八、总结
随缘ICP实时备案查询API为开发者提供了一个经济实用的域名备案查询解决方案。虽然查询成功率有限,但通过合理的重试机制和错误处理,仍能满足大多数应用场景的需求。