You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
/**
|
|
|
|
* @Author: jager
|
|
|
|
* @Email: lhj168os@gmail.com
|
|
|
|
* @File: msg
|
|
|
|
* @Date: 2021/12/3 1:40 下午
|
|
|
|
* @package: msg
|
|
|
|
* @Version: v1.0.0
|
|
|
|
*
|
|
|
|
* @Description:
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
package msg
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/jageros/hawox/errcode"
|
|
|
|
"github.com/jageros/hawox/sdk/dingtalk"
|
|
|
|
"github.com/jageros/hawox/sdk/qywx"
|
|
|
|
"stock/cfg"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
enableDingTalk = false
|
|
|
|
enableQywx = false
|
|
|
|
)
|
|
|
|
|
|
|
|
func Init() {
|
|
|
|
if cfg.DingTalkRobotUrl != "" && cfg.DingTalkSecret != "" {
|
|
|
|
dingtalk.SetConfig(cfg.DingTalkSecret, cfg.DingTalkRobotUrl)
|
|
|
|
enableDingTalk = true
|
|
|
|
}
|
|
|
|
if cfg.QywxRobotUrl != "" {
|
|
|
|
qywx.SetRobotConfig(cfg.QywxRobotUrl)
|
|
|
|
enableQywx = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Send(text string) error {
|
|
|
|
var err1, err2 error
|
|
|
|
if enableDingTalk {
|
|
|
|
err1 = dingtalk.SendMsg(text)
|
|
|
|
}
|
|
|
|
if enableQywx {
|
|
|
|
err2 = qywx.SendMsg(text)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err1 != nil {
|
|
|
|
err := errcode.WithErrcode(1, err1)
|
|
|
|
if err2 != nil {
|
|
|
|
err = err.WithErr(err2)
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err2 != nil {
|
|
|
|
return errcode.WithErrcode(2, err2)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|