-
Notifications
You must be signed in to change notification settings - Fork 0
/
usercreate.go
52 lines (45 loc) · 1.36 KB
/
usercreate.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
/**
* Created by GoLand.
* User: 姜伟
* Date: 2020/1/11 0011
* Time: 9:01
*/
package cloud
import (
"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/valyala/fasthttp"
)
// 开通云开发权限的帐号
type userCreate struct {
wx.BaseWxOpen
appId string // 应用ID
}
func (uc *userCreate) SendRequest() api.APIResult {
uc.ReqURI = "https://api.weixin.qq.com/tcb/createclouduser?access_token=" + wx.NewUtilWx().GetOpenAuthorizeAccessToken(uc.appId)
client, req := uc.GetRequest()
req.SetBody([]byte("{}"))
resp, result := uc.SendInner(client, req, errorcode.WxOpenRequestPost)
if resp.RespCode > 0 {
return result
}
respData, _ := mpf.JSONUnmarshalMap(resp.Content)
errCode, ok := respData["errcode"]
if ok && (errCode.(int) == 0) {
result.Data = respData
} else {
result.Code = errorcode.WxOpenRequestPost
result.Msg = respData["errmsg"].(string)
}
return result
}
func NewUserCreate(appId string) *userCreate {
uc := &userCreate{wx.NewBaseWxOpen(), ""}
uc.appId = appId
uc.ReqContentType = project.HTTPContentTypeJSON
uc.ReqMethod = fasthttp.MethodPost
return uc
}