-
Notifications
You must be signed in to change notification settings - Fork 7
/
qq_parser.go
73 lines (61 loc) · 2.06 KB
/
qq_parser.go
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package goauth
import (
"regexp"
"strconv"
)
/* ================================================================================
* Oauth Qq
* qq group: 582452342
* email : 2091938785@qq.com
* author : 美丽的地球啊 - mliu
* ================================================================================ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* 解析QQ返回的AccessToken
* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
func ParseAccessTokenForQq(source string) (string, string, int) {
accessToken := ""
refreshToken := ""
var expiresIn int
if source != "" {
pattern := "access_token=(.*).+expires_in=(.*).+refresh_token=(.*)"
re, _ := regexp.Compile(pattern)
if matchs := re.FindStringSubmatch(source); len(matchs) == 4 {
accessToken = matchs[1]
if matchs[2] != "" {
if _expiresIn, err := strconv.Atoi(matchs[2]); err == nil {
expiresIn = _expiresIn
}
}
refreshToken = matchs[3]
}
}
return accessToken, refreshToken, expiresIn
}
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* 解析QQ返回的OpenId
* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
func ParseOpenIdForQq(source string) string {
openId := ""
if source != "" {
pattern := "callback.+{\"client_id\":\"(.*)\",\"openid\":\"(.*)\"\\}.+"
re, _ := regexp.Compile(pattern)
if matchs := re.FindStringSubmatch(source); len(matchs) == 3 {
openId = matchs[2]
}
}
return openId
}
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* 解析QQ返回的UnionId
* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
func ParseUnionIdForQq(source string) string {
unionId := ""
if source != "" {
pattern := "callback.+{\"client_id\":\"(.*)\",\"openid\":\"(.*)\",\"unionid\":\"(.*)\"\\}.+"
re, _ := regexp.Compile(pattern)
if matchs := re.FindStringSubmatch(source); len(matchs) == 4 {
unionId = matchs[3]
}
}
return unionId
}