-
Notifications
You must be signed in to change notification settings - Fork 1
/
QQUtil.java
58 lines (52 loc) · 1.39 KB
/
QQUtil.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package cn.xanderye.util;
import java.util.Random;
public class QQUtil {
/**
* qq登录需要用到的hash33算法
* @param qrsig
* @return java.lang.String
* @author XanderYe
* @date 2020-03-15
*/
public static String hash33(String qrsig) {
int e = 0;
for (int i = 0; i < qrsig.length(); i++) {
e += (e << 5) + qrsig.charAt(i);
}
return String.valueOf(2147483647 & e);
}
/**
* 调用qq接口用到的gtk算法
* @param skey
* @return java.lang.String
* @author XanderYe
* @date 2020-03-15
*/
public static String getGTK(String skey) {
int hash = 5381;
for (int i = 0; i < skey.length(); ++i) {
hash += (hash << 5) + skey.charAt(i);
}
return String.valueOf(hash & 0x7fffffff);
}
public static String uinToQQ(String uin) {
int startIndex = 1;
for (int i = 1; i < uin.length(); i++) {
if (uin.charAt(i) != '0') {
break;
}
startIndex++;
}
return uin.substring(startIndex);
}
/**
* qq请求的jsonp随机数
* @param
* @return java.lang.String
* @author yezhendong
* @date 2020-03-29
*/
public static String getCallback() {
return System.currentTimeMillis() + String.valueOf(new Random().nextInt(100000));
}
}