当前位置:网站首页>检测微信显示无效头像图片链接
检测微信显示无效头像图片链接
2022-08-03 05:26:00 【dd00bb】
class testModule
{
public function index()
{
$avatar_url = "https://thirdwx.qlogo.cn/mmopen/fPUctVSBSHt2AZPq6ibHz8cJQyapI7Xzo8quXictzOhLB1C9tz0wFWo4sia0baktdR9cgArGkZN8RtyxZAoZQWwicv3Oia5RKFQSw/132";
// 检测头像链接是否是https或http
if (filter_var($avatar_url , FILTER_VALIDATE_URL) === false) {
echo "头像链接不正确"
return
}
// 发送网络请求
$res = $this->httpGet($avatar_url );
// 检测请求头中是否有'X-ErrNo',有代表无效头像
if(strstr($res, 'X-ErrNo')){
echo "无效的微信头像";
}
echo "有效微信头像"
return
}
/** 获取请求头信息 */
private function httpGet($sUrl)
{
$oCurl = curl_init();
// 设置请求头, 有时候需要,有时候不用,看请求网址是否有对应的要求
$header[] = "Content-type: application/x-www-form-urlencoded";
$user_agent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36";
curl_setopt($oCurl, CURLOPT_URL, $sUrl);
curl_setopt($oCurl, CURLOPT_HTTPHEADER, $header);
// 返回 response_header, 该选项非常重要,如果不为 true, 只会获得响应的正文
curl_setopt($oCurl, CURLOPT_HEADER, true);
// 是否不需要响应的正文,为了节省带宽及时间,在只需要响应头的情况下可以不要正文
curl_setopt($oCurl, CURLOPT_NOBODY, true);
// 使用上面定义的 ua
curl_setopt($oCurl, CURLOPT_USERAGENT, $user_agent);
curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1);
// 不用 POST 方式请求, 意思就是通过 GET 请求
curl_setopt($oCurl, CURLOPT_POST, false);
$sContent = curl_exec($oCurl);
// 获得响应结果里的:头大小
$headerSize = curl_getinfo($oCurl, CURLINFO_HEADER_SIZE);
// 根据头大小去获取头信息内容
$header = substr($sContent, 0, $headerSize);
curl_close($oCurl);
return $header;
}
}
边栏推荐
猜你喜欢
随机推荐
ZEMAX | 在OpticStudio中建立扩增实境(VR)头戴式显示器
中空编码器的作用——唯样商城
Eight, the difference between the interface of the abstract class
使用ZBrush制作恶魔模型
游戏3D建模师是吃青春饭的吗?被高薪挖掘的建模人才,靠的是这个
5. What is the difference between int and Integer?
各种cms getshell技巧
二分查找5 - 第一个错误的版本
移动端人脸风格化技术的应用
ZEMAX | 探究 OpticStudio 偏振分析功能
ue4学习日记4(植被,光照,光束遮挡,天空球)
ZEMAX | 绘图分辨率结果对光线追迹的影响
How the world's leading medical technology company maximizes design productivity | SOLIDWORKS Product Exploration
【随笔】平常心
2-php学习笔记之控制语句,函数
ZEMAX | How to rotate any element around any point in space
最优化方法概述
802.1AS的SystemIdentity理解
./autogen.sh: 4: ./autogen.sh: autoreconf: not found
Difference between @JsonProperty and JSONField?









