浏览代码

生成 logic 文件

boweniac 3 天之前
父节点
当前提交
8c99533638

+ 2 - 1
desc/all.api

@@ -50,4 +50,5 @@ import "./wechat/fastgpt.api"
 import "./wechat/department.api"
 import "./wechat/api_key.api"
 import "./wechat/auth_login.api"
-import "./wechat/contact_field_template.api"
+import "./wechat/contact_field_template.api"
+import "./wechat/add_wechat_friend_log.api"

+ 4 - 4
desc/wechat/add_friend_by_phone.api → desc/wechat/add_wechat_friend_log.api

@@ -3,22 +3,22 @@ import "../base.api"
 type (
     
     //add_friend_by_phone api接口请求值
-    AddFriendByPhoneNewReq {
+    AddWechatFriendLogInfo {
         Type int `json:"type"`
         WeChatIds []string `json:"WeChatId,optional,omitempty"`
         Phone string `json:"phone"`
         Message string `json:"message"`
     }
-
+)
 
 @server(
     jwt: Auth
-    group: Wx
+    group: add_friend
     middleware: Authority
 )
 
 service Wechat {
     // 手机号加好友接口
     @handler AddFriendByPhone
-    post /wx/add_friend_by_phone (AddFriendByPhoneNewReq) returns (BaseMsgResp)
+    post /add_friend/add_friend_by_phone (AddWechatFriendLogInfo) returns (BaseMsgResp)
 } 

+ 44 - 0
internal/handler/add_friend/add_friend_by_phone_handler.go

@@ -0,0 +1,44 @@
+package add_friend
+
+import (
+	"net/http"
+
+	"github.com/zeromicro/go-zero/rest/httpx"
+
+	"wechat-api/internal/logic/add_friend"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+)
+
+// swagger:route post /add_friend/add_friend_by_phone add_friend AddFriendByPhone
+//
+// 手机号加好友接口
+//
+// 手机号加好友接口
+//
+// Parameters:
+//  + name: body
+//    require: true
+//    in: body
+//    type: AddWechatFriendLogInfo
+//
+// Responses:
+//  200: BaseMsgResp
+
+func AddFriendByPhoneHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.AddWechatFriendLogInfo
+		if err := httpx.Parse(r, &req, true); err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+			return
+		}
+
+		l := add_friend.NewAddFriendByPhoneLogic(r.Context(), svcCtx)
+		resp, err := l.AddFriendByPhone(&req)
+		if err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+		} else {
+			httpx.OkJsonCtx(r.Context(), w, resp)
+		}
+	}
+}

+ 15 - 0
internal/handler/routes.go

@@ -16,6 +16,7 @@ import (
 	WorkPhone "wechat-api/internal/handler/WorkPhone"
 	Wx "wechat-api/internal/handler/Wx"
 	Wxhook "wechat-api/internal/handler/Wxhook"
+	add_friend "wechat-api/internal/handler/add_friend"
 	agent "wechat-api/internal/handler/agent"
 	agent_base "wechat-api/internal/handler/agent_base"
 	aliyun_avatar "wechat-api/internal/handler/aliyun_avatar"
@@ -2340,4 +2341,18 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 			},
 		},
 	)
+
+	server.AddRoutes(
+		rest.WithMiddlewares(
+			[]rest.Middleware{serverCtx.Authority},
+			[]rest.Route{
+				{
+					Method:  http.MethodPost,
+					Path:    "/add_friend/add_friend_by_phone",
+					Handler: add_friend.AddFriendByPhoneHandler(serverCtx),
+				},
+			}...,
+		),
+		rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
+	)
 }

+ 29 - 0
internal/logic/add_friend/add_friend_by_phone_logic.go

@@ -0,0 +1,29 @@
+package add_friend
+
+import (
+	"context"
+
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type AddFriendByPhoneLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewAddFriendByPhoneLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddFriendByPhoneLogic {
+	return &AddFriendByPhoneLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx}
+}
+
+func (l *AddFriendByPhoneLogic) AddFriendByPhone(req *types.AddWechatFriendLogInfo) (resp *types.BaseMsgResp, err error) {
+	// todo: add your logic here and delete this line
+
+	return
+}

+ 9 - 0
internal/types/types.go

@@ -4711,3 +4711,12 @@ type LoginResp struct {
 	// The log in information | 登陆返回的数据信息
 	Data LoginInfo `json:"data"`
 }
+
+// add_friend_by_phone api接口请求值
+// swagger:model AddWechatFriendLogInfo
+type AddWechatFriendLogInfo struct {
+	Type      int      `json:"type"`
+	WeChatIds []string `json:"WeChatId,optional,omitempty"`
+	Phone     string   `json:"phone"`
+	Message   string   `json:"message"`
+}