service/library/dingtalk/client.go

30 lines
716 B
Go
Raw Normal View History

2024-02-29 09:55:56 +08:00
package dingtalk
import (
"service/library/configcenter"
"service/library/logger"
"github.com/CatchZeng/dingtalk/pkg/dingtalk"
)
var defaultDingTalkClient *dingtalk.Client
func InitDefaultDingTalkClient(cfg *configcenter.DingTalkRobotConfig) {
defaultDingTalkClient = NewDingTalkCilent(cfg)
}
func NewDingTalkCilent(cfg *configcenter.DingTalkRobotConfig) *dingtalk.Client {
client := dingtalk.NewClient(cfg.AccessToken, cfg.Secret)
return client
}
func SendMsgToAll(message string) error {
msg := dingtalk.NewTextMessage().SetContent(message).SetAt(nil, true)
_, _, err := defaultDingTalkClient.Send(msg)
if err != nil {
logger.Error("SendMsgToAll fail, err: %v", err)
return err
}
return nil
}