feat: add hosted message
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
package hosted_message_service
|
||||
|
||||
import (
|
||||
"message-nest/models"
|
||||
)
|
||||
|
||||
type HostMessageService struct {
|
||||
ID int
|
||||
Text string
|
||||
Title string
|
||||
Type string
|
||||
Content string
|
||||
|
||||
PageNum int
|
||||
PageSize int
|
||||
}
|
||||
|
||||
func (st *HostMessageService) Add() error {
|
||||
model := models.HostedMessage{
|
||||
Title: st.Title,
|
||||
Content: st.Content,
|
||||
Type: st.Type,
|
||||
}
|
||||
return model.Add()
|
||||
}
|
||||
|
||||
func (st *HostMessageService) Count() (int64, error) {
|
||||
return models.GetHostMessagesTotal(st.Text, st.getMaps())
|
||||
}
|
||||
|
||||
func (st *HostMessageService) GetAll() ([]models.HostMessageResult, error) {
|
||||
tasks, err := models.GetHostMessages(st.PageNum, st.PageSize, st.Text, st.getMaps())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return tasks, nil
|
||||
}
|
||||
|
||||
func (st *HostMessageService) getMaps() map[string]interface{} {
|
||||
maps := make(map[string]interface{})
|
||||
//if len(st.Query) > 0 {
|
||||
// decodedString, err := url.QueryUnescape(st.Query)
|
||||
// if err != nil {
|
||||
// logrus.Errorf("queryUrl编码解码失败: %s", err)
|
||||
// return maps
|
||||
// }
|
||||
// err = json.Unmarshal([]byte(decodedString), &maps)
|
||||
// if err != nil {
|
||||
// logrus.Errorf("queryJson反序列化失败: %s", err)
|
||||
// return maps
|
||||
// }
|
||||
//}
|
||||
return maps
|
||||
}
|
||||
@@ -39,6 +39,10 @@ func (sw *SendTaskInsService) ValidateDiffIns(ins models.SendTasksIns) (string,
|
||||
var Config models.InsQyWeiXinConfig
|
||||
return "", Config
|
||||
}
|
||||
if ins.WayType == "MessageNest" {
|
||||
var Config models.InsQyWeiXinConfig
|
||||
return "", Config
|
||||
}
|
||||
if ins.WayType == "Custom" {
|
||||
var Config models.InsCustomConfig
|
||||
err := json.Unmarshal([]byte(ins.Config), &Config)
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package send_message_service
|
||||
|
||||
import (
|
||||
"message-nest/models"
|
||||
"message-nest/service/hosted_message_service"
|
||||
"message-nest/service/send_way_service"
|
||||
)
|
||||
|
||||
type HostMessageService struct {
|
||||
}
|
||||
|
||||
// SendHostMessage 执行托管消息记录
|
||||
func (s *HostMessageService) SendHostMessage(
|
||||
auth send_way_service.MessageNest,
|
||||
ins models.SendTasksIns,
|
||||
typeC string,
|
||||
title string,
|
||||
content string) (string, string) {
|
||||
|
||||
errMsg := ""
|
||||
var res string
|
||||
var err error
|
||||
messageService := hosted_message_service.HostMessageService{
|
||||
Title: title,
|
||||
Content: content,
|
||||
Type: typeC,
|
||||
}
|
||||
err = messageService.Add()
|
||||
if err != nil {
|
||||
errMsg = err.Error()
|
||||
res = "托管消息创建失败!"
|
||||
} else {
|
||||
res = "托管消息创建成功!"
|
||||
}
|
||||
return string(res), errMsg
|
||||
}
|
||||
@@ -194,6 +194,15 @@ func (sm *SendMessageService) Send(task models.TaskIns) (string, error) {
|
||||
sm.LogsAndStatusMark(sm.TransError(errMsg), errStrIsSuccess(errMsg))
|
||||
continue
|
||||
}
|
||||
// 托管消息的实例发送
|
||||
mnt, ok := msgObj.(send_way_service.MessageNest)
|
||||
if ok {
|
||||
cs := HostMessageService{}
|
||||
res, errMsg := cs.SendHostMessage(mnt, ins.SendTasksIns, typeC, sm.Title, content)
|
||||
sm.LogsAndStatusMark(fmt.Sprintf("返回内容:%s", res), sm.Status)
|
||||
sm.LogsAndStatusMark(sm.TransError(errMsg), errStrIsSuccess(errMsg))
|
||||
continue
|
||||
}
|
||||
sm.LogsAndStatusMark(fmt.Sprintf("发送失败:未知渠道的发信实例: %s\n", ins.ID), SendFail)
|
||||
|
||||
}
|
||||
|
||||
@@ -56,6 +56,10 @@ type WeChatOFAccount struct {
|
||||
TempID string `json:"tempid" validate:"max=2000" label:"模板消息id"`
|
||||
}
|
||||
|
||||
// MessageNest 自托管消息
|
||||
type MessageNest struct {
|
||||
}
|
||||
|
||||
func (sw *SendWay) GetByID() (interface{}, error) {
|
||||
return models.GetWayByID(sw.ID)
|
||||
}
|
||||
@@ -170,6 +174,14 @@ func (sw *SendWay) ValidateDiffWay() (string, interface{}) {
|
||||
}
|
||||
_, Msg := app.CommonPlaygroundValid(wca)
|
||||
return Msg, wca
|
||||
} else if sw.Type == "MessageNest" {
|
||||
var wca MessageNest
|
||||
err := json.Unmarshal([]byte(sw.Auth), &wca)
|
||||
if err != nil {
|
||||
return "自托管消息反序列化失败!", empty
|
||||
}
|
||||
_, Msg := app.CommonPlaygroundValid(wca)
|
||||
return Msg, wca
|
||||
}
|
||||
return fmt.Sprintf("未知的发信渠道校验: %s", sw.Type), empty
|
||||
}
|
||||
@@ -209,11 +221,11 @@ func (sw *SendWay) TestSendWay(msgObj interface{}) (string, string) {
|
||||
}
|
||||
_, ok = msgObj.(WeChatOFAccount)
|
||||
if ok {
|
||||
//var cli = message.WeChatOFAccount{
|
||||
// AppID: wca.AppID,
|
||||
// AppSecret: wca.APPSecret,
|
||||
//}
|
||||
return "微信公众号模板消息不用测试运行,请直接添加", ""
|
||||
}
|
||||
_, ok = msgObj.(MessageNest)
|
||||
if ok {
|
||||
return "自托管消息不用测试运行,请直接添加", ""
|
||||
}
|
||||
return fmt.Sprintf("未知的发信渠道校验: %s", sw.Type), ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user