fix: bug fixed
This commit is contained in:
@@ -212,11 +212,14 @@ func TestSendWay(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
errTestMsg := sendWayService.TestSendWay(msgObj)
|
||||
errTestMsg, resText := sendWayService.TestSendWay(msgObj)
|
||||
if errTestMsg != "" {
|
||||
appG.CResponse(http.StatusInternalServerError, errTestMsg, nil)
|
||||
return
|
||||
}
|
||||
|
||||
appG.CResponse(http.StatusOK, "测试渠道信息成功", nil)
|
||||
msg := "测试渠道信息成功"
|
||||
if resText != "" {
|
||||
msg += ", 返回信息:" + resText
|
||||
}
|
||||
appG.CResponse(http.StatusOK, msg, nil)
|
||||
}
|
||||
|
||||
@@ -14,18 +14,16 @@ type CustomService struct {
|
||||
}
|
||||
|
||||
// SendCustomMessage 执行发送钉钉
|
||||
func (s *CustomService) SendCustomMessage(auth send_way_service.WayDetailCustom, ins models.SendTasksIns, typeC string, title string, content string) string {
|
||||
|
||||
func (s *CustomService) SendCustomMessage(auth send_way_service.WayDetailCustom, ins models.SendTasksIns, typeC string, title string, content string) (string, string) {
|
||||
errMsg := ""
|
||||
cli := message.CustomWebhook{}
|
||||
data, _ := json.Marshal(content)
|
||||
dataStr := string(data)
|
||||
dataStr = strings.Trim(dataStr, "\"")
|
||||
bodyStr := strings.Replace(auth.Body, "TEXT", dataStr, -1)
|
||||
_, err := cli.Request(auth.Webhook, bodyStr)
|
||||
res, err := cli.Request(auth.Webhook, bodyStr)
|
||||
if err != nil {
|
||||
errMsg = fmt.Sprintf("发送失败:%s", err)
|
||||
}
|
||||
|
||||
return errMsg
|
||||
return string(res), errMsg
|
||||
}
|
||||
|
||||
@@ -12,34 +12,36 @@ type DtalkService struct {
|
||||
}
|
||||
|
||||
// SendDtalkMessage 执行发送钉钉
|
||||
func (s *DtalkService) SendDtalkMessage(auth send_way_service.WayDetailDTalk, ins models.SendTasksIns, typeC string, title string, content string) string {
|
||||
func (s *DtalkService) SendDtalkMessage(auth send_way_service.WayDetailDTalk, ins models.SendTasksIns, typeC string, title string, content string) (string, string) {
|
||||
insService := send_ins_service.SendTaskInsService{}
|
||||
errStr, c := insService.ValidateDiffIns(ins)
|
||||
if errStr != "" {
|
||||
return errStr
|
||||
return errStr, ""
|
||||
}
|
||||
_, ok := c.(models.InsDtalkConfig)
|
||||
if !ok {
|
||||
return "钉钉config校验失败"
|
||||
return "钉钉config校验失败", ""
|
||||
}
|
||||
|
||||
errMsg := ""
|
||||
var res []byte
|
||||
var err error
|
||||
cli := message.Dtalk{
|
||||
AccessToken: auth.AccessToken,
|
||||
Secret: auth.Secret,
|
||||
}
|
||||
if typeC == "text" {
|
||||
_, err := cli.SendMessageText(content)
|
||||
res, err = cli.SendMessageText(content)
|
||||
if err != nil {
|
||||
errMsg = fmt.Sprintf("发送失败:%s", ins.ContentType)
|
||||
}
|
||||
} else if typeC == "markdown" {
|
||||
_, err := cli.SendMessageMarkdown(title, content)
|
||||
res, err = cli.SendMessageMarkdown(title, content)
|
||||
if err != nil {
|
||||
errMsg = fmt.Sprintf("发送失败:%s", ins.ContentType)
|
||||
}
|
||||
} else {
|
||||
errMsg = fmt.Sprintf("未知的钉钉发送内容类型:%s", ins.ContentType)
|
||||
}
|
||||
return errMsg
|
||||
return string(res), errMsg
|
||||
}
|
||||
|
||||
@@ -105,7 +105,8 @@ func (sm *SendMessageService) Send() string {
|
||||
dtalkAuth, ok := msgObj.(send_way_service.WayDetailDTalk)
|
||||
if ok {
|
||||
es := DtalkService{}
|
||||
errMsg := es.SendDtalkMessage(dtalkAuth, ins.SendTasksIns, typeC, sm.Title, content)
|
||||
res, errMsg := es.SendDtalkMessage(dtalkAuth, ins.SendTasksIns, typeC, sm.Title, content)
|
||||
sm.LogsAndStatusMark(fmt.Sprintf("返回内容:%s", res), sm.Status)
|
||||
sm.LogsAndStatusMark(sm.TransError(errMsg), errStrIsSuccess(errMsg))
|
||||
continue
|
||||
}
|
||||
@@ -113,7 +114,8 @@ func (sm *SendMessageService) Send() string {
|
||||
customAuth, ok := msgObj.(send_way_service.WayDetailCustom)
|
||||
if ok {
|
||||
cs := CustomService{}
|
||||
errMsg := cs.SendCustomMessage(customAuth, ins.SendTasksIns, typeC, sm.Title, content)
|
||||
res, errMsg := cs.SendCustomMessage(customAuth, ins.SendTasksIns, typeC, sm.Title, content)
|
||||
sm.LogsAndStatusMark(fmt.Sprintf("返回内容:%s", res), sm.Status)
|
||||
sm.LogsAndStatusMark(sm.TransError(errMsg), errStrIsSuccess(errMsg))
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -121,14 +121,14 @@ func (sw *SendWay) ValidateDiffWay() (string, interface{}) {
|
||||
}
|
||||
|
||||
// TestSendWay 尝试带发信测试连通性
|
||||
func (sw *SendWay) TestSendWay(msgObj interface{}) string {
|
||||
func (sw *SendWay) TestSendWay(msgObj interface{}) (string, string) {
|
||||
testMsg := "This is a test message from message-nest."
|
||||
emailAuth, ok := msgObj.(WayDetailEmail)
|
||||
if ok {
|
||||
var emailer message.EmailMessage
|
||||
emailer.Init(emailAuth.Server, 465, emailAuth.Account, emailAuth.Passwd)
|
||||
errMsg := emailer.SendTextMessage(emailAuth.Account, "test email", testMsg)
|
||||
return errMsg
|
||||
return errMsg, ""
|
||||
}
|
||||
dtalkAuth, ok := msgObj.(WayDetailDTalk)
|
||||
if ok {
|
||||
@@ -136,11 +136,11 @@ func (sw *SendWay) TestSendWay(msgObj interface{}) string {
|
||||
AccessToken: dtalkAuth.AccessToken,
|
||||
Secret: dtalkAuth.Secret,
|
||||
}
|
||||
_, err := cli.SendMessageText(testMsg + dtalkAuth.Keys)
|
||||
res, err := cli.SendMessageText(testMsg + dtalkAuth.Keys)
|
||||
if err != nil {
|
||||
return fmt.Sprintf("发送失败:%s", err)
|
||||
return fmt.Sprintf("发送失败:%s", err), string(res)
|
||||
}
|
||||
return ""
|
||||
return "", string(res)
|
||||
}
|
||||
customAuth, ok := msgObj.(WayDetailCustom)
|
||||
if ok {
|
||||
@@ -149,11 +149,11 @@ func (sw *SendWay) TestSendWay(msgObj interface{}) string {
|
||||
dataStr := string(data)
|
||||
dataStr = strings.Trim(dataStr, "\"")
|
||||
bodyStr := strings.Replace(customAuth.Body, "TEXT", dataStr, -1)
|
||||
_, err := cli.Request(customAuth.Webhook, bodyStr)
|
||||
res, err := cli.Request(customAuth.Webhook, bodyStr)
|
||||
if err != nil {
|
||||
return fmt.Sprintf("发送失败:%s", err)
|
||||
return fmt.Sprintf("发送失败:%s", err), string(res)
|
||||
}
|
||||
return ""
|
||||
return "", string(res)
|
||||
}
|
||||
return fmt.Sprintf("未知的发信渠道校验: %s", sw.Type)
|
||||
return fmt.Sprintf("未知的发信渠道校验: %s", sw.Type), ""
|
||||
}
|
||||
|
||||
@@ -100,6 +100,7 @@ import { v4 as uuidv4 } from 'uuid';
|
||||
import { usePageState } from '@/store/page_sate.js';
|
||||
import { request } from '@/api/api'
|
||||
import { CONSTANT } from '@/constant'
|
||||
import { CommonUtils } from "@/util/commonUtils.js";
|
||||
|
||||
|
||||
export default defineComponent({
|
||||
|
||||
@@ -112,6 +112,7 @@ export default defineComponent({
|
||||
const rsp = await request.post('/sendways/add', postData);
|
||||
if (await rsp.data.code == 200) {
|
||||
handleCancer();
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user