当前位置:网站首页>检测微信显示无效头像图片链接
检测微信显示无效头像图片链接
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;
}
}
边栏推荐
猜你喜欢
随机推荐
浮点型数据在内存中存储的表示
五、int和Integer有什么区别?
树——二叉排序树(BST)
【3D建模制作技巧分享】ZBrush快捷键如何设置
Typora
电容器和电池有什么不同?
2021-04-30
Delightful Nuxt3 Tutorial (2): Build a Blog Quickly and Easily
ucosII OSMemCreate()函数的解析
VLAN虚拟局域网技术
Phase Vocoder的补充完善,Matlab音频变速不变调、变调不变速
3D建模为什么会变得无处不在
3. What is the difference between final, finally, and finalize?
二分查找3 - 猜数字大小
【C语言】斐波那契数列
数组与字符串14-使用双指针移除元素
IP数据包的格式(1)
classpath:与classpath*的比较
MATLAB给多组条形图添加误差棒
5. What is the difference between int and Integer?









