Browse Source

fix:修改模板列表API

jimmyyem 1 month ago
parent
commit
28150a5fab

+ 1 - 1
desc/wechat/batch_msg.api

@@ -140,8 +140,8 @@ type (
 	SendMsgReq {
 		Phone *string `json:"phone"`
 		To *string `json:"to"`
-		Text *string `json:"text"`
 		Lang *string `json:"lang"`
+		TemplateCode *string `json:"templateCode"`
 	}
 )
 

+ 4 - 0
desc/wechat/whatsapp.api

@@ -369,6 +369,10 @@ type (
 	listTemplateResp {
 		Code int    `json:"code"`
 		Msg  string `json:"msg"`
+		Data ListTemplate `json:"data,omitempty"`
+	}
+	ListTemplate {
+		BaseListInfo
 		Data []TemplateSingleInfo `json:"data,omitempty"`
 	}
 	removeTemplateReq {

+ 1 - 9
hook/aliyun/whatsapp.go

@@ -1,7 +1,6 @@
 package aliyun
 
 import (
-	"encoding/json"
 	"fmt"
 	cams20200606 "github.com/alibabacloud-go/cams-20200606/v2/client"
 	openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
@@ -516,26 +515,19 @@ func DeleteChatappTemplate(name, language, templateType, templateCode string) (*
 
 // SendChatappMessage 发送消息
 // @see https://help.aliyun.com/zh/chatapp/developer-reference/api-cams-2020-06-06-sendchatappmessage
-func SendChatappMessage(stype, messageType, templateCode, lang, sfrom, sto, stext string) (*cams20200606.SendChatappMessageResponse, error) {
+func SendChatappMessage(stype, templateCode, lang, sfrom, sto string) (*cams20200606.SendChatappMessageResponse, error) {
 	client, _err := CreateCamsClient()
 	if _err != nil {
 		return nil, _err
 	}
 
-	var content = map[string]interface{}{
-		"text": stext,
-	}
-	scontext, _ := json.Marshal(content)
-
 	request := &cams20200606.SendChatappMessageRequest{
 		ChannelType:  tea.String("whatsapp"),
 		Type:         tea.String(stype),
-		MessageType:  tea.String(messageType),
 		TemplateCode: tea.String(templateCode),
 		Language:     tea.String(lang),
 		From:         tea.String(sfrom),
 		To:           tea.String(sto),
-		Content:      tea.String(string(scontext)),
 	}
 
 	response, _err := client.SendChatappMessage(request)

+ 1 - 3
internal/logic/batch_msg/send_batch_msg_text_logic.go

@@ -26,9 +26,7 @@ func NewSendBatchMsgTextLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
 func (l *SendBatchMsgTextLogic) SendBatchMsgText(req *types.SendMsgReq) (*types.BaseMsgResp, error) {
 	resp := types.BaseMsgResp{}
 
-	result, err := aliyun.SendChatappMessage(
-		"message", "text", "", *req.Lang,
-		*req.Phone, *req.To, *req.Text)
+	result, err := aliyun.SendChatappMessage("template", *req.TemplateCode, *req.Lang, *req.Phone, *req.To)
 	l.Logger.Infof("send chatapp message result=%v\n", result)
 
 	if err != nil {

+ 2 - 1
internal/logic/whatsapp/list_whatsapp_template_logic.go

@@ -34,9 +34,10 @@ func (l *ListWhatsappTemplateLogic) ListWhatsappTemplate(req *types.ListTemplate
 		resp.Code = 1
 	} else {
 		resp.Code = 0
+		resp.Data.Total = uint64(*result.Body.Total)
 		if len(result.Body.ListTemplate) > 0 && *result.Body.Code == "OK" {
 			for _, val := range result.Body.ListTemplate {
-				resp.Data = append(resp.Data, types.TemplateSingleInfo{
+				resp.Data.Data = append(resp.Data.Data, types.TemplateSingleInfo{
 					AuditStatus:  *val.AuditStatus,
 					Category:     *val.Category,
 					Language:     *val.Language,

+ 11 - 6
internal/types/types.go

@@ -2009,10 +2009,10 @@ type HistoryInfo struct {
 
 // swagger:model SendMsgReq
 type SendMsgReq struct {
-	Phone *string `json:"phone"`
-	To    *string `json:"to"`
-	Text  *string `json:"text"`
-	Lang  *string `json:"lang"`
+	Phone        *string `json:"phone"`
+	To           *string `json:"to"`
+	Lang         *string `json:"lang"`
+	TemplateCode *string `json:"templateCode"`
 }
 
 // The data of msg information | Msg信息
@@ -3891,8 +3891,13 @@ type ListTemplateReq struct {
 
 // swagger:model listTemplateResp
 type ListTemplateResp struct {
-	Code int                  `json:"code"`
-	Msg  string               `json:"msg"`
+	Code int          `json:"code"`
+	Msg  string       `json:"msg"`
+	Data ListTemplate `json:"data,omitempty"`
+}
+
+type ListTemplate struct {
+	BaseListInfo
 	Data []TemplateSingleInfo `json:"data,omitempty"`
 }