- dingdingapi.NewWithAgentID
- CorpAsyncSend and CorpAsyncSendSimple remove agentID param
This commit is contained in:
@@ -31,29 +31,35 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type API struct {
|
type API struct {
|
||||||
corpID string
|
agentID int64
|
||||||
token string
|
corpID string
|
||||||
appID string
|
token string
|
||||||
secret string
|
appID string
|
||||||
client *http.Client
|
secret string
|
||||||
config *platformapi.APIConfig
|
client *http.Client
|
||||||
locker sync.RWMutex
|
config *platformapi.APIConfig
|
||||||
|
locker sync.RWMutex
|
||||||
|
|
||||||
callbackToken string
|
callbackToken string
|
||||||
callbackAESKey []byte
|
callbackAESKey []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(corpID, appID, secret string, config ...*platformapi.APIConfig) *API {
|
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
|
curConfig := platformapi.DefAPIConfig
|
||||||
if len(config) > 0 {
|
if len(config) > 0 {
|
||||||
curConfig = *config[0]
|
curConfig = *config[0]
|
||||||
}
|
}
|
||||||
return &API{
|
return &API{
|
||||||
corpID: corpID,
|
agentID: agentID,
|
||||||
appID: appID,
|
corpID: corpID,
|
||||||
secret: secret,
|
appID: appID,
|
||||||
client: &http.Client{Timeout: curConfig.ClientTimeout},
|
secret: secret,
|
||||||
config: &curConfig,
|
client: &http.Client{Timeout: curConfig.ClientTimeout},
|
||||||
|
config: &curConfig,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ func init() {
|
|||||||
sugarLogger = logger.Sugar()
|
sugarLogger = logger.Sugar()
|
||||||
baseapi.Init(sugarLogger)
|
baseapi.Init(sugarLogger)
|
||||||
|
|
||||||
api = New("ding7ab5687f3784a8db", "ding7iu9cptairtcls0c", "LWrZAFeqUfuVv7n_tc8vPpCAx6PT4CwManx2XCVhJOqGsx2L5XCDuX1sAN_JtvsI")
|
api = NewWithAgentID(239461075, "ding7ab5687f3784a8db", "ding7iu9cptairtcls0c", "LWrZAFeqUfuVv7n_tc8vPpCAx6PT4CwManx2XCVhJOqGsx2L5XCDuX1sAN_JtvsI")
|
||||||
api.RetrieveToken()
|
api.RetrieveToken()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ package dingdingapi
|
|||||||
|
|
||||||
import "strings"
|
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{}{
|
params := map[string]interface{}{
|
||||||
"agent_id": agentID,
|
"agent_id": a.agentID,
|
||||||
"msg": msg,
|
"msg": msg,
|
||||||
}
|
}
|
||||||
if len(userIDList) > 0 {
|
if len(userIDList) > 0 {
|
||||||
@@ -20,8 +20,8 @@ func (a *API) CorpAsyncSend(agentID int, userIDList, deptIDList []string, isToAl
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *API) CorpAsyncSendSimple(agentID int, userID, content string) (err error) {
|
func (a *API) CorpAsyncSendSimple(userID, content string) (err error) {
|
||||||
return a.CorpAsyncSend(agentID, []string{userID}, nil, false, map[string]interface{}{
|
return a.CorpAsyncSend([]string{userID}, nil, false, map[string]interface{}{
|
||||||
"msgtype": "text",
|
"msgtype": "text",
|
||||||
"text": map[string]interface{}{
|
"text": map[string]interface{}{
|
||||||
"content": content,
|
"content": content,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package dingdingapi
|
|||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
func TestCorpAsyncSend(t *testing.T) {
|
func TestCorpAsyncSend(t *testing.T) {
|
||||||
err := api.CorpAsyncSend(239461075, []string{
|
err := api.CorpAsyncSend([]string{
|
||||||
"051063452224284964",
|
"051063452224284964",
|
||||||
}, nil, false, map[string]interface{}{
|
}, nil, false, map[string]interface{}{
|
||||||
"msgtype": "text",
|
"msgtype": "text",
|
||||||
@@ -19,7 +19,7 @@ func TestCorpAsyncSend(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestCorpAsyncSendSimple(t *testing.T) {
|
func TestCorpAsyncSendSimple(t *testing.T) {
|
||||||
err := api.CorpAsyncSendSimple(239461075, "051063452224284964", `
|
err := api.CorpAsyncSendSimple("051063452224284964", `
|
||||||
管理用户列表或角色列表。 Casbinadfs 认为由项目自身来管理用户、角色列表更为合适, 用户通常有他们的密码,但是 Casbin 的设计思想并不是把它作为一个存储密码的容器。 而是存储RBAC方案中用户和角色之间的映射关系。
|
管理用户列表或角色列表。 Casbinadfs 认为由项目自身来管理用户、角色列表更为合适, 用户通常有他们的密码,但是 Casbin 的设计思想并不是把它作为一个存储密码的容器。 而是存储RBAC方案中用户和角色之间的映射关系。
|
||||||
`)
|
`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user