微信域名拦截检测php源码
我的站长站
2023-05-12
共人阅读
本文分享微信域名拦截检测 PHP 源码,可批量 / 单条检测域名在微信内是否被封禁、拦截、无法正常访问,讲解检测原理、接口调用、结果判断、异常容错处理,代码可直接部署使用,适用于域名运维、站点巡检、防拦截监控等场景。
<?php
/**
* 微信域名拦截检测
*/
// 页面编码
header("Content-type:application/json");
// 隐藏WARNING
error_reporting(E_ALL ^ E_WARNING);
// 获取headers
$checkUrl = get_headers('http://mp.weixinbridge.com/mp/wapredirect?url='.$_REQUEST['url']);
$headerStr = json_encode($checkUrl);
// 提取Location后面的
$Location_behind = substr($headerStr, strripos($headerStr, "Location"));
// 判断域名状态
if($Location_behind == 'false'){
// 该域名无法正常访问
$result = array(
'code' => 201,
'msg' => '该域名无法正常访问,暂时无法查询访问状态'
);
}else if(strpos($Location_behind,'weixin110') !== false){
// Location后面包含weixin110就是被封了
// 域名被封
$result = array(
'code' => 202,
'msg' => '域名被封'
);
}else{
// 域名被封
$result = array(
'code' => 200,
'msg' => '域名正常'
);
}
// 输出JSON
echo json_encode($result,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE);
?>