feat(小程序): 添加小程序密钥支持并修复更新时间显示问题

添加 AppSecret 字段支持小程序认证
修复列表页中更新时间显示错误的问题
新增微信小程序二维码生成接口
This commit is contained in:
邹方成 2025-10-18 11:18:25 +08:00
parent 23e7d42531
commit f1a364bae2
6 changed files with 274 additions and 6 deletions

View File

@ -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": {

View File

@ -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": {

View File

@ -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:

View File

@ -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),
}
}

View File

@ -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

View File

@ -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