- 门店状态变化添加发送微信通知消息
This commit is contained in:
49
business/jxutils/ddmsg/ddmsg.go
Normal file
49
business/jxutils/ddmsg/ddmsg.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package ddmsg
|
||||
|
||||
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/business/auth2/authprovider/weixin"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
|
||||
func SendDDUserMessage(msgType, ddUserID, title, content string) (err error) {
|
||||
globals.SugarLogger.Debugf("SendDDUserMessage ddUserID:%s, title:%s, content:%s", ddUserID, title, content)
|
||||
if globals.IsProductEnv() {
|
||||
if msgType == dingdingapi.MsgTyeText {
|
||||
err = api.DingDingAPI.CorpAsyncSendSimple(ddUserID, content)
|
||||
} else if msgType == dingdingapi.MsgTypeMarkdown {
|
||||
err = api.DingDingAPI.CorpAsyncSendMarkdown([]string{ddUserID}, nil, false, title, content)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
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 {
|
||||
for _, auth := range authList {
|
||||
if auth.Type == dingding.AuthTypeStaff || auth.Type == weixin.AuthTypeMP {
|
||||
findOneMethod = true
|
||||
if msgType == dingdingapi.MsgTypeMarkdown && len(content) > dingdingapi.MaxWorkContentLen {
|
||||
content = content[:dingdingapi.MaxWorkContentLen-4] + "..."
|
||||
}
|
||||
err = SendDDUserMessage(msgType, auth.AuthID, 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
|
||||
}
|
||||
Reference in New Issue
Block a user