This commit is contained in:
@@ -0,0 +1,401 @@
|
||||
package initialize
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/system"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/plugin/plugin-tool/utils"
|
||||
)
|
||||
|
||||
// Api 初始化API权限
|
||||
func Api(ctx context.Context) {
|
||||
// 注册微信集成相关API
|
||||
utils.RegisterApis(
|
||||
// 小程序用户相关API
|
||||
system.SysApi{
|
||||
Path: "/wechat/mini/login",
|
||||
Description: "小程序登录",
|
||||
ApiGroup: "微信小程序",
|
||||
Method: "POST",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mini/userinfo",
|
||||
Description: "获取小程序用户信息",
|
||||
ApiGroup: "微信小程序",
|
||||
Method: "GET",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mini/userinfo",
|
||||
Description: "更新小程序用户信息",
|
||||
ApiGroup: "微信小程序",
|
||||
Method: "PUT",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mini/bind-phone",
|
||||
Description: "绑定手机号",
|
||||
ApiGroup: "微信小程序",
|
||||
Method: "POST",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mini/users",
|
||||
Description: "获取小程序用户列表",
|
||||
ApiGroup: "微信小程序",
|
||||
Method: "GET",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mini/check-unionid",
|
||||
Description: "检查UnionID",
|
||||
ApiGroup: "微信小程序",
|
||||
Method: "GET",
|
||||
},
|
||||
|
||||
// 公众号用户相关API
|
||||
system.SysApi{
|
||||
Path: "/wechat/mp/users",
|
||||
Description: "获取公众号用户列表",
|
||||
ApiGroup: "微信公众号",
|
||||
Method: "GET",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mp/user",
|
||||
Description: "获取公众号用户信息",
|
||||
ApiGroup: "微信公众号",
|
||||
Method: "GET",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mp/user/sync",
|
||||
Description: "同步公众号用户信息",
|
||||
ApiGroup: "微信公众号",
|
||||
Method: "POST",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mp/user/remark",
|
||||
Description: "更新公众号用户备注",
|
||||
ApiGroup: "微信公众号",
|
||||
Method: "PUT",
|
||||
},
|
||||
|
||||
// 公众号消息相关API
|
||||
system.SysApi{
|
||||
Path: "/wechat/mp/messages",
|
||||
Description: "获取公众号消息列表",
|
||||
ApiGroup: "微信公众号",
|
||||
Method: "GET",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mp/message/text",
|
||||
Description: "发送文本消息",
|
||||
ApiGroup: "微信公众号",
|
||||
Method: "POST",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mp/message/image",
|
||||
Description: "发送图片消息",
|
||||
ApiGroup: "微信公众号",
|
||||
Method: "POST",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mp/message/:id",
|
||||
Description: "获取消息详情",
|
||||
ApiGroup: "微信公众号",
|
||||
Method: "GET",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mp/message/:id",
|
||||
Description: "删除消息",
|
||||
ApiGroup: "微信公众号",
|
||||
Method: "DELETE",
|
||||
},
|
||||
|
||||
// 微信Webhook(公开接口)
|
||||
system.SysApi{
|
||||
Path: "/wechat/official/webhook",
|
||||
Description: "微信公众号Webhook",
|
||||
ApiGroup: "微信公众号",
|
||||
Method: "GET",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/official/webhook",
|
||||
Description: "微信公众号Webhook",
|
||||
ApiGroup: "微信公众号",
|
||||
Method: "POST",
|
||||
},
|
||||
|
||||
// 小程序统计相关API
|
||||
system.SysApi{
|
||||
Path: "/wechat/mini/statistics",
|
||||
Description: "获取小程序基础统计数据",
|
||||
ApiGroup: "微信小程序",
|
||||
Method: "GET",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mini/statistics/visit-trend",
|
||||
Description: "获取小程序访问趋势数据",
|
||||
ApiGroup: "微信小程序",
|
||||
Method: "GET",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mini/statistics/source",
|
||||
Description: "获取小程序用户来源分布数据",
|
||||
ApiGroup: "微信小程序",
|
||||
Method: "GET",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mini/statistics/page",
|
||||
Description: "获取小程序页面访问数据",
|
||||
ApiGroup: "微信小程序",
|
||||
Method: "GET",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mini/statistics/retention",
|
||||
Description: "获取小程序用户留存数据",
|
||||
ApiGroup: "微信小程序",
|
||||
Method: "GET",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mini/statistics/device",
|
||||
Description: "获取小程序设备分布数据",
|
||||
ApiGroup: "微信小程序",
|
||||
Method: "GET",
|
||||
},
|
||||
// 公众号标签管理相关API
|
||||
system.SysApi{
|
||||
Path: "/wechat/mp/tag",
|
||||
Description: "获取公众号标签列表",
|
||||
ApiGroup: "微信公众号",
|
||||
Method: "GET",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mp/tag/:id",
|
||||
Description: "获取公众号标签详情",
|
||||
ApiGroup: "微信公众号",
|
||||
Method: "GET",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mp/tag",
|
||||
Description: "创建公众号标签",
|
||||
ApiGroup: "微信公众号",
|
||||
Method: "POST",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mp/tag",
|
||||
Description: "更新公众号标签",
|
||||
ApiGroup: "微信公众号",
|
||||
Method: "PUT",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mp/tag/:id",
|
||||
Description: "删除公众号标签",
|
||||
ApiGroup: "微信公众号",
|
||||
Method: "DELETE",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mp/tag/sync",
|
||||
Description: "同步公众号标签",
|
||||
ApiGroup: "微信公众号",
|
||||
Method: "POST",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mp/tag/list-all-simple",
|
||||
Description: "获取公众号标签简单列表",
|
||||
ApiGroup: "微信公众号",
|
||||
Method: "GET",
|
||||
},
|
||||
|
||||
// 公众号统计数据相关API
|
||||
system.SysApi{
|
||||
Path: "/wechat/mp/statistics",
|
||||
Description: "获取公众号基础统计数据",
|
||||
ApiGroup: "微信公众号",
|
||||
Method: "GET",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mp/statistics/user-growth",
|
||||
Description: "获取公众号用户增长数据",
|
||||
ApiGroup: "微信公众号",
|
||||
Method: "GET",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mp/statistics/message-type",
|
||||
Description: "获取公众号消息类型分布数据",
|
||||
ApiGroup: "微信公众号",
|
||||
Method: "GET",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mp/statistics/message-trend",
|
||||
Description: "获取公众号消息趋势数据",
|
||||
ApiGroup: "微信公众号",
|
||||
Method: "GET",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mp/statistics/region",
|
||||
Description: "获取公众号地区分布数据",
|
||||
ApiGroup: "微信公众号",
|
||||
Method: "GET",
|
||||
},
|
||||
// 公众号图文发表记录相关API
|
||||
system.SysApi{
|
||||
Path: "/wechat/mp/news",
|
||||
Description: "获取公众号图文发表记录列表",
|
||||
ApiGroup: "微信公众号",
|
||||
Method: "GET",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mp/news/:id",
|
||||
Description: "获取公众号图文详情",
|
||||
ApiGroup: "微信公众号",
|
||||
Method: "GET",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mp/news",
|
||||
Description: "创建公众号图文记录",
|
||||
ApiGroup: "微信公众号",
|
||||
Method: "POST",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mp/news",
|
||||
Description: "更新公众号图文记录",
|
||||
ApiGroup: "微信公众号",
|
||||
Method: "PUT",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mp/news/:id",
|
||||
Description: "删除公众号图文记录",
|
||||
ApiGroup: "微信公众号",
|
||||
Method: "DELETE",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mp/news/:id/statistics",
|
||||
Description: "获取公众号图文数据统计",
|
||||
ApiGroup: "微信公众号",
|
||||
Method: "GET",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mp/news/sync",
|
||||
Description: "同步公众号图文发表记录",
|
||||
ApiGroup: "微信公众号",
|
||||
Method: "POST",
|
||||
},
|
||||
|
||||
// 微信配置管理相关API
|
||||
system.SysApi{
|
||||
Path: "/wechat/mp/config",
|
||||
Description: "获取微信配置",
|
||||
ApiGroup: "微信公众号",
|
||||
Method: "GET",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mp/config",
|
||||
Description: "保存微信配置",
|
||||
ApiGroup: "微信公众号",
|
||||
Method: "POST",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mp/config/test",
|
||||
Description: "测试微信配置",
|
||||
ApiGroup: "微信公众号",
|
||||
Method: "POST",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mp/config/validate",
|
||||
Description: "验证微信配置",
|
||||
ApiGroup: "微信公众号",
|
||||
Method: "POST",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mp/qrcode/generate",
|
||||
Description: "生成公众号二维码",
|
||||
ApiGroup: "微信公众号",
|
||||
Method: "POST",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mp/quota/clear",
|
||||
Description: "清空API配额",
|
||||
ApiGroup: "微信公众号",
|
||||
Method: "POST",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mp/config/list",
|
||||
Description: "获取微信配置列表",
|
||||
ApiGroup: "微信公众号",
|
||||
Method: "GET",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mp/config/:id",
|
||||
Description: "删除微信配置",
|
||||
ApiGroup: "微信公众号",
|
||||
Method: "DELETE",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mp/webhook/logs",
|
||||
Description: "获取Webhook日志",
|
||||
ApiGroup: "微信公众号",
|
||||
Method: "GET",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mp/webhook/logs/:id",
|
||||
Description: "获取Webhook日志详情",
|
||||
ApiGroup: "微信公众号",
|
||||
Method: "GET",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mp/webhook/logs/clear",
|
||||
Description: "清空Webhook日志",
|
||||
ApiGroup: "微信公众号",
|
||||
Method: "POST",
|
||||
},
|
||||
|
||||
// 公众号草稿管理相关API
|
||||
system.SysApi{
|
||||
Path: "/wechat/mp/draft",
|
||||
Description: "获取公众号草稿列表",
|
||||
ApiGroup: "微信公众号",
|
||||
Method: "GET",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mp/draft/:id",
|
||||
Description: "获取公众号草稿详情",
|
||||
ApiGroup: "微信公众号",
|
||||
Method: "GET",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mp/draft",
|
||||
Description: "创建公众号草稿",
|
||||
ApiGroup: "微信公众号",
|
||||
Method: "POST",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mp/draft",
|
||||
Description: "更新公众号草稿",
|
||||
ApiGroup: "微信公众号",
|
||||
Method: "PUT",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mp/draft/:id",
|
||||
Description: "删除公众号草稿",
|
||||
ApiGroup: "微信公众号",
|
||||
Method: "DELETE",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mp/draft/:id/publish",
|
||||
Description: "发布公众号草稿",
|
||||
ApiGroup: "微信公众号",
|
||||
Method: "POST",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mp/draft/sync",
|
||||
Description: "同步公众号草稿",
|
||||
ApiGroup: "微信公众号",
|
||||
Method: "POST",
|
||||
},
|
||||
system.SysApi{
|
||||
Path: "/wechat/mp/draft/count",
|
||||
Description: "获取公众号草稿数量统计",
|
||||
ApiGroup: "微信公众号",
|
||||
Method: "GET",
|
||||
},
|
||||
)
|
||||
|
||||
global.GVA_LOG.Info("微信集成API权限注册完成")
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package initialize
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/plugin/wechat-integration/model"
|
||||
)
|
||||
|
||||
// Gorm 初始化数据库表
|
||||
func Gorm(ctx context.Context) {
|
||||
// 自动迁移数据库表
|
||||
err := global.GVA_DB.WithContext(ctx).AutoMigrate(
|
||||
&model.WechatMiniUser{},
|
||||
&model.MpUser{},
|
||||
&model.MpMessage{},
|
||||
&model.MpMenu{},
|
||||
&model.MpAutoReply{},
|
||||
&model.MpMaterial{},
|
||||
&model.MpNews{},
|
||||
&model.MpConfig{},
|
||||
&model.MpWebhookLog{},
|
||||
&model.MpDraft{},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("微信集成插件数据库表迁移失败: " + err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
global.GVA_LOG.Info("微信集成插件数据库表迁移完成")
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package initialize
|
||||
|
||||
import (
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/middleware"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/plugin/wechat-integration/router"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// Router 初始化路由
|
||||
func Router(engine *gin.Engine) {
|
||||
// 获取路由组,微信插件使用/api前缀与前端匹配
|
||||
publicGroup := engine.Group("")
|
||||
privateGroup := engine.Group("")
|
||||
|
||||
// 添加JWT认证和Casbin权限中间件
|
||||
privateGroup.Use(middleware.JWTAuth()).Use(middleware.CasbinHandler())
|
||||
|
||||
// 初始化微信路由
|
||||
wechatRouter := router.WechatRouter{}
|
||||
|
||||
// 公开路由(不需要认证)
|
||||
wechatRouter.InitWechatPublicRouter(publicGroup)
|
||||
|
||||
// 私有路由(需要认证)
|
||||
wechatRouter.InitWechatRouter(privateGroup)
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package initialize
|
||||
|
||||
import (
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/plugin/wechat-integration/config"
|
||||
)
|
||||
|
||||
// Viper 初始化配置
|
||||
func Viper() {
|
||||
// 微信配置已经在主配置文件中定义,这里只需要验证
|
||||
if global.GVA_CONFIG.Wechat.MiniAppID == "" {
|
||||
global.GVA_LOG.Warn("微信小程序 AppID 未配置")
|
||||
}
|
||||
|
||||
if global.GVA_CONFIG.Wechat.OfficialAppID == "" {
|
||||
global.GVA_LOG.Warn("微信公众号 AppID 未配置")
|
||||
}
|
||||
|
||||
if global.GVA_CONFIG.Wechat.OfficialToken == "" {
|
||||
global.GVA_LOG.Warn("微信公众号 Token 未配置")
|
||||
}
|
||||
|
||||
global.GVA_LOG.Info("微信集成插件配置验证完成")
|
||||
}
|
||||
|
||||
// GetWechatConfig 获取微信配置
|
||||
func GetWechatConfig() config.WechatConfig {
|
||||
return config.WechatConfig{
|
||||
MiniAppID: global.GVA_CONFIG.Wechat.MiniAppID,
|
||||
MiniAppSecret: global.GVA_CONFIG.Wechat.MiniAppSecret,
|
||||
OfficialAppID: global.GVA_CONFIG.Wechat.OfficialAppID,
|
||||
OfficialAppSecret: global.GVA_CONFIG.Wechat.OfficialAppSecret,
|
||||
OfficialToken: global.GVA_CONFIG.Wechat.OfficialToken,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user