From e7cfef0960c31def4cd86376e64169b45512a6c8 Mon Sep 17 00:00:00 2001 From: gazebo Date: Fri, 22 Mar 2019 14:17:29 +0800 Subject: [PATCH] - dingdingapi.NewWithAgentID - CorpAsyncSend and CorpAsyncSendSimple remove agentID param --- platformapi/dingdingapi/dingdingapi.go | 30 ++++++++++++--------- platformapi/dingdingapi/dingdingapi_test.go | 2 +- platformapi/dingdingapi/message.go | 8 +++--- platformapi/dingdingapi/message_test.go | 4 +-- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/platformapi/dingdingapi/dingdingapi.go b/platformapi/dingdingapi/dingdingapi.go index d582c568..29c05d3b 100644 --- a/platformapi/dingdingapi/dingdingapi.go +++ b/platformapi/dingdingapi/dingdingapi.go @@ -31,29 +31,35 @@ const ( ) type API struct { - corpID string - token string - appID string - secret string - client *http.Client - config *platformapi.APIConfig - locker sync.RWMutex + agentID int64 + corpID string + token string + appID string + secret string + client *http.Client + config *platformapi.APIConfig + locker sync.RWMutex callbackToken string callbackAESKey []byte } func New(corpID, appID, secret string, config ...*platformapi.APIConfig) *API { + return NewWithAgentID(0, corpID, appID, secret, config...) +} + +func NewWithAgentID(agentID int64, corpID, appID, secret string, config ...*platformapi.APIConfig) *API { curConfig := platformapi.DefAPIConfig if len(config) > 0 { curConfig = *config[0] } return &API{ - corpID: corpID, - appID: appID, - secret: secret, - client: &http.Client{Timeout: curConfig.ClientTimeout}, - config: &curConfig, + agentID: agentID, + corpID: corpID, + appID: appID, + secret: secret, + client: &http.Client{Timeout: curConfig.ClientTimeout}, + config: &curConfig, } } diff --git a/platformapi/dingdingapi/dingdingapi_test.go b/platformapi/dingdingapi/dingdingapi_test.go index 1ffb4aa0..0870a16f 100644 --- a/platformapi/dingdingapi/dingdingapi_test.go +++ b/platformapi/dingdingapi/dingdingapi_test.go @@ -18,7 +18,7 @@ func init() { sugarLogger = logger.Sugar() baseapi.Init(sugarLogger) - api = New("ding7ab5687f3784a8db", "ding7iu9cptairtcls0c", "LWrZAFeqUfuVv7n_tc8vPpCAx6PT4CwManx2XCVhJOqGsx2L5XCDuX1sAN_JtvsI") + api = NewWithAgentID(239461075, "ding7ab5687f3784a8db", "ding7iu9cptairtcls0c", "LWrZAFeqUfuVv7n_tc8vPpCAx6PT4CwManx2XCVhJOqGsx2L5XCDuX1sAN_JtvsI") api.RetrieveToken() } diff --git a/platformapi/dingdingapi/message.go b/platformapi/dingdingapi/message.go index fe1cecaf..6598ae5e 100644 --- a/platformapi/dingdingapi/message.go +++ b/platformapi/dingdingapi/message.go @@ -2,9 +2,9 @@ package dingdingapi import "strings" -func (a *API) CorpAsyncSend(agentID int, userIDList, deptIDList []string, isToAllUser bool, msg map[string]interface{}) (err error) { +func (a *API) CorpAsyncSend(userIDList, deptIDList []string, isToAllUser bool, msg map[string]interface{}) (err error) { params := map[string]interface{}{ - "agent_id": agentID, + "agent_id": a.agentID, "msg": msg, } if len(userIDList) > 0 { @@ -20,8 +20,8 @@ func (a *API) CorpAsyncSend(agentID int, userIDList, deptIDList []string, isToAl return err } -func (a *API) CorpAsyncSendSimple(agentID int, userID, content string) (err error) { - return a.CorpAsyncSend(agentID, []string{userID}, nil, false, map[string]interface{}{ +func (a *API) CorpAsyncSendSimple(userID, content string) (err error) { + return a.CorpAsyncSend([]string{userID}, nil, false, map[string]interface{}{ "msgtype": "text", "text": map[string]interface{}{ "content": content, diff --git a/platformapi/dingdingapi/message_test.go b/platformapi/dingdingapi/message_test.go index 7c6fc56e..bd07a292 100644 --- a/platformapi/dingdingapi/message_test.go +++ b/platformapi/dingdingapi/message_test.go @@ -3,7 +3,7 @@ package dingdingapi import "testing" func TestCorpAsyncSend(t *testing.T) { - err := api.CorpAsyncSend(239461075, []string{ + err := api.CorpAsyncSend([]string{ "051063452224284964", }, nil, false, map[string]interface{}{ "msgtype": "text", @@ -19,7 +19,7 @@ func TestCorpAsyncSend(t *testing.T) { } func TestCorpAsyncSendSimple(t *testing.T) { - err := api.CorpAsyncSendSimple(239461075, "051063452224284964", ` + err := api.CorpAsyncSendSimple("051063452224284964", ` 管理用户列表或角色列表。 Casbinadfs 认为由项目自身来管理用户、角色列表更为合适, 用户通常有他们的密码,但是 Casbin 的设计思想并不是把它作为一个存储密码的容器。 而是存储RBAC方案中用户和角色之间的映射关系。 `) if err != nil {