Browse Source

Merge branch 'yhg_250102' into debug

jimmyyem 2 months ago
parent
commit
78d4761680

+ 16 - 0
desc/wechat/whatsapp.api

@@ -211,6 +211,14 @@ type (
 		Websites []string  `json:"websites,optional"`
 		About string `json:"about,optional"`
 	}
+	registerReq {
+		Phone  *string `json:"phone"`
+		WaId  *string `json:"waId"`
+	}
+	deregisterReq {
+		Phone  *string `json:"phone"`
+		WaId  *string `json:"waId"`
+	}
 )
 
 @server(
@@ -279,4 +287,12 @@ service Wechat {
 	// 设置商业信息
 	@handler setBusinessInfo
 	post /whatsapp/setBusinessInfo (setBusinessReq) returns (BaseMsgResp)
+
+	// 注册WhatsApp号码
+	@handler registerPhoneNumber
+	post /whatsapp/registerPhoneNumber (registerReq) returns (BaseMsgResp)
+
+	// 取消注册WhatsApp号码
+	@handler deregisterPhoneNumber
+	post /whatsapp/deregisterPhoneNumber (deregisterReq) returns (BaseMsgResp)
 }

+ 60 - 0
hook/aliyun/whatsapp.go

@@ -294,3 +294,63 @@ func SetCamsBusiness(phone, custSpaceId, address, description, vertical, email,
 
 	return response, nil
 }
+
+// GetCamsPhoneVerifyStatus 查询号码验证状态
+func GetCamsPhoneVerifyStatus(phone, custSpaceId string) (*cams20200606.GetPhoneNumberVerificationStatusResponse, error) {
+	client, _err := CreateCamsClient()
+	if _err != nil {
+		return nil, _err
+	}
+
+	request := &cams20200606.GetPhoneNumberVerificationStatusRequest{
+		PhoneNumber: tea.String(phone),
+		CustSpaceId: tea.String(custSpaceId),
+	}
+
+	response, _err := client.GetPhoneNumberVerificationStatus(request)
+	if _err != nil {
+		return nil, _err
+	}
+
+	return response, nil
+}
+
+// RegisterCamsPhoneNumber 号码注册
+func RegisterCamsPhoneNumber(phone, custSpaceId string) (*cams20200606.ChatappPhoneNumberRegisterResponse, error) {
+	client, _err := CreateCamsClient()
+	if _err != nil {
+		return nil, _err
+	}
+
+	request := &cams20200606.ChatappPhoneNumberRegisterRequest{
+		PhoneNumber: tea.String(phone),
+		CustSpaceId: tea.String(custSpaceId),
+	}
+
+	response, _err := client.ChatappPhoneNumberRegister(request)
+	if _err != nil {
+		return nil, _err
+	}
+
+	return response, nil
+}
+
+// DeRegisterCamsPhoneNumber 号码取消注册
+func DeRegisterCamsPhoneNumber(phone, custSpaceId string) (*cams20200606.ChatappPhoneNumberDeregisterResponse, error) {
+	client, _err := CreateCamsClient()
+	if _err != nil {
+		return nil, _err
+	}
+
+	request := &cams20200606.ChatappPhoneNumberDeregisterRequest{
+		PhoneNumber: tea.String(phone),
+		CustSpaceId: tea.String(custSpaceId),
+	}
+
+	response, _err := client.ChatappPhoneNumberDeregister(request)
+	if _err != nil {
+		return nil, _err
+	}
+
+	return response, nil
+}

+ 10 - 0
internal/handler/routes.go

@@ -1854,6 +1854,16 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 					Path:    "/whatsapp/setBusinessInfo",
 					Handler: whatsapp.SetBusinessInfoHandler(serverCtx),
 				},
+				{
+					Method:  http.MethodPost,
+					Path:    "/whatsapp/registerPhoneNumber",
+					Handler: whatsapp.RegisterPhoneNumberHandler(serverCtx),
+				},
+				{
+					Method:  http.MethodPost,
+					Path:    "/whatsapp/deregisterPhoneNumber",
+					Handler: whatsapp.DeregisterPhoneNumberHandler(serverCtx),
+				},
 			}...,
 		),
 		rest.WithJwt(serverCtx.Config.Auth.AccessSecret),

+ 44 - 0
internal/handler/whatsapp/deregister_phone_number_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/deregisterPhoneNumber whatsapp DeregisterPhoneNumber
+//
+// 取消注册WhatsApp号码
+//
+// 取消注册WhatsApp号码
+//
+// Parameters:
+//  + name: body
+//    require: true
+//    in: body
+//    type: deregisterReq
+//
+// Responses:
+//  200: BaseMsgResp
+
+func DeregisterPhoneNumberHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.DeregisterReq
+		if err := httpx.Parse(r, &req, true); err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+			return
+		}
+
+		l := whatsapp.NewDeregisterPhoneNumberLogic(r.Context(), svcCtx)
+		resp, err := l.DeregisterPhoneNumber(&req)
+		if err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+		} else {
+			httpx.OkJsonCtx(r.Context(), w, resp)
+		}
+	}
+}

+ 44 - 0
internal/handler/whatsapp/register_phone_number_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/registerPhoneNumber whatsapp RegisterPhoneNumber
+//
+// 注册WhatsApp号码
+//
+// 注册WhatsApp号码
+//
+// Parameters:
+//  + name: body
+//    require: true
+//    in: body
+//    type: registerReq
+//
+// Responses:
+//  200: BaseMsgResp
+
+func RegisterPhoneNumberHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.RegisterReq
+		if err := httpx.Parse(r, &req, true); err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+			return
+		}
+
+		l := whatsapp.NewRegisterPhoneNumberLogic(r.Context(), svcCtx)
+		resp, err := l.RegisterPhoneNumber(&req)
+		if err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+		} else {
+			httpx.OkJsonCtx(r.Context(), w, resp)
+		}
+	}
+}

+ 36 - 0
internal/logic/whatsapp/deregister_phone_number_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 DeregisterPhoneNumberLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewDeregisterPhoneNumberLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeregisterPhoneNumberLogic {
+	return &DeregisterPhoneNumberLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx}
+}
+
+func (l *DeregisterPhoneNumberLogic) DeregisterPhoneNumber(req *types.DeregisterReq) (*types.BaseMsgResp, error) {
+	resp := types.BaseMsgResp{Msg: "取消注册成功"}
+
+	_, err := aliyun.DeRegisterCamsPhoneNumber(*req.Phone, *req.WaId)
+	if err != nil {
+		resp.Msg = err.Error()
+		resp.Code = 1
+	}
+
+	return &resp, nil
+}

+ 36 - 0
internal/logic/whatsapp/register_phone_number_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 RegisterPhoneNumberLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewRegisterPhoneNumberLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RegisterPhoneNumberLogic {
+	return &RegisterPhoneNumberLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx}
+}
+
+func (l *RegisterPhoneNumberLogic) RegisterPhoneNumber(req *types.RegisterReq) (*types.BaseMsgResp, error) {
+	resp := types.BaseMsgResp{Msg: "注册成功"}
+
+	_, err := aliyun.RegisterCamsPhoneNumber(*req.Phone, *req.WaId)
+	if err != nil {
+		resp.Msg = err.Error()
+		resp.Code = 1
+	}
+
+	return &resp, nil
+}

+ 12 - 0
internal/types/types.go

@@ -3626,6 +3626,18 @@ type SetBusinessReq struct {
 	About             string   `json:"about,optional"`
 }
 
+// swagger:model registerReq
+type RegisterReq struct {
+	Phone *string `json:"phone"`
+	WaId  *string `json:"waId"`
+}
+
+// swagger:model deregisterReq
+type DeregisterReq struct {
+	Phone *string `json:"phone"`
+	WaId  *string `json:"waId"`
+}
+
 // The data of whatsapp channel information | WhatsappChannel信息
 // swagger:model WhatsappChannelInfo
 type WhatsappChannelInfo struct {