From f1a364bae270a43c7a7e31b0dd341ab25bd8301a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=96=B9=E6=88=90?= Date: Sat, 18 Oct 2025 11:18:25 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=B0=8F=E7=A8=8B=E5=BA=8F):=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=B0=8F=E7=A8=8B=E5=BA=8F=E5=AF=86=E9=92=A5=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=B9=B6=E4=BF=AE=E5=A4=8D=E6=9B=B4=E6=96=B0=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E6=98=BE=E7=A4=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加 AppSecret 字段支持小程序认证 修复列表页中更新时间显示错误的问题 新增微信小程序二维码生成接口 --- docs/docs.go | 97 +++++++++++++++++++ docs/swagger.json | 97 +++++++++++++++++++ docs/swagger.yaml | 67 +++++++++++++ internal/api/app/app_list.go | 3 +- internal/api/app/app_modify.go | 10 +- .../repository/mysql/dao/mini_program.gen.go | 6 +- 6 files changed, 274 insertions(+), 6 deletions(-) diff --git a/docs/docs.go b/docs/docs.go index ecc0477..bad5323 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -1109,6 +1109,52 @@ const docTemplate = `{ } } }, + "/api/wechat/qrcode": { + "post": { + "description": "根据 AppID、AppSecret 和页面路径生成微信小程序二维码", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "微信" + ], + "summary": "生成微信小程序二维码", + "parameters": [ + { + "description": "请求参数", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/wechat.generateQRCodeRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/wechat.generateQRCodeResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/code.Failure" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/code.Failure" + } + } + } + } + }, "/app/messages": { "get": { "description": "获取消息日志", @@ -1521,6 +1567,7 @@ const docTemplate = `{ "type": "object", "required": [ "app_id", + "app_secret", "name" ], "properties": { @@ -1528,6 +1575,10 @@ const docTemplate = `{ "description": "小程序ID", "type": "string" }, + "app_secret": { + "description": "小程序密钥", + "type": "string" + }, "avatar": { "description": "头像", "type": "string" @@ -1618,6 +1669,10 @@ const docTemplate = `{ "description": "小程序ID", "type": "string" }, + "app_secret": { + "description": "小程序密钥", + "type": "string" + }, "avatar": { "description": "小程序头像", "type": "string" @@ -1700,6 +1755,7 @@ const docTemplate = `{ "type": "object", "required": [ "app_id", + "app_secret", "name" ], "properties": { @@ -1707,6 +1763,10 @@ const docTemplate = `{ "description": "小程序ID", "type": "string" }, + "app_secret": { + "description": "小程序密钥", + "type": "string" + }, "avatar": { "description": "头像", "type": "string" @@ -2149,6 +2209,43 @@ const docTemplate = `{ "type": "string" } } + }, + "wechat.generateQRCodeRequest": { + "type": "object", + "required": [ + "app_id", + "app_secret", + "path" + ], + "properties": { + "app_id": { + "description": "微信小程序 AppID", + "type": "string" + }, + "app_secret": { + "description": "微信小程序 AppSecret", + "type": "string" + }, + "path": { + "description": "小程序页面路径", + "type": "string" + } + } + }, + "wechat.generateQRCodeResponse": { + "type": "object", + "properties": { + "data": { + "description": "Base64 编码的图片数据", + "type": "string" + }, + "message": { + "type": "string" + }, + "success": { + "type": "boolean" + } + } } }, "securityDefinitions": { diff --git a/docs/swagger.json b/docs/swagger.json index 26a5b86..139bddf 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -1101,6 +1101,52 @@ } } }, + "/api/wechat/qrcode": { + "post": { + "description": "根据 AppID、AppSecret 和页面路径生成微信小程序二维码", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "微信" + ], + "summary": "生成微信小程序二维码", + "parameters": [ + { + "description": "请求参数", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/wechat.generateQRCodeRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/wechat.generateQRCodeResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/code.Failure" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "$ref": "#/definitions/code.Failure" + } + } + } + } + }, "/app/messages": { "get": { "description": "获取消息日志", @@ -1513,6 +1559,7 @@ "type": "object", "required": [ "app_id", + "app_secret", "name" ], "properties": { @@ -1520,6 +1567,10 @@ "description": "小程序ID", "type": "string" }, + "app_secret": { + "description": "小程序密钥", + "type": "string" + }, "avatar": { "description": "头像", "type": "string" @@ -1610,6 +1661,10 @@ "description": "小程序ID", "type": "string" }, + "app_secret": { + "description": "小程序密钥", + "type": "string" + }, "avatar": { "description": "小程序头像", "type": "string" @@ -1692,6 +1747,7 @@ "type": "object", "required": [ "app_id", + "app_secret", "name" ], "properties": { @@ -1699,6 +1755,10 @@ "description": "小程序ID", "type": "string" }, + "app_secret": { + "description": "小程序密钥", + "type": "string" + }, "avatar": { "description": "头像", "type": "string" @@ -2141,6 +2201,43 @@ "type": "string" } } + }, + "wechat.generateQRCodeRequest": { + "type": "object", + "required": [ + "app_id", + "app_secret", + "path" + ], + "properties": { + "app_id": { + "description": "微信小程序 AppID", + "type": "string" + }, + "app_secret": { + "description": "微信小程序 AppSecret", + "type": "string" + }, + "path": { + "description": "小程序页面路径", + "type": "string" + } + } + }, + "wechat.generateQRCodeResponse": { + "type": "object", + "properties": { + "data": { + "description": "Base64 编码的图片数据", + "type": "string" + }, + "message": { + "type": "string" + }, + "success": { + "type": "boolean" + } + } } }, "securityDefinitions": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 04dd342..715df64 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -192,6 +192,9 @@ definitions: app_id: description: 小程序ID type: string + app_secret: + description: 小程序密钥 + type: string avatar: description: 头像 type: string @@ -203,6 +206,7 @@ definitions: type: string required: - app_id + - app_secret - name type: object app.createAppResponse: @@ -258,6 +262,9 @@ definitions: app_id: description: 小程序ID type: string + app_secret: + description: 小程序密钥 + type: string avatar: description: 小程序头像 type: string @@ -319,6 +326,9 @@ definitions: app_id: description: 小程序ID type: string + app_secret: + description: 小程序密钥 + type: string avatar: description: 头像 type: string @@ -330,6 +340,7 @@ definitions: type: string required: - app_id + - app_secret - name type: object app.modifyAppResponse: @@ -635,6 +646,32 @@ definitions: description: 真实图片地址 type: string type: object + wechat.generateQRCodeRequest: + properties: + app_id: + description: 微信小程序 AppID + type: string + app_secret: + description: 微信小程序 AppSecret + type: string + path: + description: 小程序页面路径 + type: string + required: + - app_id + - app_secret + - path + type: object + wechat.generateQRCodeResponse: + properties: + data: + description: Base64 编码的图片数据 + type: string + message: + type: string + success: + type: boolean + type: object info: contact: {} title: mini-chat 接口文档 @@ -1343,6 +1380,36 @@ paths: summary: 上传图片 tags: - 通用 + /api/wechat/qrcode: + post: + consumes: + - application/json + description: 根据 AppID、AppSecret 和页面路径生成微信小程序二维码 + parameters: + - description: 请求参数 + in: body + name: request + required: true + schema: + $ref: '#/definitions/wechat.generateQRCodeRequest' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/wechat.generateQRCodeResponse' + "400": + description: Bad Request + schema: + $ref: '#/definitions/code.Failure' + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/code.Failure' + summary: 生成微信小程序二维码 + tags: + - 微信 /app/messages: get: consumes: diff --git a/internal/api/app/app_list.go b/internal/api/app/app_list.go index a7d100d..cfe4282 100755 --- a/internal/api/app/app_list.go +++ b/internal/api/app/app_list.go @@ -137,11 +137,12 @@ func (h *handler) PageList() core.HandlerFunc { res.List[k] = listData{ ID: v.ID, AppID: v.AppID, + AppSecret: v.AppSecret, Name: v.Name, Description: v.Description, Avatar: v.Avatar, CreatedAt: timeutil.FriendlyTime(v.CreatedAt), - UpdatedAt: timeutil.FriendlyTime(v.CreatedAt), + UpdatedAt: timeutil.FriendlyTime(v.UpdatedAt), } } diff --git a/internal/api/app/app_modify.go b/internal/api/app/app_modify.go index 7e37a8a..6bbc080 100644 --- a/internal/api/app/app_modify.go +++ b/internal/api/app/app_modify.go @@ -14,10 +14,11 @@ import ( ) type modifyAppRequest struct { - AppID string `json:"app_id" binding:"required"` // 小程序ID - Name string `json:"name" binding:"required"` // 名称 - Description string `json:"description"` // 描述 - Avatar string `json:"avatar"` // 头像 + AppID string `json:"app_id" binding:"required"` // 小程序ID + AppSecret string `json:"app_secret" binding:"required"` // 小程序密钥 + Name string `json:"name" binding:"required"` // 名称 + Description string `json:"description"` // 描述 + Avatar string `json:"avatar"` // 头像 } type modifyAppResponse struct { @@ -121,6 +122,7 @@ func (h *handler) ModifyApp() core.HandlerFunc { } checkIdInfo.AppID = req.AppID + checkIdInfo.AppSecret = req.AppSecret checkIdInfo.Name = req.Name checkIdInfo.Description = req.Description checkIdInfo.Avatar = req.Avatar diff --git a/internal/repository/mysql/dao/mini_program.gen.go b/internal/repository/mysql/dao/mini_program.gen.go index 859696c..d467291 100644 --- a/internal/repository/mysql/dao/mini_program.gen.go +++ b/internal/repository/mysql/dao/mini_program.gen.go @@ -29,6 +29,7 @@ func newMiniProgram(db *gorm.DB, opts ...gen.DOOption) miniProgram { _miniProgram.ALL = field.NewAsterisk(tableName) _miniProgram.ID = field.NewInt32(tableName, "id") _miniProgram.AppID = field.NewString(tableName, "app_id") + _miniProgram.AppSecret = field.NewString(tableName, "app_secret") _miniProgram.AdminID = field.NewInt32(tableName, "admin_id") _miniProgram.Name = field.NewString(tableName, "name") _miniProgram.Description = field.NewString(tableName, "description") @@ -50,6 +51,7 @@ type miniProgram struct { ALL field.Asterisk ID field.Int32 // 主键ID AppID field.String // 小程序ID + AppSecret field.String // 小程序密钥 AdminID field.Int32 // 管理员ID Name field.String // 名称 Description field.String // 描述 @@ -76,6 +78,7 @@ func (m *miniProgram) updateTableName(table string) *miniProgram { m.ALL = field.NewAsterisk(table) m.ID = field.NewInt32(table, "id") m.AppID = field.NewString(table, "app_id") + m.AppSecret = field.NewString(table, "app_secret") m.AdminID = field.NewInt32(table, "admin_id") m.Name = field.NewString(table, "name") m.Description = field.NewString(table, "description") @@ -100,9 +103,10 @@ func (m *miniProgram) GetFieldByName(fieldName string) (field.OrderExpr, bool) { } func (m *miniProgram) fillFieldMap() { - m.fieldMap = make(map[string]field.Expr, 10) + m.fieldMap = make(map[string]field.Expr, 11) m.fieldMap["id"] = m.ID m.fieldMap["app_id"] = m.AppID + m.fieldMap["app_secret"] = m.AppSecret m.fieldMap["admin_id"] = m.AdminID m.fieldMap["name"] = m.Name m.fieldMap["description"] = m.Description