admin管理员组文章数量:1530085
一、获取QQ昵称
获取QQ昵称是通过QQ空间的一个Api接口(JSONP格式)获取
http://users.qzone.qq/fcg-bin/cgi_get_portrait.fcg?uins=760613041
示范:
二、获取QQ头像
可以通过下面这两个链接中的任意一个
http://q1.qlogo/g?b=qq&nk=760613041&s=300
http://q2.qlogo/headimg_dl?dst_uin=760613041&spec=40
示范:
其中nk为QQ号,s为头像的尺寸
参数s
对应的尺寸
1
40 × 40
2
40 × 40
3
100 × 100
4
140 × 140
5
640 × 640
40
40 × 40
100
100 × 100
三、Java获取、包装数据
@PostMapping("/qq/{qq}")
public ResponseVO qq(@PathVariable("qq") String qq) {
if (StringUtils.isEmpty(qq)) {
return ResultUtil.error("");
}
Map resultMap = new HashMap<>(4);
String nickname = "匿名";
String json = RestClientUtil.get("http://users.qzone.qq/fcg-bin/cgi_get_portrait.fcg?uins=" + qq, "GBK");
if (!StringUtils.isEmpty(json)) {
try {
json = json.replaceAll("portraitCallBack|\\\\s*|\\t|\\r|\\n", "");
json = json.substring(1, json.length() - 1);
LOG.info(json);
JSONObject object = JSONObject.parseObject(json);
JSONArray array = object.getJSONArray(qq);
nickname = array.getString(6);
} catch (Exception e) {
LOG.error("通过QQ号获取用户昵称发生异常", e);
}
}
resultMap.put("avatar", "https://q1.qlogo/g?b=qq&nk=" + qq + "&s=40");
resultMap.put("nickname", nickname);
resultMap.put("email", qq + "@qq");
resultMap.put("url", "https://user.qzone.qq/" + qq);
return ResultUtil.success(null, resultMap);
}
注:RestClientUtil类为普通的发起HTTP请求的工具类,可自己实现,也可在文末的源码链接中获取
版权声明:本文标题:php获取qq头像和昵称,通过接口获取QQ头像和昵称 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dongtai/1726252634a1062634.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论