Эх сурвалжийг харах

账号管理页面,在退出登录时杀掉进程

boweniac 6 сар өмнө
parent
commit
a538c69344

+ 4 - 0
desc/wechat/wxhook.api

@@ -100,6 +100,10 @@ service Wechat {
     @handler logout
     post /wxhook/logout (IDReq) returns (BaseMsgResp)
 
+    // 结束微信
+    @handler terminateThisWeChat
+    post /wxhook/terminateThisWeChat (IDReq) returns (BaseMsgResp)
+
     // 获取好友和群信息
     @handler getFriendsAndGroups
     post /wxhook/getFriendsAndGroups (IDReq) returns (BaseMsgResp)

+ 15 - 0
hook/sys.go

@@ -18,6 +18,21 @@ func (h *Hook) Logout() (result LogoutResp, err error) {
 	return
 }
 
+// 结束微信
+func (h *Hook) TerminateThisWeChat(pid string) (result LogoutResp, err error) {
+	resp, err := h.Client.R().SetBody(&TerminateThisWeChatReq{
+		PID: pid,
+	}).SetSuccessResult(&result).Post("http://" + h.ServerIp + ":" + h.AdminPort + "/TerminateThisWeChat")
+	if err != nil {
+		return
+	}
+	if !resp.IsSuccessState() {
+		err = fmt.Errorf("TerminateThisWeChatReq failed with status code %d", resp.StatusCode)
+		return
+	}
+	return
+}
+
 // 获取微信总数
 func (h *Hook) GetWeChatProcessNumber() (result GetWeChatProcessNumberResp, err error) {
 	resp, err := h.Client.R().SetSuccessResult(&result).Post("http://" + h.ServerIp + ":" + h.AdminPort + "/Get_WeChatProcessNumber")

+ 4 - 0
hook/type.go

@@ -203,6 +203,10 @@ type StartWechatReq struct {
 	StartPort string `json:"StartPort"`
 }
 
+type TerminateThisWeChatReq struct {
+	PID string `json:"PID"`
+}
+
 type StartWechatResp struct {
 	StartPort string `json:"StartPort"`
 	Success   string `json:"success"`

+ 44 - 0
internal/handler/Wxhook/terminate_this_we_chat_handler.go

@@ -0,0 +1,44 @@
+package Wxhook
+
+import (
+	"net/http"
+
+	"github.com/zeromicro/go-zero/rest/httpx"
+
+	"wechat-api/internal/logic/Wxhook"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+)
+
+// swagger:route post /wxhook/terminateThisWeChat Wxhook TerminateThisWeChat
+//
+// 结束微信
+//
+// 结束微信
+//
+// Parameters:
+//  + name: body
+//    require: true
+//    in: body
+//    type: IDReq
+//
+// Responses:
+//  200: BaseMsgResp
+
+func TerminateThisWeChatHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.IDReq
+		if err := httpx.Parse(r, &req, true); err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+			return
+		}
+
+		l := Wxhook.NewTerminateThisWeChatLogic(r.Context(), svcCtx)
+		resp, err := l.TerminateThisWeChat(&req)
+		if err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+		} else {
+			httpx.OkJsonCtx(r.Context(), w, resp)
+		}
+	}
+}

+ 5 - 0
internal/handler/routes.go

@@ -212,6 +212,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 				},
 				{
 					Method:  http.MethodPost,
+					Path:    "/wxhook/terminateThisWeChat",
+					Handler: Wxhook.TerminateThisWeChatHandler(serverCtx),
+				},
+				{
+					Method:  http.MethodPost,
 					Path:    "/wxhook/getFriendsAndGroups",
 					Handler: Wxhook.GetFriendsAndGroupsHandler(serverCtx),
 				},

+ 1 - 1
internal/logic/Wxhook/logout_logic.go

@@ -59,6 +59,6 @@ func (l *LogoutLogic) Logout(req *types.IDReq) (resp *types.BaseMsgResp, err err
 	} else {
 		resp.Code = errorcode.Unknown
 	}
-
+	_, _ = hookClient.TerminateThisWeChat(wxInfo.ProcessID)
 	return
 }

+ 29 - 0
internal/logic/Wxhook/terminate_this_we_chat_logic.go

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