-
Notifications
You must be signed in to change notification settings - Fork 0
/
userget.go
62 lines (53 loc) · 1.58 KB
/
userget.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
/**
* Created by GoLand.
* User: 姜伟
* Date: 2020/1/13 0013
* Time: 9:09
*/
package user
import (
"regexp"
"github.com/a07061625/gompf/mpf"
"github.com/a07061625/gompf/mpf/api"
"github.com/a07061625/gompf/mpf/api/wx"
"github.com/a07061625/gompf/mpf/mpconstant/errorcode"
"github.com/a07061625/gompf/mpf/mpconstant/project"
"github.com/a07061625/gompf/mpf/mperr"
)
type userGet struct {
wx.BaseWxAccount
appId string
openid string // 用户openid
}
func (ug *userGet) SetOpenid(openid string) {
match, _ := regexp.MatchString(project.RegexWxOpenid, openid)
if match {
ug.ReqData["next_openid"] = openid
} else {
panic(mperr.NewWxAccount(errorcode.WxAccountParam, "用户openid不合法", nil))
}
}
func (ug *userGet) SendRequest() api.APIResult {
ug.ReqData["access_token"] = wx.NewUtilWx().GetSingleAccessToken(ug.appId)
ug.ReqURI = "https://api.weixin.qq.com/cgi-bin/user/get?" + mpf.HTTPCreateParams(ug.ReqData, "none", 1)
client, req := ug.GetRequest()
resp, result := ug.SendInner(client, req, errorcode.WxAccountRequestGet)
if resp.RespCode > 0 {
return result
}
respData, _ := mpf.JSONUnmarshalMap(resp.Content)
_, ok := respData["errcode"]
if ok {
result.Code = errorcode.WxAccountRequestGet
result.Msg = respData["errmsg"].(string)
} else {
result.Data = respData
}
return result
}
func NewUserGet(appId string) *userGet {
ug := &userGet{wx.NewBaseWxAccount(), "", ""}
ug.appId = appId
ug.ReqData["next_openid"] = ""
return ug
}