无意中从朋友网站那里发现了一个QQ头像的接口
https://q2.qlogo.cn/headimg_dl?dst_uin=1355502473&spec=100
参数说明
dst_uin:QQ号
spec:图片大小,试了几个,只有100和640有效,推测用于默认和高清头像
spec:图片大小,试了几个,只有100和640有效,推测用于默认和高清头像
然后就是对主题内的functions.php下手,添加以下代码
add_filter('get_avatar', 'qq_img', 10, 2);
function qq_img($avatar,$id_or_email)
{
$email = '';
//获取邮箱
if (is_numeric($id_or_email)){
$id = (int)$id_or_email;
$user = get_userdata($id);
if ($user)
$email = $user->user_email;
}else if(is_object($id_or_email)){
if (!empty($id_or_email->user_id)){
$id = (int)$id_or_email->user_id;
$user = get_userdata($id);
if ($user)
$email = $user->user_email;
}else if(!empty($id_or_email->comment_author_email)){
$email = $id_or_email->comment_author_email;
}
}else{
$email = $id_or_email;
}
$hash = md5(strtolower(trim($email)));
$url = 'https://avatar.zrahh.com/avatar/' . $hash;
if(stripos($email,"@qq.com"))//判断是否为QQ邮箱
{
$qq=str_ireplace("@qq.com","",$email);
if(preg_match("/^\d+$/",$qq))//正则过滤英文邮箱
{
$qqavatar="https://q2.qlogo.cn/headimg_dl?dst_uin=".$qq."&spec=100";
return '<img src="'.$qqavatar.'"class="avatar avatar-50 photo" width="50" height="50" alt="avatar" />';
}else{ //如果是英文QQ邮箱就调用Gravatar头像
return '<img src="'.$url.'"class="avatar avatar-50 photo" width="50" height="50" alt="avatar" />';
}
}else{ //不是QQ邮箱
return '<img src="'.$url.'"class="avatar avatar-50 photo" width="50" height="50" alt="avatar" />';
}
}
现在使用QQ邮箱评论可以显示QQ头像了,但还有几个缺点:
1.会覆盖掉那些设置了Gravatar头像却使用QQ邮箱的用户。网上搜到了一篇利用返回http头判断用户是否设置了头像,但在国内会拖慢加载速度(国内源仍然不快),故没有借鉴,等有空看看有没有更好的方法。
2.自定义Gravatar默认头像失效,这个对我来说不是很重要,所以就不管了(坏笑)
3.未在其他主题测试过,兼容性未知
留言使用qq的话 还是很方便的。
确实,毕竟QQ用户群体很大,不至于评论区出现一堆没头像的用户
使用qq留言挺方便的啊 挺好的
你看这个手多好看啊
啊这
大佬居然回我了!毕竟你说的那个什么头像我也不知道是啥( OωO )
我是用edge回复的啊……怎么显示的是chrome……edge新版难道真的是微软和谷歌梦幻联动吗(
新版edge确实采用了Chromium内核()
这个我知道但是请问为什么浏览器类型识别错误了
感觉这个博客顶上的那张图片可以改成你的饭制关卡的(被打死)
你知道我的头像哪里来的吗
bzd (/ω\)
B站一个叫月上不是月下的up画的
我故意约了个很简单的东西所以白嫖到了
啊看不懂
那就去学PHP(bushi)
可以有但我觉得然并卵...我周围留言填outlook之类的邮箱比QQ还多
不如给没有Gravatar头像的用户做一个随机默认头像
这种情况用wordpress自带的就挺好
但我觉得WP自带的也不是很彳亍
我想自己弄一套随机头像
也可以,但是怎么检测默认头像是个问题
直接替换默认头像((
用网上那种返回http头的方法判断慢死了,得不偿失