2025年10月最新PHP实现抖音、qq、微信、微信小程序封禁检测统一工具
介绍
这是一个基于PHP的统一封禁检测工具,支持QQ域名、微信域名、抖音域名以及微信小程序的封禁状态检测。通过单一接口即可完成多种平台的检测需求,方便快捷。
完整代码
<?php
/**
* 多平台封禁检测统一工具
* 2025年10月最新版本
* 支持QQ、微信、抖音域名检测以及微信小程序状态检测
*/
class UnifiedBanChecker {
// 各平台API地址配置
private $apiConfig = [
'qq' => [
'url' => 'https://api.wxapi.work/qq/api.PHP',
'param' => 'url'
],
'wechat' => [
'url' => 'https://api.wxapi.work/wechat/api.PHP',
'param' => 'url'
],
'douyin' => [
'url' => 'https://api.wxapi.work/douyin/api.PHP',
'param' => 'url'
],
'miniprogram' => [
'url' => 'https://api.wxapi.work/xcx/checkxcx.PHP',
'param' => 'appid'
]
];
/**
* 统一检测方法
* @param string $platform 检测平台 (qq/wechat/douyin/miniprogram)
* @param string $target 检测目标 (域名或AppID)
* @return array 返回统一格式的结果
*/
public function check($platform, $target) {
// 验证平台支持
if (!isset($this->apiConfig[$platform])) {
return $this->formatResult(false, '不支持的检测平台');
}
// 验证目标格式
if (!$this->validateTarget($platform, $target)) {
return $this->formatResult(false, '检测目标格式不正确');
}
try {
// 构建API请求
$apiUrl = $this->buildApiUrl($platform, $target);
// 发送请求
$response = $this->sendRequest($apiUrl);
// 解析响应
return $this->parseResponse($platform, $response);
} catch (Exception $e) {
return $this->formatResult(false, '检测失败: ' . $e->getMessage());
}
}
/**
* 验证检测目标格式
*/
private function validateTarget($platform, $target) {
switch ($platform) {
case 'miniprogram':
return preg_match('/^wx[a-f0-9]{16,}$/i', $target);
default:
return preg_match('/^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/i', $target);
}
}
/**
* 构建API请求URL
*/
private function buildApiUrl($platform, $target) {
$config = $this->apiConfig[$platform];
return $config['url'] . '?' . $config['param'] . '=' . urlencode($target);
}
/**
* 发送HTTP请求
*/
private function sendRequest($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode != 200) {
throw new Exception('API请求失败,HTTP状态码: ' . $httpCode);
}
return $response;
}
/**
* 解析API响应
*/
private function parseResponse($platform, $response) {
$data = json_decode($response, true);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new Exception('API返回数据解析失败');
}
// 根据不同平台处理返回结果
switch ($platform) {
case 'qq':
// QQ状态: 2=正常,其他=封禁
$status = isset($data['status']) && $data['status'] == 2;
$message = $status ? '域名正常' : '域名被封禁';
break;
case 'wechat':
// 微信状态: 2=正常,1=被拦截,0=被封
if (!isset($data['status'])) {
throw new Exception('微信API返回数据格式异常');
}
$statusMap = [
2 => ['status' => true, 'message' => '域名正常'],
1 => ['status' => false, 'message' => '域名被拦截'],
0 => ['status' => false, 'message' => '域名被封禁']
];
$result = $statusMap[$data['status']] ?? ['status' => false, 'message' => '未知状态'];
$status = $result['status'];
$message = $result['message'];
break;
case 'douyin':
// 抖音状态: 1=正常,其他=封禁
$status = isset($data['status']) && $data['status'] == 1;
$message = $status ? '域名正常' : '域名被封禁';
break;
case 'miniprogram':
// 小程序状态: 1=正常,0=被封
if (!isset($data['code'])) {
throw new Exception('小程序API返回数据格式异常');
}
$status = $data['code'] == 1;
$message = $status ? '小程序状态正常' : ($data['status'] ?? '小程序已被封禁');
break;
default:
throw new Exception('未知平台类型');
}
return $this->formatResult($status, $message);
}
/**
* 格式化返回结果
*/
private function formatResult($status, $message) {
return [
'success' => $status,
'code' => $status ? 1 : 0,
'message' => $message,
'timestamp' => time()
];
}
}
// 使用示例
if (isset($_GET['platform']) && isset($_GET['target'])) {
header('Content-Type: application/json; charset=utf-8');
$checker = new UnifiedBanChecker();
$result = $checker->check($_GET['platform'], $_GET['target']);
echo json_encode($result, JSON_UNESCAPED_UNICODE);
exit;
}
/**
* 函数式快捷调用方法
*/
function check_ban_status($platform, $target) {
$checker = new UnifiedBanChecker();
return $checker->check($platform, $target);
}
?>
使用方法
1. 基本使用方式
// 引入检测类
require_once 'UnifiedBanChecker.php';
// 创建检测器实例
$checker = new UnifiedBanChecker();
// 检测QQ域名状态
$qqResult = $checker->check('qq', 'baidu.com');
// 检测微信域名状态
$wechatResult = $checker->check('wechat', 'example.com');
// 检测抖音域名状态
$douyinResult = $checker->check('douyin', 'test.com');
// 检测微信小程序状态
$mpResult = $checker->check('miniprogram', 'wx81894c6dbb81c2e2');
// 输出结果
echo "QQ检测结果: " . json_encode($qqResult, JSON_UNESCAPED_UNICODE) . "\n";
echo "微信检测结果: " . json_encode($wechatResult, JSON_UNESCAPED_UNICODE) . "\n";
echo "抖音检测结果: " . json_encode($douyinResult, JSON_UNESCAPED_UNICODE) . "\n";
echo "小程序检测结果: " . json_encode($mpResult, JSON_UNESCAPED_UNICODE) . "\n";
2. Web接口方式
将代码保存为 check.php,然后通过URL访问:
http://yoursite.com/check.php?platform=qq&target=baidu.com
http://yoursite.com/check.php?platform=wechat&target=example.com
http://yoursite.com/check.php?platform=douyin&target=test.com
http://yoursite.com/check.php?platform=miniprogram&target=wx81894c6dbb81c2e2
3. 批量检测示例
// 批量检测多个平台
$targets = [
['platform' => 'qq', 'target' => 'baidu.com'],
['platform' => 'wechat', 'target' => 'example.com'],
['platform' => 'douyin', 'target' => 'test.com'],
['platform' => 'miniprogram', 'target' => 'wx81894c6dbb81c2e2']
];
$checker = new UnifiedBanChecker();
$results = [];
foreach ($targets as $item) {
$results[] = [
'platform' => $item['platform'],
'target' => $item['target'],
'result' => $checker->check($item['platform'], $item['target'])
];
}
// 输出批量检测结果
header('Content-Type: application/json; charset=utf-8');
echo json_encode($results, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
返回结果格式
所有检测统一返回格式:
{
"success": true,
"code": 1,
"message": "检测结果描述",
"timestamp": 1735678800
}
字段说明:
-
success: 布尔值,表示检测是否成功/正常 -
code: 状态码,1表示正常,0表示异常/封禁 -
message: 详细的状态描述信息 -
timestamp: 检测时间戳
各平台状态对照表
|
平台 |
正常状态 |
异常状态 |
|---|---|---|
|
QQ域名 |
|
|
|
微信域名 |
|
|
|
抖音域名 |
|
|
|
微信小程序 |
|
|
特点
-
统一接口:一个类实现所有平台的检测
-
标准化返回:所有平台返回相同格式的结果
-
自动验证:自动验证域名和AppID格式
-
错误处理:完善的异常捕获和处理机制
-
易于扩展:方便添加新的检测平台
注意事项
-
确保服务器已安装PHP并开启curl扩展
-
根据实际网络环境调整超时时间
-
生产环境建议添加请求频率限制
-
定期检查API接口是否有变更
这个统一工具极大简化了多平台封禁检测的复杂度,提高了开发效率,适用于各种Web应用和后台服务。
更多推荐



所有评论(0)