-
Notifications
You must be signed in to change notification settings - Fork 0
/
memberinfo.go
71 lines (60 loc) · 1.84 KB
/
memberinfo.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
/**
* Created by GoLand.
* User: 姜伟
* Date: 2019/12/29 0029
* Time: 11:24
*/
package member
import (
"regexp"
"github.com/a07061625/gompf/mpf"
"github.com/a07061625/gompf/mpf/api"
"github.com/a07061625/gompf/mpf/api/mpprint"
"github.com/a07061625/gompf/mpf/mpconstant/errorcode"
"github.com/a07061625/gompf/mpf/mpconstant/project"
"github.com/a07061625/gompf/mpf/mperr"
"github.com/valyala/fasthttp"
)
type memberInfo struct {
mpprint.BaseFeYin
uid string // 商户id
}
func (mi *memberInfo) SetUid(uid string) {
match, _ := regexp.MatchString(project.RegexDigitAlpha, uid)
if match {
mi.uid = uid
mi.ReqURI = mpprint.FeYinServiceDomain + "/member/" + uid + "?access_token="
} else {
panic(mperr.NewPrintFeYin(errorcode.PrintFeYinParam, "商户id不合法", nil))
}
}
func (mi *memberInfo) checkData() (*fasthttp.Client, *fasthttp.Request) {
if len(mi.uid) == 0 {
panic(mperr.NewPrintFeYin(errorcode.PrintFeYinParam, "商户id不能为空", nil))
}
mi.ReqURI += mpprint.NewUtilPrint().GetFeYinAccessToken(mi.GetAppId())
return mi.GetRequest()
}
func (mi *memberInfo) SendRequest() api.APIResult {
client, req := mi.checkData()
resp, result := mi.SendInner(client, req, errorcode.PrintFeYinRequestGet)
if resp.RespCode > 0 {
return result
}
respData, _ := mpf.JSONUnmarshalMap(resp.Content)
_, ok := respData["errcode"]
if ok {
result.Code = errorcode.PrintFeYinRequestGet
result.Msg = respData["errmsg"].(string)
} else {
result.Data = respData
}
return result
}
func NewMemberInfo(appId string) *memberInfo {
mi := &memberInfo{mpprint.NewBaseFeYin(), ""}
mi.SetAppId(appId)
mi.ReqMethod = fasthttp.MethodGet
mi.ReqContentType = project.HTTPContentTypeForm
return mi
}