当前位置:网站首页>检测微信显示无效头像图片链接
检测微信显示无效头像图片链接
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;
}
}
边栏推荐
猜你喜欢
随机推荐
VCC(电源)和 GND(地)之间电容的作用
Difference between @JsonProperty and JSONField?
MySql的Sql语句的练习(试试你能写出来几道呢)
NIO知识汇总 收藏这一篇就够了!!!
802.1AS 时钟同步原理理解
大佬!Maya+ZBrush+Substance制作泰坦野兽全流程!
How the world's leading medical technology company maximizes design productivity | SOLIDWORKS Product Exploration
二分查找2 - x的平方根
数组与字符串14-使用双指针移除元素
【C语言】输出100~200之间的素数/质数(3种方法)
ue4学习日记4(植被,光照,光束遮挡,天空球)
【测试基础】bug分级、测试流程、ISO9126质量模型
电子元器件的分类有哪些?
802.1AS的SystemIdentity理解
2. What is the difference between Exception and Error?
ue4入门学习笔记1(操作界面)
二分查找4 - 搜索旋转排序数组
6. What is the difference between Vector, ArrayList and LinkedList?(design, performance, safety)
快速的将结构体各成员清零
ZEMAX | 如何创建复杂的非序列物体