-
Notifications
You must be signed in to change notification settings - Fork 0
/
roleget.go
58 lines (50 loc) · 1.53 KB
/
roleget.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
/**
* Created by GoLand.
* User: 姜伟
* Date: 2020/1/31 0031
* Time: 22:33
*/
package role
import (
"github.com/a07061625/gompf/mpf"
"github.com/a07061625/gompf/mpf/api/dingtalk"
"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 roleGet struct {
dingtalk.BaseCorp
corpId string
agentTag string
atType string
roleId int // 角色ID
}
func (rg *roleGet) SetRoleId(roleId int) {
if roleId > 0 {
rg.roleId = roleId
} else {
panic(mperr.NewDingTalkCorp(errorcode.DingTalkCorpParam, "角色ID不合法", nil))
}
}
func (rg *roleGet) CheckData() (*fasthttp.Client, *fasthttp.Request) {
if rg.roleId <= 0 {
panic(mperr.NewDingTalkCorp(errorcode.DingTalkCorpParam, "角色ID不能为空", nil))
}
rg.ExtendData["roleId"] = rg.roleId
rg.ReqURI = dingtalk.UrlService + "/topapi/role/getrole?access_token=" + dingtalk.NewUtil().GetAccessToken(rg.corpId, rg.agentTag, rg.atType)
reqBody := mpf.JSONMarshal(rg.ExtendData)
client, req := rg.GetRequest()
req.SetBody([]byte(reqBody))
return client, req
}
func NewRoleGet(corpId, agentTag, atType string) *roleGet {
rg := &roleGet{dingtalk.NewCorp(), "", "", "", 0}
rg.corpId = corpId
rg.agentTag = agentTag
rg.atType = atType
rg.ReqContentType = project.HTTPContentTypeJSON
rg.ReqMethod = fasthttp.MethodPost
return rg
}