jimmyyem 3 hónapja
szülő
commit
688392d5db

+ 44 - 0
internal/handler/whatsapp/get_automation_handler.go

@@ -0,0 +1,44 @@
+package whatsapp
+
+import (
+	"net/http"
+
+	"github.com/zeromicro/go-zero/rest/httpx"
+
+	"wechat-api/internal/logic/whatsapp"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+)
+
+// swagger:route post /whatsapp/getAutomation whatsapp GetAutomation
+//
+// 获取开场白
+//
+// 获取开场白
+//
+// Parameters:
+//  + name: body
+//    require: true
+//    in: body
+//    type: AutomationReq
+//
+// Responses:
+//  200: AutomationResp
+
+func GetAutomationHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.AutomationReq
+		if err := httpx.Parse(r, &req, true); err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+			return
+		}
+
+		l := whatsapp.NewGetAutomationLogic(r.Context(), svcCtx)
+		resp, err := l.GetAutomation(&req)
+		if err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+		} else {
+			httpx.OkJsonCtx(r.Context(), w, resp)
+		}
+	}
+}

+ 44 - 0
internal/handler/whatsapp/send_whatsapp_code_handler.go

@@ -0,0 +1,44 @@
+package whatsapp
+
+import (
+	"net/http"
+
+	"github.com/zeromicro/go-zero/rest/httpx"
+
+	"wechat-api/internal/logic/whatsapp"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+)
+
+// swagger:route post /whatsapp/sendCode whatsapp SendWhatsappCode
+//
+// 发送验证码
+//
+// 发送验证码
+//
+// Parameters:
+//  + name: body
+//    require: true
+//    in: body
+//    type: sendCodeReq
+//
+// Responses:
+//  200: BaseMsgResp
+
+func SendWhatsappCodeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.SendCodeReq
+		if err := httpx.Parse(r, &req, true); err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+			return
+		}
+
+		l := whatsapp.NewSendWhatsappCodeLogic(r.Context(), svcCtx)
+		resp, err := l.SendWhatsappCode(&req)
+		if err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+		} else {
+			httpx.OkJsonCtx(r.Context(), w, resp)
+		}
+	}
+}

+ 44 - 0
internal/handler/whatsapp/set_automation_handler.go

@@ -0,0 +1,44 @@
+package whatsapp
+
+import (
+	"net/http"
+
+	"github.com/zeromicro/go-zero/rest/httpx"
+
+	"wechat-api/internal/logic/whatsapp"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+)
+
+// swagger:route post /whatsapp/setAutomation whatsapp SetAutomation
+//
+// 编辑开场白
+//
+// 编辑开场白
+//
+// Parameters:
+//  + name: body
+//    require: true
+//    in: body
+//    type: SetAutomationReq
+//
+// Responses:
+//  200: BaseMsgResp
+
+func SetAutomationHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.SetAutomationReq
+		if err := httpx.Parse(r, &req, true); err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+			return
+		}
+
+		l := whatsapp.NewSetAutomationLogic(r.Context(), svcCtx)
+		resp, err := l.SetAutomation(&req)
+		if err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+		} else {
+			httpx.OkJsonCtx(r.Context(), w, resp)
+		}
+	}
+}

+ 44 - 0
internal/handler/whatsapp/submit_whatsapp_code_handler.go

@@ -0,0 +1,44 @@
+package whatsapp
+
+import (
+	"net/http"
+
+	"github.com/zeromicro/go-zero/rest/httpx"
+
+	"wechat-api/internal/logic/whatsapp"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+)
+
+// swagger:route post /whatsapp/submitCode whatsapp SubmitWhatsappCode
+//
+// 提交验证信息
+//
+// 提交验证信息
+//
+// Parameters:
+//  + name: body
+//    require: true
+//    in: body
+//    type: submitCodeReq
+//
+// Responses:
+//  200: BaseMsgResp
+
+func SubmitWhatsappCodeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.SubmitCodeReq
+		if err := httpx.Parse(r, &req, true); err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+			return
+		}
+
+		l := whatsapp.NewSubmitWhatsappCodeLogic(r.Context(), svcCtx)
+		resp, err := l.SubmitWhatsappCode(&req)
+		if err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+		} else {
+			httpx.OkJsonCtx(r.Context(), w, resp)
+		}
+	}
+}

+ 58 - 0
internal/logic/whatsapp/get_automation_logic.go

@@ -0,0 +1,58 @@
+package whatsapp
+
+import (
+	"context"
+	"wechat-api/hook/aliyun"
+
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type GetAutomationLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewGetAutomationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetAutomationLogic {
+	return &GetAutomationLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx}
+}
+
+func (l *GetAutomationLogic) GetAutomation(req *types.AutomationReq) (*types.AutomationResp, error) {
+	resp := types.AutomationResp{}
+	automation, err := aliyun.GetAutomation(*req.WaId, *req.Phone)
+	l.Logger.Infof("automation=%v err=%v\n", automation, err)
+	if err != nil {
+		resp.Msg = err.Error()
+		resp.Code = 1
+	}
+
+	// 获取内容并赋值
+	if automation.Body.Data.Commands != nil {
+		for _, v := range automation.Body.Data.Commands {
+			resp.Data.Commands = append(resp.Data.Commands, types.Command{
+				CommandDescription: *v.CommandDescription,
+				CommandName:        *v.CommandName,
+			})
+		}
+	}
+	if automation.Body.Data.Commands != nil {
+		for _, v := range automation.Body.Data.Prompts {
+			resp.Data.Prompts = append(resp.Data.Prompts, *v)
+		}
+	}
+	if automation.Body.Data.PhoneNumber != nil {
+		resp.Data.PhoneNumber = *automation.Body.Data.PhoneNumber
+	}
+
+	if automation.Body.Data.EnableWelcomeMessage != nil {
+		resp.Data.EnableWelcomeMessage = *automation.Body.Data.EnableWelcomeMessage
+	}
+
+	return &resp, nil
+}

+ 39 - 0
internal/logic/whatsapp/send_whatsapp_code_logic.go

@@ -0,0 +1,39 @@
+package whatsapp
+
+import (
+	"context"
+	"wechat-api/hook/aliyun"
+
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type SendWhatsappCodeLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewSendWhatsappCodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SendWhatsappCodeLogic {
+	return &SendWhatsappCodeLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx}
+}
+
+func (l *SendWhatsappCodeLogic) SendWhatsappCode(req *types.SendCodeReq) (*types.BaseMsgResp, error) {
+	resp := types.BaseMsgResp{}
+	_, err := aliyun.SendCamsCode(*req.Phone, *req.WaId, *req.Method, *req.Locale)
+	l.Logger.Infof("err=%v\n", err)
+
+	if err != nil {
+		resp.Msg = err.Error()
+		resp.Code = 1
+	} else {
+		resp.Msg = "发送成功"
+	}
+
+	return &resp, nil
+}

+ 36 - 0
internal/logic/whatsapp/set_automation_logic.go

@@ -0,0 +1,36 @@
+package whatsapp
+
+import (
+	"context"
+	"wechat-api/hook/aliyun"
+
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type SetAutomationLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewSetAutomationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SetAutomationLogic {
+	return &SetAutomationLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx}
+}
+
+func (l *SetAutomationLogic) SetAutomation(req *types.SetAutomationReq) (*types.BaseMsgResp, error) {
+	resp := types.BaseMsgResp{}
+	_, err := aliyun.SetAutomation(req.WaId, req.PhoneNumber, req.Prompts)
+
+	if err != nil {
+		resp.Code = 1
+		resp.Msg = err.Error()
+	}
+
+	return &resp, nil
+}

+ 36 - 0
internal/logic/whatsapp/submit_whatsapp_code_logic.go

@@ -0,0 +1,36 @@
+package whatsapp
+
+import (
+	"context"
+	"wechat-api/hook/aliyun"
+
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type SubmitWhatsappCodeLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewSubmitWhatsappCodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SubmitWhatsappCodeLogic {
+	return &SubmitWhatsappCodeLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx}
+}
+
+func (l *SubmitWhatsappCodeLogic) SubmitWhatsappCode(req *types.SubmitCodeReq) (*types.BaseMsgResp, error) {
+	resp := types.BaseMsgResp{}
+	_, err := aliyun.SubmitCamsCode(*req.Phone, *req.Code, *req.WaId)
+
+	if err != nil {
+		resp.Msg = err.Error()
+		resp.Code = 1
+	}
+
+	return &resp, nil
+}