From 4001993e96259b353b1834019f21864665fb7173 Mon Sep 17 00:00:00 2001 From: summer <> Date: Wed, 5 Nov 2025 16:43:44 +0800 Subject: [PATCH] =?UTF-8?q?feat(1.0):=20=E8=B0=83=E6=95=B4=E6=A8=A1?= =?UTF-8?q?=E7=89=88=E5=8F=98=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/docs.go | 4 ++ docs/swagger.json | 4 ++ docs/swagger.yaml | 3 ++ internal/api/app/app_list.go | 74 ++++++++++++++++++++++++++---------- 4 files changed, 65 insertions(+), 20 deletions(-) diff --git a/docs/docs.go b/docs/docs.go index 7cab7b7..39eb42a 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -1946,6 +1946,10 @@ const docTemplate = `{ "description": "小程序头像", "type": "string" }, + "check_status_text": { + "description": "状态文字描述", + "type": "string" + }, "created_at": { "description": "创建时间", "type": "string" diff --git a/docs/swagger.json b/docs/swagger.json index 8757102..c0eda75 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -1938,6 +1938,10 @@ "description": "小程序头像", "type": "string" }, + "check_status_text": { + "description": "状态文字描述", + "type": "string" + }, "created_at": { "description": "创建时间", "type": "string" diff --git a/docs/swagger.yaml b/docs/swagger.yaml index d3168cf..dbaeff6 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -311,6 +311,9 @@ definitions: avatar: description: 小程序头像 type: string + check_status_text: + description: 状态文字描述 + type: string created_at: description: 创建时间 type: string diff --git a/internal/api/app/app_list.go b/internal/api/app/app_list.go index 0d4c97f..330bf99 100755 --- a/internal/api/app/app_list.go +++ b/internal/api/app/app_list.go @@ -6,9 +6,11 @@ import ( "mini-chat/internal/code" "mini-chat/internal/pkg/core" + "mini-chat/internal/pkg/httpclient" "mini-chat/internal/pkg/timeutil" "mini-chat/internal/pkg/validation" + "go.uber.org/zap" "gorm.io/gorm" ) @@ -21,16 +23,17 @@ type listRequest struct { } type listData struct { - ID int32 `json:"id"` // 小程序编号 - AppID string `json:"app_id"` // 小程序ID - AppSecret string `json:"app_secret"` // 小程序密钥 - Name string `json:"name"` // 小程序名称 - Description string `json:"description"` // 小程序描述 - Avatar string `json:"avatar"` // 小程序头像 - TemplateID string `json:"template_id"` // 模版ID - CreatedAt string `json:"created_at"` // 创建时间 - UpdatedAt string `json:"updated_at"` // 更新时间 - MessageTotal int64 `json:"message_total"` // 消息总数 + ID int32 `json:"id"` // 小程序编号 + AppID string `json:"app_id"` // 小程序ID + AppSecret string `json:"app_secret"` // 小程序密钥 + Name string `json:"name"` // 小程序名称 + Description string `json:"description"` // 小程序描述 + Avatar string `json:"avatar"` // 小程序头像 + TemplateID string `json:"template_id"` // 模版ID + CreatedAt string `json:"created_at"` // 创建时间 + UpdatedAt string `json:"updated_at"` // 更新时间 + MessageTotal int64 `json:"message_total"` // 消息总数 + CheckStatusText string `json:"check_status_text"` // 状态文字描述 } type listResponse struct { @@ -135,19 +138,50 @@ func (h *handler) PageList() core.HandlerFunc { res.Total = count res.List = make([]listData, len(resultData)) + type checkAppResponse struct { + Code int `json:"code"` + Appid string `json:"appid"` + Status string `json:"status"` + } + + checkAppRes := new(checkAppResponse) for k, v := range resultData { messageTotalCount, _ := h.readDB.AppMessageLog.WithContext(ctx.RequestContext()).Where(h.readDB.AppMessageLog.AppID.Eq(v.AppID)).Count() + checkStatusText := "未知" + response, err := httpclient.GetHttpClientWithContext(ctx.RequestContext()).R(). + SetQueryParams(map[string]string{ + "appid": v.AppID, + }). + SetResult(checkAppRes). + Get("https://api.wxapi.work/xcx/checkxcx.php") + + if err != nil { + h.logger.Error("请求失败", zap.Error(err)) + } + + // 检查响应状态码 + if response.IsError() { + h.logger.Error(fmt.Sprintf("请求APP验证服务异常(%d)", response.StatusCode())) + } + + if checkAppRes.Code == 1 { + checkStatusText = "正常" + } else if checkAppRes.Code == 0 { + checkStatusText = "封禁" + } + res.List[k] = listData{ - ID: v.ID, - AppID: v.AppID, - AppSecret: v.AppSecret, - Name: v.Name, - Description: v.Description, - Avatar: v.Avatar, - TemplateID: v.TemplateID, - CreatedAt: timeutil.FriendlyTime(v.CreatedAt), - UpdatedAt: timeutil.FriendlyTime(v.UpdatedAt), - MessageTotal: messageTotalCount, + ID: v.ID, + AppID: v.AppID, + AppSecret: v.AppSecret, + Name: v.Name, + Description: v.Description, + Avatar: v.Avatar, + TemplateID: v.TemplateID, + CreatedAt: timeutil.FriendlyTime(v.CreatedAt), + UpdatedAt: timeutil.FriendlyTime(v.UpdatedAt), + MessageTotal: messageTotalCount, + CheckStatusText: checkStatusText, } }