Skip to content

Commit a54b6d4

Browse files
authored
Merge pull request #123 from Raxcl/hotfix-qqName-fix
fix:QQ昵称获取失效的问题修复
2 parents b17d892 + dd1b47c commit a54b6d4

File tree

3 files changed

+60
-11
lines changed

3 files changed

+60
-11
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package cn.raxcl.model.vo;
2+
3+
import lombok.Data;
4+
5+
import java.util.Map;
6+
7+
/**
8+
* @author raxcl
9+
* @date 2024-01-19 9:54:53
10+
*/
11+
@Data
12+
public class QqResultVO {
13+
private String success;
14+
15+
private String msg;
16+
17+
private Map<String, Object> data;
18+
19+
private String time;
20+
21+
private String api_vers;
22+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package cn.raxcl.model.vo;
2+
3+
import lombok.Data;
4+
5+
/**
6+
* @author raxcl
7+
* @date 2024-01-19 9:54:53
8+
*/
9+
@Data
10+
public class QqVO {
11+
/**
12+
* qq号
13+
*/
14+
private Long qq;
15+
16+
/**
17+
* qq昵称
18+
*/
19+
private String name;
20+
21+
/**
22+
* qq邮箱
23+
*/
24+
private String email;
25+
26+
/**
27+
* qq头像
28+
*/
29+
private String avatar;
30+
}

blog-api/src/main/java/top/naccl/util/QQInfoUtils.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,21 @@
1212
*/
1313
public class QQInfoUtils {
1414
private static RestTemplate restTemplate = new RestTemplate();
15-
private static final String QQ_NICKNAME_URL = "https://r.qzone.qq.com/fcg-bin/cgi_get_portrait.fcg?uins={1}";
15+
// 原接口半失效,需要提供cookie才可使用,暂时替换为备用接口,感谢 苏晓晴 大佬友情提供
16+
private static final String QQ_NICKNAME_URL = "https://api.toubiec.cn/api/qqinfo_v4.php?qq={1}";
1617
private static final String QQ_AVATAR_URL = "https://q.qlogo.cn/g?b=qq&nk=%s&s=100";
1718

1819
/**
1920
* 获取QQ昵称
2021
*
21-
* @param qq
22-
* @return
23-
* @throws UnsupportedEncodingException
22+
* @param qq qq
2423
*/
25-
public static String getQQNickname(String qq) throws UnsupportedEncodingException {
26-
String res = restTemplate.getForObject(QQ_NICKNAME_URL, String.class, qq);
27-
byte[] bytes = res.getBytes("iso-8859-1");
28-
String nickname = new String(bytes, "gb18030").split(",")[6].replace("\"", "");
29-
if ("".equals(nickname)) {
30-
return "nickname";
24+
public static String getQqNickname(String qq) {
25+
QqResultVO qqResultVO = REST_TEMPLATE.getForObject(QQ_NICKNAME_URL, QqResultVO.class, qq);
26+
if (qqResultVO != null) {
27+
return new ObjectMapper().convertValue(qqResultVO.getData(), QqVO.class).getName();
3128
}
32-
return nickname;
29+
return "nickname";
3330
}
3431

3532
/**

0 commit comments

Comments
 (0)