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