46 lines
1.4 KiB
Go
46 lines
1.4 KiB
Go
package msg
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"git.rosy.net.cn/baseapi/platformapi/dingdingapi"
|
|
"git.rosy.net.cn/jx-callback/business/auth2"
|
|
"git.rosy.net.cn/jx-callback/business/auth2/authprovider/dingding"
|
|
"git.rosy.net.cn/jx-callback/globals"
|
|
"git.rosy.net.cn/jx-callback/globals/api"
|
|
)
|
|
|
|
func SendUserMessage(msgType, userID, title, content string) (err error) {
|
|
globals.SugarLogger.Debugf("SendUserMessage userID:%s, title:%s, content:%s", userID, title, content)
|
|
authList, err := auth2.GetUserBindAuthInfo(userID)
|
|
findOneMethod := false
|
|
if err == nil {
|
|
if title != "" {
|
|
content = title + "\n" + content
|
|
}
|
|
for _, auth := range authList {
|
|
if auth.Type == dingding.AuthTypeStaff {
|
|
findOneMethod = true
|
|
if len(content) > dingdingapi.MaxWorkContentLen {
|
|
content = content[:dingdingapi.MaxWorkContentLen-4] + "..."
|
|
}
|
|
if globals.IsProductEnv() {
|
|
if msgType == dingdingapi.MsgTyeText {
|
|
err = api.DingDingAPI.CorpAsyncSendSimple(auth.AuthID, content)
|
|
} else if msgType == dingdingapi.MsgTypeMarkdown {
|
|
err = api.DingDingAPI.CorpAsyncSendMarkdown([]string{auth.AuthID}, nil, false, title, content)
|
|
}
|
|
}
|
|
break
|
|
}
|
|
}
|
|
}
|
|
if !findOneMethod {
|
|
err = fmt.Errorf("用户[%s]找不到至少一个有效的通讯方式", userID)
|
|
}
|
|
if err != nil {
|
|
globals.SugarLogger.Infof("SendUserMessage userID:%s, title:%s, content:%s failed with error:%v", userID, title, content, err)
|
|
}
|
|
return err
|
|
}
|