-
Notifications
You must be signed in to change notification settings - Fork 0
/
agentget.go
50 lines (42 loc) · 1.6 KB
/
agentget.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
package service
import (
"strconv"
"time"
"github.com/a07061625/gompf/mpf"
"github.com/a07061625/gompf/mpf/api/dingtalk"
"github.com/a07061625/gompf/mpf/mpconstant/project"
"github.com/valyala/fasthttp"
)
// 获取授权企业的应用信息
type agentGet struct {
dingtalk.BaseProvider
corpId string
agentTag string
}
func (ag *agentGet) CheckData() (*fasthttp.Client, *fasthttp.Request) {
providerConf := dingtalk.NewConfig().GetProvider()
suiteTicket := dingtalk.NewUtil().GetProviderSuiteTicket()
nowTime := strconv.FormatInt(time.Now().Unix(), 10)
corpConf := dingtalk.NewConfig().GetCorp(ag.corpId)
agentInfo := corpConf.GetAgentInfo(ag.agentTag)
ag.ExtendData["agentid"] = agentInfo["id"]
ag.ExtendData["suite_key"] = providerConf.GetSuiteKey()
ag.ReqData["timestamp"] = nowTime
ag.ReqData["accessKey"] = providerConf.GetSuiteKey()
ag.ReqData["suiteTicket"] = suiteTicket
ag.ReqData["signature"] = dingtalk.NewUtil().CreateApiSign(nowTime+"\n"+suiteTicket, providerConf.GetSuiteSecret())
ag.ReqURI = dingtalk.UrlService + "/service/get_agent?" + mpf.HTTPCreateParams(ag.ReqData, "none", 1)
reqBody := mpf.JSONMarshal(ag.ExtendData)
client, req := ag.GetRequest()
req.SetBody([]byte(reqBody))
return client, req
}
func NewAgentGet(corpId, agentTag string) *agentGet {
ag := &agentGet{dingtalk.NewProvider(), "", ""}
ag.corpId = corpId
ag.agentTag = agentTag
ag.ExtendData["auth_corpid"] = corpId
ag.ReqContentType = project.HTTPContentTypeJSON
ag.ReqMethod = fasthttp.MethodPost
return ag
}