Compare commits

..

No commits in common. "55d219b364d02bd6c3d9b847beb423f2ec033067" and "685ce618a94e6b8ca914b173047270c71604b562" have entirely different histories.

222 changed files with 4571 additions and 11949 deletions

View File

@ -1,54 +0,0 @@
name: BuildImage
on:
push:
# branches:
# - main
tags:
- '*'
jobs:
build-image:
runs-on: ubuntu-latest
container:
# 使用这个镜像不然Docker无法打包镜像
image: catthehacker/ubuntu:act-latest
steps:
- name: Setup Golang
uses: actions/setup-go@v3
with:
go-version: '>=1.21.0'
cache: false
- name: Checkout Code
uses: actions/checkout@v3
- name: Gen Tags
id: gen_tags
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: gitee.ltd/lxh/go-wxhelper
tags: |
type=ref,event=branch
type=ref,event=tag
- name: Print Tags
run: |
echo "${{ steps.gen_tags.outputs.tags }}"
echo "----------------- labels -----------------"
echo "${{ steps.meta.outputs.labels }}"
- name: Login to Repository
uses: docker/login-action@v2
with:
registry: gitee.ltd
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
- name: Build image
uses: docker/build-push-action@v2
with:
push: true
tags: ${{ steps.gen_tags.outputs.tags }}
labels: ${{ steps.gen_tags.outputs.labels }}

13
.gitignore vendored
View File

@ -1,11 +1,10 @@
.idea
vendor
logs
*.exe
*.pprof
cache
log
*build*
debug
dist
*.log
blacklist.txt
frontend.*
*_deleted*
config.yaml

View File

@ -1,21 +1,18 @@
FROM golang:alpine as builder
WORKDIR /builder
COPY . .
#ENV GO111MODULE=on
#ENV GOPROXY=https://goproxy.cn,direct
RUN go version
RUN go mod download && go build -o wxhelper
RUN ls -lh && chmod -R +x ./*
RUN go mod download
RUN go build -o app
RUN ls -lh && chmod +x ./app
FROM code.hyxc1.com/open/alpine:3.16.0 as runner
LABEL org.opencontainers.image.authors="lxh@cxh.cn"
EXPOSE 19099
EXPOSE 8080
# 定义一下版本号
ARG APP_VER
ENV APP_VER=${APP_VER}
WORKDIR /app
COPY --from=builder /builder/wxhelper ./wxhelper
COPY --from=builder /builder/views ./views
CMD ./wxhelper
COPY --from=builder /builder/app ./app
CMD ./app

View File

@ -0,0 +1,25 @@
package aiassistant
import (
"github.com/gin-gonic/gin"
"unicode/utf8"
"wechat-robot/pkg/response"
aiAssistantService "wechat-robot/service/aiassistant"
)
// DeleteById
// @description: 删除AI助手
// @param ctx
func DeleteById(ctx *gin.Context) {
var id = ctx.Param("id")
if utf8.RuneCountInString(id) != 32 {
response.New(ctx).SetMsg("参数错误").Fail()
return
}
// 删除数据
if err := aiAssistantService.DeleteById(id); err != nil {
response.New(ctx).SetMsg("删除失败").SetError(err).Fail()
} else {
response.New(ctx).SetMsg("删除成功").Success()
}
}

View File

@ -0,0 +1,25 @@
package aiassistant
import (
"github.com/gin-gonic/gin"
"wechat-robot/model/param/aiassistant"
"wechat-robot/pkg/response"
aiAssistantService "wechat-robot/service/aiassistant"
)
// Save
// @description: 保存AI助手
// @param ctx
func Save(ctx *gin.Context) {
var p aiassistant.Save
if err := ctx.ShouldBind(&p); err != nil {
response.New(ctx).SetMsg("参数错误").SetError(err).Fail()
return
}
// 保存数据
if err := aiAssistantService.Save(p); err != nil {
response.New(ctx).SetMsg("保存失败").SetError(err).Fail()
return
}
response.New(ctx).SetMsg("保存成功").Success()
}

View File

@ -0,0 +1,26 @@
package aiassistant
import (
"github.com/gin-gonic/gin"
"wechat-robot/model/param/aiassistant"
"wechat-robot/pkg/response"
aiAssistantService "wechat-robot/service/aiassistant"
)
// GetAll
// @description: 获取所有AI助手
// @param ctx
func GetAll(ctx *gin.Context) {
var p aiassistant.GetAll
if err := ctx.ShouldBind(&p); err != nil {
response.New(ctx).SetMsg("参数错误").SetError(err).Fail()
return
}
records, err := aiAssistantService.GetAll(p)
if err != nil {
response.New(ctx).SetMsg("获取失败").SetError(err).Fail()
return
}
response.New(ctx).SetData(records).Success()
}

View File

@ -0,0 +1,34 @@
package login
import (
"github.com/gin-gonic/gin"
"github.com/mojocn/base64Captcha"
"wechat-robot/model/vo/login"
"wechat-robot/pkg/captcha"
"wechat-robot/pkg/response"
)
// GetImgCaptcha
// @description: 获取图片验证码
// @param ctx
func GetImgCaptcha(ctx *gin.Context) {
store := new(captcha.RedisStore)
math := base64Captcha.DriverMath{
Height: 60,
Width: 240,
Fonts: []string{"ApothecaryFont.ttf"},
}
driver := math.ConvertFonts()
// 验证码生成器
c := base64Captcha.NewCaptcha(driver, store)
id, imgStr, _, err := c.Generate()
if err != nil {
response.New(ctx).SetMsg("验证码生成失败").Fail()
return
}
// 数据返回
result := login.CaptchaCode{Id: id, Img: imgStr}
response.New(ctx).SetData(result).Success()
}

120
api/admin/login/login.go Normal file
View File

@ -0,0 +1,120 @@
package login
import (
"context"
"encoding/json"
"gitee.ltd/lxh/logger/log"
"github.com/gin-gonic/gin"
"net/http"
"net/url"
"wechat-robot/internal/redis"
"wechat-robot/model/param/login"
"wechat-robot/pkg/auth"
"wechat-robot/pkg/captcha"
"wechat-robot/pkg/response"
userService "wechat-robot/service/adminuser"
)
// Login
// @description: 登录
// @param ctx
// @return err
func Login(ctx *gin.Context) {
log.Debugf("收到登录请求")
var p login.GetTokenWithPassword
if err := ctx.ShouldBind(&p); err != nil {
response.New(ctx).SetMsg("参数错误").SetError(err).Fail()
return
}
// 验证验证码是否正确
if !new(captcha.RedisStore).Verify(p.VerifyId, p.VerifyCode, true) {
response.New(ctx).SetMsg("验证码错误").Fail()
return
}
// 重写参数
ctx.Request.Form = url.Values{
"username": {p.Username},
"password": {p.Password},
"scope": {"ALL"},
"grant_type": {"password"},
}
// 参数解析成功,进行登录
if err := auth.OAuthServer.HandleTokenRequest(ctx.Writer, ctx.Request); err != nil {
log.Errorf("登录失败:%s", err.Error())
response.New(ctx).SetMsg("系统错误").SetError(err).Fail()
return
}
if ctx.Writer.Status() == http.StatusOK {
go userService.UpdateLastLoginInfo(p.Username, ctx.ClientIP())
}
}
// Refresh
// @description: 刷新Token
// @param ctx
func Refresh(ctx *gin.Context) {
var p login.RefreshToken
if err := ctx.ShouldBind(&p); err != nil {
response.New(ctx).SetMsg("参数错误").SetError(err).Fail()
return
}
// 取出用户Id
userId := auth.GetUserIdWithRefreshToken(p.RefreshToken)
// 重写参数
ctx.Request.Form = url.Values{
"refresh_token": {p.RefreshToken},
"grant_type": {"refresh_token"},
}
// 刷新Token
if err := auth.OAuthServer.HandleTokenRequest(ctx.Writer, ctx.Request); err != nil {
log.Errorf("Token数据返回失败: %v", err.Error())
response.New(ctx).SetMsg("系统错误").Fail()
}
// 登录成功才更新登录时间
if ctx.Writer.Status() == http.StatusOK {
// 登录成功更新登录时间和IP
go userService.UpdateLastLoginInfo(userId, ctx.ClientIP())
}
}
// Logout
// @description: 退出登录
// @param ctx
func Logout(ctx *gin.Context) {
log.Debug("退出登录啦")
// Token字符串前缀
const bearerSchema string = "Bearer "
// 取出Token
tokenHeader := ctx.GetHeader("Authorization")
tokenStr := tokenHeader[len(bearerSchema):]
// 取出原始RedisKey
baseDataId, err := redis.Client.Get(context.Background(), "oauth:token:"+tokenStr).Result()
if err != nil {
response.New(ctx).SetMsg("Token信息获取失败").Fail()
return
}
baseDataStr, err := redis.Client.Get(context.Background(), "oauth:token:"+baseDataId).Result()
if err != nil {
response.New(ctx).SetMsg("Token信息获取失败").Fail()
return
}
// 转换数据为Map
tokenData := make(map[string]interface{})
if err = json.Unmarshal([]byte(baseDataStr), &tokenData); err != nil {
response.New(ctx).SetMsg("系统错误").SetError(err).Fail()
return
}
// 删除Redis缓存的数据
redis.Client.Del(context.Background(), "oauth:token:"+baseDataId)
redis.Client.Del(context.Background(), "oauth:token:"+tokenData["Access"].(string))
redis.Client.Del(context.Background(), "oauth:token:"+tokenData["Refresh"].(string))
response.New(ctx).Success()
}

1
api/admin/menu/menu.go Normal file
View File

@ -0,0 +1 @@
package menu

24
api/admin/menu/save.go Normal file
View File

@ -0,0 +1,24 @@
package menu
import (
"github.com/gin-gonic/gin"
menuParam "wechat-robot/model/param/menu"
"wechat-robot/pkg/response"
"wechat-robot/service/menu"
)
// Save
// @description: 保存菜单
// @param ctx
func Save(ctx *gin.Context) {
var p menuParam.Save
if err := ctx.ShouldBind(&p); err != nil {
response.New(ctx).SetError(err).Fail()
return
}
if err := menu.Save(p); err != nil {
response.New(ctx).SetError(err).Fail()
return
}
response.New(ctx).Success()
}

23
api/admin/menu/user.go Normal file
View File

@ -0,0 +1,23 @@
package menu
import (
"github.com/gin-gonic/gin"
"wechat-robot/pkg/response"
"wechat-robot/service/menu"
)
// GetUserMenuTree
// @description: 获取用户权限内的菜单树
// @param ctx
func GetUserMenuTree(ctx *gin.Context) {
// 获取用户Id
userId := ctx.GetString("userId")
// 获取菜单树
tree, err := menu.GetUserMenus(userId)
if err != nil {
response.New(ctx).SetMsg("系统错误").SetError(err).Fail()
return
}
// 返回数据
response.New(ctx).SetData(tree).Success()
}

25
api/admin/robot/delete.go Normal file
View File

@ -0,0 +1,25 @@
package robot
import (
"github.com/gin-gonic/gin"
"unicode/utf8"
"wechat-robot/pkg/response"
robotService "wechat-robot/service/robot"
)
// DeleteById
// @description: 删除机器人
// @param ctx
func DeleteById(ctx *gin.Context) {
var id = ctx.Param("id")
if utf8.RuneCountInString(id) != 32 {
response.New(ctx).SetMsg("参数错误").Fail()
return
}
// 删除数据
if err := robotService.DeleteById(id); err != nil {
response.New(ctx).SetMsg("删除失败").SetError(err).Fail()
} else {
response.New(ctx).SetMsg("删除成功").Success()
}
}

31
api/admin/robot/save.go Normal file
View File

@ -0,0 +1,31 @@
package robot
import (
"github.com/gin-gonic/gin"
robotParam "wechat-robot/model/param/robot"
"wechat-robot/pkg/response"
robotService "wechat-robot/service/robot"
)
// Save
// @description: 保存机器人
// @param ctx
func Save(ctx *gin.Context) {
var p robotParam.Save
if err := ctx.ShouldBind(&p); err != nil {
response.New(ctx).SetMsg("参数错误").SetError(err).Fail()
return
}
// 参数校验
if p.Id == "" && (p.HookApi == "" || p.Version == 0) {
response.New(ctx).SetMsg("参数错误").Fail()
return
}
if err := robotService.Save(p); err != nil {
response.New(ctx).SetMsg("保存失败").SetError(err).Fail()
return
}
response.New(ctx).SetMsg("保存成功").Success()
}

26
api/admin/robot/select.go Normal file
View File

@ -0,0 +1,26 @@
package robot
import (
"github.com/gin-gonic/gin"
robotParam "wechat-robot/model/param/robot"
"wechat-robot/pkg/response"
robotService "wechat-robot/service/robot"
)
// GetAll
// @description: 获取所有机器人
// @param ctx
func GetAll(ctx *gin.Context) {
var p robotParam.GetAll
if err := ctx.ShouldBind(&p); err != nil {
response.New(ctx).SetMsg("参数错误").SetError(err).Fail()
return
}
records, err := robotService.GetAll(p)
if err != nil {
response.New(ctx).SetMsg("数据获取失败").SetError(err).Fail()
return
}
response.New(ctx).SetData(records).Success()
}

27
api/admin/role/role.go Normal file
View File

@ -0,0 +1,27 @@
package role
import (
"github.com/gin-gonic/gin"
roleParam "wechat-robot/model/param/role"
"wechat-robot/pkg/response"
roleService "wechat-robot/service/role"
)
// GetAll
// @description: 获取所有角色
// @param ctx
func GetAll(ctx *gin.Context) {
var p roleParam.GetAll
if err := ctx.ShouldBind(&p); err != nil {
response.New(ctx).SetMsg("参数错误").SetError(err).Fail()
return
}
records, err := roleService.GetAll(p)
if err != nil {
response.New(ctx).SetMsg("获取所有角色失败").SetError(err).Fail()
return
}
response.New(ctx).SetData(records).Success()
}

21
api/callback/hook.go Normal file
View File

@ -0,0 +1,21 @@
package callback
import (
"gitee.ltd/lxh/logger/log"
"github.com/gin-gonic/gin"
"wechat-robot/model/param/callback"
"wechat-robot/pkg/response"
)
// RobotHookNotify
// @description: 机器人HOOK后回调
// @param ctx
func RobotHookNotify(ctx *gin.Context) {
var param callback.RobotHook
if err := ctx.ShouldBind(&param); err != nil {
response.New(ctx).SetError(err).Fail()
return
}
log.Debugf("机器人已启动Id: %s", param.Robot)
}

View File

@ -1,36 +0,0 @@
package app
import (
"github.com/gin-gonic/gin"
"go-wechat/common/response"
"go-wechat/config"
"go-wechat/service"
)
// SaveAssistant
// @description: 保存AI助手
// @param ctx
func SaveAssistant(ctx *gin.Context) {
//ctx.String(http.StatusOK, "操作成功")
ctx.Redirect(302, "/assistant.html")
}
// GetAssistants
// @description: 获取AI助手列表
// @param ctx
func GetAssistants(ctx *gin.Context) {
records, err := service.GetAllAiAssistant()
if err != nil {
response.New(ctx).SetMsg("系统错误").SetError(err).Fail()
return
}
response.New(ctx).SetData(records).Success()
}
// GetAiModels
// @description: 获取AI模型列表
// @param ctx
func GetAiModels(ctx *gin.Context) {
response.New(ctx).SetData(config.Conf.Ai.Models).Success()
}

View File

@ -1,33 +0,0 @@
package app
import (
"github.com/gin-gonic/gin"
"go-wechat/common/response"
"go-wechat/service"
)
// GetFriends
// @description: 获取好友列表
// @param ctx
func GetFriends(ctx *gin.Context) {
// 取出所有好友列表
friends, _, err := service.GetAllFriend()
if err != nil {
response.New(ctx).SetMsg("系统错误").SetError(err).Fail()
}
response.New(ctx).SetData(friends).Success()
}
// GetGroups
// @description: 获取群列表
// @param ctx
func GetGroups(ctx *gin.Context) {
// 取出所有好友列表
_, groups, err := service.GetAllFriend()
if err != nil {
response.New(ctx).SetMsg("系统错误").SetError(err).Fail()
}
response.New(ctx).SetData(groups).Success()
}

View File

@ -1,259 +0,0 @@
package app
import (
"github.com/gin-gonic/gin"
"go-wechat/client"
"go-wechat/model/entity"
"gorm.io/gorm"
"log"
"net/http"
)
// changeStatusParam
// @description: 修改状态用的参数集
type changeStatusParam struct {
WxId string `json:"wxId" binding:"required"`
UserId string `json:"userId"`
}
// changeUseAiModelParam
// @description: 修改使用的AI模型用的参数集
type changeUseAiModelParam struct {
WxId string `json:"wxid" binding:"required"` // 群Id或微信Id
Model string `json:"model" binding:"required"` // 模型代码
}
// autoClearMembers
// @description: 自动清理群成员
type autoClearMembers struct {
WxId string `json:"wxid" binding:"required"` // 群Id
Days int `json:"days"` // 多少天未发言
}
// ChangeEnableAiStatus
// @description: 修改是否开启AI
// @param ctx
func ChangeEnableAiStatus(ctx *gin.Context) {
var p changeStatusParam
if err := ctx.ShouldBindJSON(&p); err != nil {
ctx.String(http.StatusBadRequest, "参数错误")
return
}
log.Printf("待修改的微信Id%s", p.WxId)
err := client.MySQL.Model(&entity.Friend{}).
Where("wxid = ?", p.WxId).
Update("`enable_ai`", gorm.Expr(" !`enable_ai`")).Error
if err != nil {
log.Printf("修改是否开启AI失败%s", err)
ctx.String(http.StatusInternalServerError, "操作失败: %s", err)
return
}
ctx.String(http.StatusOK, "操作成功")
}
// ChangeUseAiModel
// @description: 修改使用的AI模型
// @param ctx
func ChangeUseAiModel(ctx *gin.Context) {
var p changeUseAiModelParam
if err := ctx.ShouldBind(&p); err != nil {
ctx.String(http.StatusBadRequest, "参数错误")
return
}
err := client.MySQL.Model(&entity.Friend{}).
Where("wxid = ?", p.WxId).
Update("`ai_model`", p.Model).Error
if err != nil {
log.Printf("修改【%s】的AI模型失败%s", p.WxId, err)
ctx.String(http.StatusInternalServerError, "操作失败: %s", err)
return
}
ctx.String(http.StatusOK, "操作成功")
}
// ChangeUseAiAssistant
// @description: 修改使用的AI助手
// @param ctx
func ChangeUseAiAssistant(ctx *gin.Context) {
// 此处复用一下结构体
var p changeUseAiModelParam
if err := ctx.ShouldBind(&p); err != nil {
ctx.String(http.StatusBadRequest, "参数错误")
return
}
err := client.MySQL.Model(&entity.Friend{}).
Where("wxid = ?", p.WxId).
Update("`prompt`", p.Model).Error
if err != nil {
log.Printf("修改【%s】的AI助手失败%s", p.WxId, err)
ctx.String(http.StatusInternalServerError, "操作失败: %s", err)
return
}
ctx.String(http.StatusOK, "操作成功")
}
// ChangeEnableGroupRankStatus
// @description: 修改是否开启水群排行榜
// @param ctx
func ChangeEnableGroupRankStatus(ctx *gin.Context) {
var p changeStatusParam
if err := ctx.ShouldBindJSON(&p); err != nil {
ctx.String(http.StatusBadRequest, "参数错误")
return
}
log.Printf("待修改的群Id%s", p.WxId)
err := client.MySQL.Model(&entity.Friend{}).
Where("wxid = ?", p.WxId).
Update("`enable_chat_rank`", gorm.Expr(" !`enable_chat_rank`")).Error
if err != nil {
log.Printf("修改开启水群排行榜失败:%s", err)
ctx.String(http.StatusInternalServerError, "操作失败: %s", err)
return
}
ctx.String(http.StatusOK, "操作成功")
}
// ChangeEnableSummaryStatus
// @description: 修改是否开启聊天记录总结
// @param ctx
func ChangeEnableSummaryStatus(ctx *gin.Context) {
var p changeStatusParam
if err := ctx.ShouldBindJSON(&p); err != nil {
ctx.String(http.StatusBadRequest, "参数错误")
return
}
log.Printf("待修改的群Id%s", p.WxId)
err := client.MySQL.Model(&entity.Friend{}).
Where("wxid = ?", p.WxId).
Update("`enable_summary`", gorm.Expr(" !`enable_summary`")).Error
if err != nil {
log.Printf("修改开启聊天记录总结失败:%s", err)
ctx.String(http.StatusInternalServerError, "操作失败: %s", err)
return
}
ctx.String(http.StatusOK, "操作成功")
}
// ChangeEnableWelcomeStatus
// @description: 修改是否开启迎新
// @param ctx
func ChangeEnableWelcomeStatus(ctx *gin.Context) {
var p changeStatusParam
if err := ctx.ShouldBindJSON(&p); err != nil {
ctx.String(http.StatusBadRequest, "参数错误")
return
}
log.Printf("待修改的群Id%s", p.WxId)
err := client.MySQL.Model(&entity.Friend{}).
Where("wxid = ?", p.WxId).
Update("`enable_welcome`", gorm.Expr(" !`enable_welcome`")).Error
if err != nil {
log.Printf("修改开启迎新失败:%s", err)
ctx.String(http.StatusInternalServerError, "操作失败: %s", err)
return
}
ctx.String(http.StatusOK, "操作成功")
}
// ChangeEnableCommandStatus
// @description: 修改是否开启指令
// @param ctx
func ChangeEnableCommandStatus(ctx *gin.Context) {
var p changeStatusParam
if err := ctx.ShouldBindJSON(&p); err != nil {
ctx.String(http.StatusBadRequest, "参数错误")
return
}
log.Printf("待修改的群Id%s", p.WxId)
err := client.MySQL.Model(&entity.Friend{}).
Where("wxid = ?", p.WxId).
Update("`enable_command`", gorm.Expr(" !`enable_command`")).Error
if err != nil {
log.Printf("修改指令启用状态失败:%s", err)
ctx.String(http.StatusInternalServerError, "操作失败: %s", err)
return
}
ctx.String(http.StatusOK, "操作成功")
}
// ChangeSkipGroupRankStatus
// @description: 修改是否跳过水群排行榜
// @param ctx
func ChangeSkipGroupRankStatus(ctx *gin.Context) {
var p changeStatusParam
if err := ctx.ShouldBindJSON(&p); err != nil {
ctx.String(http.StatusBadRequest, "参数错误")
return
}
log.Printf("待修改的群Id%s -> %s", p.WxId, p.UserId)
err := client.MySQL.Model(&entity.GroupUser{}).
Where("group_id = ?", p.WxId).
Where("wxid = ?", p.UserId).
Update("`skip_chat_rank`", gorm.Expr(" !`skip_chat_rank`")).Error
if err != nil {
log.Printf("修改跳过水群排行榜失败:%s", err)
ctx.String(http.StatusInternalServerError, "操作失败: %s", err)
return
}
ctx.String(http.StatusOK, "操作成功")
}
// ChangeEnableNewsStatus
// @description: 修改是否开启新闻
// @param ctx
func ChangeEnableNewsStatus(ctx *gin.Context) {
var p changeStatusParam
if err := ctx.ShouldBindJSON(&p); err != nil {
ctx.String(http.StatusBadRequest, "参数错误")
return
}
log.Printf("待修改的Id%s", p.WxId)
err := client.MySQL.Model(&entity.Friend{}).
Where("wxid = ?", p.WxId).
Update("`enable_news`", gorm.Expr(" !`enable_news`")).Error
if err != nil {
log.Printf("修改早报启用状态失败:%s", err)
ctx.String(http.StatusInternalServerError, "操作失败: %s", err)
return
}
ctx.String(http.StatusOK, "操作成功")
}
// AutoClearMembers
// @description: 自动清理群成员
// @param ctx
func AutoClearMembers(ctx *gin.Context) {
var p autoClearMembers
if err := ctx.ShouldBindJSON(&p); err != nil {
ctx.String(http.StatusBadRequest, "参数错误")
return
}
log.Printf("待修改的Id%s", p.WxId)
err := client.MySQL.Model(&entity.Friend{}).
Where("wxid = ?", p.WxId).
Update("`clear_member`", p.Days).Error
if err != nil {
log.Printf("修改自动清理群成员阈值失败:%s", err)
ctx.String(http.StatusInternalServerError, "操作失败: %s", err)
return
}
ctx.String(http.StatusOK, "操作成功")
}

View File

@ -1,30 +0,0 @@
package app
import (
"github.com/gin-gonic/gin"
"go-wechat/service"
"net/http"
)
type getGroupUser struct {
GroupId string `json:"groupId" form:"groupId" binding:"required"` // 群Id
}
// GetGroupUsers
// @description: 获取群成员列表
// @param ctx
func GetGroupUsers(ctx *gin.Context) {
var p getGroupUser
if err := ctx.ShouldBind(&p); err != nil {
ctx.String(http.StatusBadRequest, "参数错误")
return
}
// 查询数据
records, err := service.GetGroupUsersByGroupId(p.GroupId)
if err != nil {
ctx.String(http.StatusInternalServerError, "查询失败: %s", err.Error())
return
}
// 暂时先就这样写着,跑通了再改
ctx.JSON(http.StatusOK, records)
}

View File

@ -1,116 +0,0 @@
package app
import (
"fmt"
"github.com/gin-gonic/gin"
"go-wechat/config"
"go-wechat/service"
"net/http"
)
// Index
// @description: 首页
// @param ctx
func Index(ctx *gin.Context) {
var result = gin.H{
"msg": "success",
}
// 取出所有好友列表
friends, groups, err := service.GetAllFriend()
if err != nil {
result["msg"] = fmt.Sprintf("数据获取失败: %s", err.Error())
}
var in, notIn int
for _, d := range friends {
if d.IsOk {
in++
} else {
notIn++
}
}
result["friendCount"] = in
result["friendWithoutCount"] = notIn
var gin, gnotIn int
for _, d := range groups {
if d.IsOk {
gin++
} else {
gnotIn++
}
}
result["groupCount"] = gin
result["groupWithoutCount"] = gnotIn
result["vnc"] = config.Conf.Wechat.VncUrl
result["isVnc"] = config.Conf.Wechat.VncUrl != ""
result["aiModels"] = config.Conf.Ai.Models
// 渲染页面
ctx.HTML(http.StatusOK, "index.html", result)
}
// Friend
// @description: 好友列表
// @param ctx
func Friend(ctx *gin.Context) {
var result = gin.H{
"msg": "success",
}
// 取出所有好友列表
friends, _, err := service.GetAllFriend()
if err != nil {
result["msg"] = fmt.Sprintf("数据获取失败: %s", err.Error())
}
result["friends"] = friends
result["vnc"] = config.Conf.Wechat.VncUrl
result["aiModels"] = config.Conf.Ai.Models
result["assistant"], _ = service.GetAllAiAssistant()
// 渲染页面
ctx.HTML(http.StatusOK, "friend.html", result)
}
// Group
// @description: 群组列表
// @param ctx
func Group(ctx *gin.Context) {
var result = gin.H{
"msg": "success",
}
// 取出所有好友列表
_, groups, err := service.GetAllFriend()
if err != nil {
result["msg"] = fmt.Sprintf("数据获取失败: %s", err.Error())
}
result["groups"] = groups
result["vnc"] = config.Conf.Wechat.VncUrl
result["aiModels"] = config.Conf.Ai.Models
result["assistant"], _ = service.GetAllAiAssistant()
// 渲染页面
ctx.HTML(http.StatusOK, "group.html", result)
}
// Assistant
// @description: AI角色
// @param ctx
func Assistant(ctx *gin.Context) {
var result = gin.H{
"msg": "success",
}
result["aiModels"] = config.Conf.Ai.Models
result["assistant"], _ = service.GetAllAiAssistant()
// 渲染页面
ctx.HTML(http.StatusOK, "assistant.html", result)
}
// PageNotFound
// @description: 404页面
// @param ctx
func PageNotFound(ctx *gin.Context) {
// 渲染页面
ctx.HTML(http.StatusOK, "404.html", nil)
}

View File

@ -1,38 +0,0 @@
package client
import (
"go-wechat/config"
"gorm.io/driver/mysql"
"gorm.io/gorm"
"gorm.io/gorm/logger"
"log"
"os"
"strconv"
)
// MySQL MySQL客户端
var MySQL *gorm.DB
func InitMySQLClient() {
// 创建连接对象
mysqlConfig := mysql.Config{
DSN: config.Conf.MySQL.GetDSN(),
DontSupportRenameIndex: true, // 重命名索引时采用删除并新建的方式
DontSupportRenameColumn: true, // 用 `change` 重命名列
}
// gorm 配置
gormConfig := gorm.Config{}
// 是否开启调试模式
if flag, _ := strconv.ParseBool(os.Getenv("GORM_DEBUG")); flag {
gormConfig.Logger = logger.Default.LogMode(logger.Info)
}
conn, err := gorm.Open(mysql.New(mysqlConfig), &gormConfig)
if err != nil {
log.Panicf("初始化MySQL连接失败, 错误信息: %v", err)
} else {
log.Println("MySQL连接成功")
}
MySQL = conn
}

View File

@ -1,6 +0,0 @@
package constant
var SpecialId = []string{"filehelper", "newsapp", "fmessage", "weibo", "qqmail", "tmessage", "qmessage", "qqsync",
"floatbottle", "lbsapp", "shakeapp", "medianote", "qqfriend", "readerapp", "blogapp", "facebookapp", "masssendapp",
"meishiapp", "feedsapp", "voip", "blogappweixin", "weixin", "brandsessionholder", "weixinreminder", "officialaccounts",
"notification_messages", "wxitil", "userexperience_alarm", "notification_messages", "exmail_tool"}

View File

@ -1,44 +0,0 @@
package current
import (
"go-wechat/model/model"
plugin "go-wechat/plugin"
)
// robotInfo
// @description: 机器人信息
type robotInfo struct {
info model.RobotUserInfo
MessageHandler plugin.MessageHandler // 启用的插件
}
// 当前接入的机器人信息
var ri robotInfo
// SetRobotInfo
// @description: 设置机器人信息
// @param info
func SetRobotInfo(info model.RobotUserInfo) {
ri.info = info
}
// GetRobotInfo
// @description: 获取机器人信息
// @return model.RobotUserInfo
func GetRobotInfo() model.RobotUserInfo {
return ri.info
}
// GetRobotMessageHandler
// @description: 获取机器人插件信息
// @return robotInfo
func GetRobotMessageHandler() plugin.MessageHandler {
return ri.MessageHandler
}
// SetRobotMessageHandler
// @description: 设置机器人插件信息
// @param handler
func SetRobotMessageHandler(handler plugin.MessageHandler) {
ri.MessageHandler = handler
}

View File

@ -1,123 +0,0 @@
system:
# 添加新好友或群之后通知给指定的人
newFriendNotify:
enable: true
toUser:
- "wxid_xxx"
# 默认AI等配置
defaultRule:
# 默认是否开启AI
ai: true
# 默认是否开启水群排行榜
chatRank: true
# 默认是否开启聊天记录总结
summary: true
# 默认是否开启新成员加群欢迎
welcome: true
# 每日早报
news: true
# 微信HOOK配置
wechat:
# 微信HOOK接口地址
host: 10.0.0.79:19088
# 微信容器映射出来的vnc页面地址没有就不填
# vncUrl: http://192.168.1.175:19087/vnc_lite.html
# 是否在启动的时候自动设置hook服务的回调
autoSetCallback: false
# 回调IP如果是Docker运行本参数必填(填auto表示自动不适用于 docker 环境)如果Docker修改了映射格式为 ip:port
callback: 10.0.0.51
# 转发到其他地址
forward:
# - 10.0.0.247:4299
# 数据库
mysql:
drive: mysql # 使用的数据库驱动,支持 mysql、postgres
host: 10.0.0.31
port: 3307
user: wechat
password: wechat123
db: wechat
schema: public # postgres 专用
task:
enable: false
news:
enable: true
cron: '14 11 * * *' # 每天0:30
syncFriends:
enable: false
cron: '*/5 * * * *' # 五分钟一次
groupSummary:
enable: false
cron: '30 0 * * *' # 每天0:30
waterGroup:
enable: false
cron:
yesterday: '30 9 * * *' # 每天9:30
week: '30 9 * * 1' # 每周一9:30
month: '30 9 1 * *' # 每月1号9:30
year: '0 9 1 1 *' # 每年1月1号9:30
# MQ配置
mq:
# 是否启用
enable: false
# RabbitMQ配置
rabbitmq:
host: 10.0.0.247
port: 5672
user: wechat
password: wechat123
vhost: wechat
# AI回复
ai:
# 是否启用
enable: false
# 模型不填默认gpt-3.5-turbo-0613
model: gpt-3.5-turbo-0613
# 群聊总结模型
summaryModel: gpt-4-0613
# OpenAI Api key
apiKey: sk-xxxx
# 接口代理域名不填默认ChatGPT官方地址
baseUrl: https://sxxx
# 人设
personality: 你的名字叫张三,你是一个百科机器人,你的爱好是看电影,你的性格是开朗的,你的专长是讲故事,你的梦想是当一名童话故事作家。你对政治没有一点儿兴趣,也不会讨论任何与政治相关的话题,你甚至可以拒绝回答这一类话题。
models:
- name: ChatGPT-4
model: gpt-4
- name: 讯飞星火v3.1
model: SparkDesk-v3.1
- name: 讯飞星火v3.5
model: SparkDesk-v3.5
- name: 月之暗面-8k
model: moonshot-v1-8k
- name: 月之暗面-32k
model: moonshot-v1-32k
- name: 月之暗面-128k
model: moonshot-v1-128k
- name: 跃问
model: StepChat
- name: 豆包Lite-4k
model: Doubao-lite-4k
- name: 豆包Pro-4k
model: Doubao-pro-4k
# 资源配置
# map[k]v结构k 会变成全小写,所以这儿不能用大写字母
resource:
# 欢迎新成员表情包
welcome-new:
type: emotion
path: 58e4150be2bba8f7b71974b10391f9e9
# 给新好友或者群的自我介绍,不配置就不发送
introduce:
type: text
path: "大家好我是一个AI机器人可以直接@我询问你想问的问题。"
# 水群排行榜词云,只能是图片,末尾的`\%s`也是必须的
wordcloud:
type: image
path: D:\Share\wordcloud\%s

15
config.yaml.example Normal file
View File

@ -0,0 +1,15 @@
# 数据库配置
database:
type: mysql # 使用的数据库类型,可选 mysql | postgresql
host: mysql # 数据库地址(使用docker-compose启动可以不用改)
port: 3306 # 数据库端口
username: pixiu # 数据库用户名
password: pixiu # 数据库密码
database: pixiu # 数据库名
# Redis配置
redis:
host: redis # Redis地址(使用docker-compose启动可以不用改)
port: 6379 # Redis端口
password: mNhgeSk32fUf69C6
db: 0

View File

@ -1,20 +0,0 @@
package config
// ai
// @description: AI配置
type ai struct {
Enable bool `json:"enable" yaml:"enable"` // 是否启用AI
Model string `json:"model" yaml:"model"` // 模型
SummaryModel string `json:"summaryModel" yaml:"summaryModel"` // 总结模型
ApiKey string `json:"apiKey" yaml:"apiKey"` // API Key
BaseUrl string `json:"baseUrl" yaml:"baseUrl"` // API地址
Personality string `json:"personality" yaml:"personality"` // 人设
Models []aiModel `json:"models" yaml:"models"` // 模型列表
}
// aiModel
// @description: AI模型
type aiModel struct {
Name string `json:"name" yaml:"name"` // 模型名称
Model string `json:"model" yaml:"model"` // 模型代码
}

View File

@ -6,11 +6,7 @@ var Conf conf
// Config
// @description: 配置
type conf struct {
System system `json:"system" yaml:"system"` // 系统配置
Task task `json:"task" yaml:"task"` // 定时任务配置
MySQL mysql `json:"mysql" yaml:"mysql"` // MySQL 配置
Wechat wechat `json:"wechat" yaml:"wechat"` // 微信助手
Mq mq `json:"mq" yaml:"mq"` // MQ 配置
Ai ai `json:"ai" yaml:"ai"` // AI配置
Resource map[string]resourceItem `json:"resource" yaml:"resource"` // 资源配置
Database db `json:"database" yaml:"database"` // 数据库 配置
Redis redis `json:"redis" yaml:"redis"` // Redis 配置
Mq mq `json:"mq" yaml:"mq"` // MQ 配置
}

32
config/db.go Normal file
View File

@ -0,0 +1,32 @@
package config
import "fmt"
// db
// @description: 数据库配置
type db struct {
Type string `json:"type" yaml:"type" mapstructure:"type"` // 数据库类型
Host string `json:"host" yaml:"host" mapstructure:"host"` // 数据库地址
Port int `json:"port" yaml:"port" mapstructure:"port"` // 数据库端口
Username string `json:"username" yaml:"username" mapstructure:"username"` // 数据库用户名
Password string `json:"password" yaml:"password" mapstructure:"password"` // 数据库密码
Database string `json:"database" yaml:"database" mapstructure:"database"` // 数据库名称
}
// GetMysqlDSN
// @description: 获取MySQL连接DSN
// @receiver d
// @return string
func (d db) GetMysqlDSN() string {
return fmt.Sprintf("%s:%s@tcp(%s:%v)/%s?charset=utf8mb4&parseTime=True&loc=Local",
d.Username, d.Password, d.Host, d.Port, d.Database)
}
// GetPostgreSQLDSN
// @description: 获取PostgreSQL连接DSN
// @receiver d
// @return string
func (d db) GetPostgreSQLDSN() string {
return fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%d sslmode=disable TimeZone=Asia/Shanghai",
d.Host, d.Username, d.Password, d.Database, d.Port)
}

View File

@ -5,7 +5,6 @@ import "fmt"
// mq
// @description: MQ配置
type mq struct {
Enable bool `json:"enable" yaml:"enable"` // 是否启用
RabbitMQ rabbitMq `json:"rabbitmq" yaml:"rabbitmq"` // RabbitMQ配置
}

View File

@ -1,24 +0,0 @@
package config
import (
"fmt"
)
// mysql
// @description: MySQL配置
type mysql struct {
Host string `mapstructure:"host" yaml:"host"` // 主机
Port int `mapstructure:"port" yaml:"port"` // 端口
User string `mapstructure:"user" yaml:"user"` // 用户名
Password string `mapstructure:"password" yaml:"password"` // 密码
Db string `mapstructure:"db" yaml:"db"` // 数据库名称
}
// GetDSN
// @description: 返回 MySQL 连接字符串
// @receiver c
// @return string
func (c mysql) GetDSN() string {
return fmt.Sprintf("%s:%s@tcp(%s:%v)/%s?charset=utf8mb4&parseTime=True&loc=Local",
c.User, c.Password, c.Host, c.Port, c.Db)
}

15
config/redis.go Normal file
View File

@ -0,0 +1,15 @@
package config
import "fmt"
// Redis配置
type redis struct {
Host string `mapstructure:"host" yaml:"host"` // 主机
Port int `mapstructure:"port" yaml:"port"` // 端口
Password string `mapstructure:"password" yaml:"password"` // 密码
Db int `mapstructure:"db" yaml:"db"` // 数据库名称
}
func (r redis) GetDSN() string {
return fmt.Sprintf("%s:%v", r.Host, r.Port)
}

View File

@ -1,8 +0,0 @@
package config
// resourceItem
// @description: 资源项
type resourceItem struct {
Type string `json:"type" yaml:"type"` // 类型
Path string `json:"path" yaml:"path"` // 路径
}

View File

@ -1,22 +0,0 @@
package config
// 系统配置
type system struct {
NewFriendNotify newFriendNotify `json:"newFriendNotify" yaml:"newFriendNotify"` // 新好友通知
DefaultRule defaultRule `json:"defaultRule" yaml:"defaultRule"` // 默认规则
}
// 添加新好友或群之后通知给指定的人
type newFriendNotify struct {
Enable bool `json:"enable" yaml:"enable"` // 是否启用
ToUser []string `json:"toUser" yaml:"toUser"` // 通知给谁
}
// 默认规则
type defaultRule struct {
Ai bool `json:"ai" yaml:"ai"` // 是否启用AI
ChatRank bool `json:"chatRank" yaml:"chatRank"` // 是否启用聊天排行榜
Summary bool `json:"summary" yaml:"summary"` // 是否启用聊天总结
Welcome bool `json:"welcome" yaml:"welcome"` // 是否启用欢迎新成员
News bool `json:"news" yaml:"news"` // 是否启用每日早报
}

View File

@ -1,34 +0,0 @@
package config
// task
// @description: 定时任务
type task struct {
Enable bool `json:"enable" yaml:"enable"` // 是否启用
News syncFriends `json:"news" yaml:"news"` // 每日早报
SyncFriends syncFriends `json:"syncFriends" yaml:"syncFriends"` // 同步好友
WaterGroup waterGroup `json:"waterGroup" yaml:"waterGroup"` // 水群排行榜
GroupSummary syncFriends `json:"groupSummary" yaml:"groupSummary"` // 群聊总结
}
// syncFriends
// @description: 同步好友
type syncFriends struct {
Enable bool `json:"enable" yaml:"enable"` // 是否启用
Cron string `json:"cron" yaml:"cron"` // 定时任务表达式
}
// waterGroup
// @description: 水群排行榜
type waterGroup struct {
Enable bool `json:"enable" yaml:"enable"` // 是否启用
Cron waterGroupCron `json:"cron" yaml:"cron"` // 定时任务表达式
}
// waterGroupCron
// @description: 水群排行榜定时任务
type waterGroupCron struct {
Yesterday string `json:"yesterday" yaml:"yesterday"` // 昨日排行榜
Week string `json:"week" yaml:"week"` // 周排行榜
Month string `json:"month" yaml:"month"` // 月排行榜
Year string `json:"year" yaml:"year"` // 年排行榜
}

View File

@ -1,35 +0,0 @@
package config
import "strings"
// wxHelper
// @description: 微信助手
type wechat struct {
Host string `json:"host" yaml:"host"` // 接口地址
VncUrl string `json:"vncUrl" yaml:"vncUrl"` // vnc页面地址
AutoSetCallback bool `json:"autoSetCallback" yaml:"autoSetCallback"` // 是否自动设置回调地址
Callback string `json:"callback" yaml:"callback"` // 回调地址
Forward []string `json:"forward" yaml:"forward"` // 转发地址
}
// Check
// @description: 检查配置是否可用
// @receiver w
// @return bool
func (w wechat) Check() bool {
if w.Host == "" {
return false
}
if w.AutoSetCallback && w.Callback == "" {
return false
}
return true
}
func (w wechat) GetURL(uri string) string {
host := w.Host
if !strings.HasPrefix(w.Host, "http://") {
host = "http://" + w.Host
}
return host + uri
}

View File

@ -1,46 +0,0 @@
version: '3.9'
services:
wechat:
image: lxh01/wxhelper-docker:3.9.5.81-v11
container_name: gw-wechat
restart: unless-stopped
environment:
- WINEDEBUG=fixme-all
volumes:
- ./data/wechat:/home/app/.wine/drive_c/users/app/Documents/WeChat\ Files
ports:
- "19087:8080"
- "19088:19088"
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:19088/api/checkLogin"]
interval: 60s
timeout: 10s
retries: 5
mysql:
image: mysql:8
container_name: gw-db
restart: unless-stopped
environment:
- MYSQL_ROOT_PASSWORD=wechat
- MYSQL_USER=wechat
- MYSQL_PASSWORD=wechat
- MYSQL_DATABASE=wechat
volumes:
- ./data/db:/var/lib/mysql
wxhelper:
image: gitee.ltd/lxh/go-wxhelper:latest
container_name: gw-service
restart: unless-stopped
depends_on:
- mysql
- wechat
volumes:
# 配置文件请参阅项目根目录的config.yaml文件
- ./config/config.yaml:/app/config.yaml
ports:
- "19099:19099"

View File

@ -1,18 +0,0 @@
/* eslint-env node */
require('@rushstack/eslint-patch/modern-module-resolution')
module.exports = {
env: {
node: true,
},
root: true,
'extends': [
'plugin:vue/vue3-essential',
'eslint:recommended',
'@vue/eslint-config-typescript',
'@vue/eslint-config-prettier/skip-formatting'
],
parserOptions: {
ecmaVersion: 'latest'
}
}

30
frontend/.gitignore vendored
View File

@ -1,30 +0,0 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
.DS_Store
dist
dist-ssr
coverage
*.local
/cypress/videos/
/cypress/screenshots/
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
*.tsbuildinfo

View File

@ -1,8 +0,0 @@
{
"$schema": "https://json.schemastore.org/prettierrc",
"semi": false,
"tabWidth": 2,
"singleQuote": true,
"printWidth": 100,
"trailingComma": "none"
}

View File

@ -1,7 +0,0 @@
{
"recommendations": [
"Vue.volar",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode"
]
}

View File

@ -1,39 +0,0 @@
# frontend
This template should help get you started developing with Vue 3 in Vite.
## Recommended IDE Setup
[VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur).
## Type Support for `.vue` Imports in TS
TypeScript cannot handle type information for `.vue` imports by default, so we replace the `tsc` CLI with `vue-tsc` for type checking. In editors, we need [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) to make the TypeScript language service aware of `.vue` types.
## Customize configuration
See [Vite Configuration Reference](https://vitejs.dev/config/).
## Project Setup
```sh
npm install
```
### Compile and Hot-Reload for Development
```sh
npm run dev
```
### Type-Check, Compile and Minify for Production
```sh
npm run build
```
### Lint with [ESLint](https://eslint.org/)
```sh
npm run lint
```

1
frontend/env.d.ts vendored
View File

@ -1 +0,0 @@
/// <reference types="vite/client" />

View File

@ -1,13 +0,0 @@
<!DOCTYPE html>
<html lang="en" class="h-full bg-gray-100">
<head>
<meta charset="UTF-8">
<link rel="icon" href="/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>一个微信机器人</title>
</head>
<body style="min-height: 911px" class="h-full">
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>

File diff suppressed because it is too large Load Diff

View File

@ -1,46 +0,0 @@
{
"name": "frontend",
"version": "0.0.0",
"private": true,
"type": "module",
"scripts": {
"dev": "vite",
"build": "run-p type-check \"build-only {@}\" --",
"preview": "vite preview",
"build-only": "vite build",
"type-check": "vue-tsc --build --force",
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
"format": "prettier --write src/"
},
"dependencies": {
"@headlessui/vue": "^1.7.22",
"@tailwindcss/forms": "^0.5.7",
"axios": "^1.7.2",
"pinia": "^2.1.7",
"qs": "^6.12.2",
"vue": "^3.4.29",
"vue-router": "^4.3.3"
},
"devDependencies": {
"@rushstack/eslint-patch": "^1.8.0",
"@tsconfig/node20": "^20.1.4",
"@types/node": "^20.14.5",
"@types/qs": "^6.9.15",
"@vitejs/plugin-vue": "^5.0.5",
"@vitejs/plugin-vue-jsx": "^4.0.0",
"@vue/eslint-config-prettier": "^9.0.0",
"@vue/eslint-config-typescript": "^13.0.0",
"@vue/tsconfig": "^0.5.1",
"autoprefixer": "^10.4.19",
"daisyui": "^4.12.10",
"eslint": "^8.57.0",
"eslint-plugin-vue": "^9.23.0",
"npm-run-all2": "^6.2.0",
"postcss": "^8.4.39",
"prettier": "^3.2.5",
"tailwindcss": "^3.4.4",
"typescript": "~5.4.0",
"vite": "^5.3.1",
"vue-tsc": "^2.0.21"
}
}

View File

@ -1,6 +0,0 @@
export default {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
};

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

View File

@ -1,10 +0,0 @@
<script setup lang="ts">
import MainNav from '@/components/layout/MainNav.vue'
</script>
<template>
<MainNav />
</template>
<style scoped>
</style>

View File

@ -1,6 +0,0 @@
// 默认返回数据结构
export type BaseResult<T> = {
code: number;
message: string;
data?: T;
};

View File

@ -1,43 +0,0 @@
import { http } from '@/utils/http'
import type { BaseResult } from '@/api/base'
/** 通讯录列表返回结果 */
export type ContactItem = {
/** 微信号 */
CustomAccount: string,
/** 昵称 */
Nickname: string,
/** 昵称拼音大写首字母 */
Pinyin: string,
/** 昵称拼音全拼 */
PinyinAll: string,
/** 微信原始Id */
Wxid: string,
/** 最后活跃时间 */
LastActive: Date,
/** 是否使用AI */
EnableAi: boolean,
/** AI模型 */
AiModel: string,
/** AI助手或者自定义提示词 */
Prompt: string,
/** 是否使用聊天排行 */
EnableChatRank: boolean,
/** 是否使用迎新 */
EnableWelcome: boolean,
/** 是否启用指令 */
EnableCommand: boolean,
/** 是否启用总结 */
EnableSummary: boolean,
/** 是否启用新闻 */
EnableNews: boolean,
/** 清理成员配置(多少天未活跃的) */
ClearMember: number,
/** 是否还在通讯库(群聊是要还在群里也算) */
IsOk: boolean
}
/** 获取首页基础信息 */
export const getFriendList = () => {
return http.request<BaseResult<Array<ContactItem>>>('get', '/api/contact/friend')
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 210 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 123 KiB

View File

@ -1,3 +0,0 @@
<template>
</template>

View File

@ -1,73 +0,0 @@
<script setup lang="ts">
import { RouterView } from 'vue-router'
import { Disclosure, DisclosureButton, DisclosurePanel, Menu, MenuButton, MenuItem, MenuItems } from '@headlessui/vue'
defineOptions({
name: 'MainNav'
})
const navigation = [
{ name: '首页', href: '/', current: true },
{ name: '好友列表', href: '/friend', current: false },
{ name: '群组', href: '/group', current: false },
{ name: 'AI角色', href: '/assistant', current: false }
]
//
const setCurrent = (href: string) => {
navigation.forEach(item => {
item.current = item.href === href
})
}
</script>
<template>
<div class="min-h-full">
<div class="bg-green-600 pb-32">
<Disclosure as="nav" class="border-b border-green-300 border-opacity-25 bg-green-600 lg:border-none">
<div class="mx-auto max-w-7xl px-2 sm:px-4 lg:px-8">
<div
class="relative flex h-16 items-center justify-between lg:border-b lg:border-green-400 lg:border-opacity-25">
<div class="flex items-center px-2 lg:px-0">
<div class="flex-shrink-0">
<img class="block h-8 w-8" src="../../assets/img/logo.png" alt="Your Company" />
</div>
<div class="hidden lg:ml-10 lg:block">
<div class="flex space-x-4">
<a v-for="item in navigation" :key="item.name" :href="item.href"
:class="[item.current ? 'bg-green-700 text-white' : 'text-white hover:bg-green-500 hover:bg-opacity-75', 'rounded-md px-3 py-2 text-sm font-medium']"
:aria-current="item.current ? 'page' : undefined" @click="setCurrent(item.href)">{{ item.name }}</a>
</div>
</div>
</div>
</div>
</div>
</Disclosure>
<header class="py-10">
<div class="mx-auto max-w-7xl px-4 sm:px-6 lg:px-8">
<h1 class="text-3xl font-bold tracking-tight text-white">Dashboard</h1>
</div>
</header>
</div>
<main class="-mt-32">
<div class="mx-auto max-w-7xl px-4 pb-12 sm:px-6 lg:px-8">
<div class="rounded-lg bg-white px-5 py-6 shadow sm:px-6">
<RouterView />
</div>
</div>
</main>
<footer>
<div class="mx-auto max-w-3xl px-4 sm:px-6 lg:max-w-7xl lg:px-8">
<div class="border-t border-gray-200 py-8 text-center text-sm text-gray-500 sm:text-left">
<span class="block sm:inline">本项目完全开源开源地址: </span>
<span class="block sm:inline text-red-500">
<a target="_blank" href="https://gitee.ltd/lxh/go-wxhelper">https://gitee.ltd</a>
</span>
</div>
</div>
</footer>
</div>
</template>

View File

@ -1,15 +0,0 @@
import { createApp } from 'vue'
import { createPinia } from 'pinia'
import App from './App.vue'
import router from './router'
// Tailwind CSS
import "tailwindcss/tailwind.css";
const app = createApp(App)
app.use(createPinia())
app.use(router)
app.mount('#app')

View File

@ -1,31 +0,0 @@
import { createRouter, createWebHistory } from 'vue-router'
import IndexPage from '@/views/index/index.vue'
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
routes: [
{
path: '/',
name: 'home',
component: IndexPage
},
{
path: '/friend',
name: 'Friend',
// 这么写是为了实现懒加载
component: () => import('@/views/friend/index.vue')
},
{
path: '/group',
name: 'Group',
component: () => import('@/views/group/index.vue')
},
{
path: '/assistant',
name: 'Assistant',
component: () => import('@/views/assistant/index.vue')
}
]
})
export default router

View File

@ -1,12 +0,0 @@
import { ref, computed } from 'vue'
import { defineStore } from 'pinia'
export const useCounterStore = defineStore('counter', () => {
const count = ref(0)
const doubleCount = computed(() => count.value * 2)
function increment() {
count.value++
}
return { count, doubleCount, increment }
})

View File

@ -1,136 +0,0 @@
import Axios, {
type AxiosInstance,
type AxiosRequestConfig,
type CustomParamsSerializer,
type AxiosResponse
} from 'axios'
import type { HttpError, RequestMethods } from './types.d'
import { stringify } from 'qs'
// 相关配置请参考www.axios-js.com/zh-cn/docs/#axios-request-config-1
const defaultConfig: AxiosRequestConfig = {
// 请求超时时间
timeout: 10000,
headers: {
Accept: 'application/json, text/plain, */*',
'Content-Type': 'application/json',
'X-Requested-With': 'XMLHttpRequest'
},
// 数组格式参数序列化https://github.com/axios/axios/issues/5142
paramsSerializer: {
serialize: stringify as unknown as CustomParamsSerializer
}
}
class Http {
constructor() {
this.httpInterceptorsRequest()
this.httpInterceptorsResponse()
}
/** 初始化配置对象 */
private static initConfig: AxiosRequestConfig = {}
/** 保存当前`Axios`实例对象 */
private static axiosInstance: AxiosInstance = Axios.create(defaultConfig)
/** 请求拦截 */
private httpInterceptorsRequest(): void {
Http.axiosInstance.interceptors.request.use(
async (config: AxiosRequestConfig): Promise<any> => {
// 开启进度条动画
// NProgress.start();
// 优先判断post/get等方法是否传入回调否则执行初始化设置等回调
// if (typeof config.beforeRequestCallback === 'function') {
// config.beforeRequestCallback(config)
// return config
// }
// if (Http.initConfig.beforeRequestCallback) {
// Http.initConfig.beforeRequestCallback(config)
// return config
// }
return config
},
(error: HttpError) => {
return Promise.reject(error)
}
)
}
/** 响应拦截 */
private httpInterceptorsResponse(): void {
const instance = Http.axiosInstance
instance.interceptors.response.use(
(response: AxiosResponse) => {
// const $config = response.config
// 关闭进度条动画
// NProgress.done()
// 优先判断post/get等方法是否传入回调否则执行初始化设置等回调
// if (typeof $config.beforeResponseCallback === 'function') {
// $config.beforeResponseCallback(response)
// return response.data
// }
// if (Http.initConfig.beforeResponseCallback) {
// Http.initConfig.beforeResponseCallback(response)
// return response.data
// }
return response.data
},
(error: HttpError) => {
const $error = error
$error.isCancelRequest = Axios.isCancel($error)
// 关闭进度条动画
// NProgress.done()
// 所有的响应异常 区分来源为取消请求/非取消请求
return Promise.reject($error)
}
)
}
/** 通用请求工具函数 */
public request<T>(
method: RequestMethods,
url: string,
param?: AxiosRequestConfig,
axiosConfig?: AxiosRequestConfig
): Promise<T> {
const config = {
method,
url,
...param,
...axiosConfig
} as AxiosRequestConfig
// 单独处理自定义请求/响应回调
return new Promise((resolve, reject) => {
Http.axiosInstance
.request<T>(config)
.then((response: any): void => {
return resolve(response)
})
.catch((error) => {
reject(error)
})
})
}
/** 单独抽离的`post`工具函数 */
public post<T, P>(
url: string,
params?: AxiosRequestConfig<P>,
config?: AxiosRequestConfig
): Promise<T> {
return this.request<T>('post', url, params, config)
}
/** 单独抽离的`get`工具函数 */
public get<T, P>(
url: string,
params?: AxiosRequestConfig<P>,
config?: AxiosRequestConfig
): Promise<T> {
return this.request<T>('get', url, params, config)
}
}
export const http = new Http()

View File

@ -1,43 +0,0 @@
import type {
Method,
AxiosError,
AxiosResponse,
AxiosRequestConfig
} from "axios";
export type RequestMethods = Extract<
Method,
"get" | "post" | "put" | "delete" | "patch" | "option" | "head"
>;
export interface HttpError extends AxiosError {
isCancelRequest?: boolean;
}
export interface HttpResponse extends AxiosResponse {
config: HttpRequestConfig;
}
export interface HttpRequestConfig extends AxiosRequestConfig {
beforeRequestCallback?: (request: HttpRequestConfig) => void;
beforeResponseCallback?: (response: HttpResponse) => void;
}
export default class Http {
request<T>(
method: RequestMethods,
url: string,
param?: AxiosRequestConfig,
axiosConfig?: HttpRequestConfig
): Promise<T>;
post<T, P>(
url: string,
params?: T,
config?: HttpRequestConfig
): Promise<P>;
get<T, P>(
url: string,
params?: T,
config?: HttpRequestConfig
): Promise<P>;
}

View File

@ -1,12 +0,0 @@
<script setup lang="ts">
defineOptions({
name: "AssistantPage"
});
</script>
<template>
<main>
<h1>AI角色</h1>
</main>
</template>

View File

@ -1,25 +0,0 @@
import { onMounted, ref } from 'vue'
import { type ContactItem, getFriendList } from '@/api/contact'
// 起飞
export function useHook() {
const dataList = ref<ContactItem[]>([]);
// 获取数据
async function onSearch() {
const { data } = await getFriendList();
dataList.value = data;
console.log(data);
}
// 挂载时执行
onMounted(() => {
onSearch();
});
return {
dataList,
onSearch
}
}

View File

@ -1,47 +0,0 @@
<script setup lang="ts">
import { useHook } from '@/views/friend/hook'
defineOptions({
name: "FriendPage"
});
const { dataList, onSearch } = useHook()
</script>
<template>
<ul role="list" class="grid grid-cols-1 gap-x-6 gap-y-8 lg:grid-cols-3 xl:gap-x-8">
<li class="overflow-hidden rounded-xl border border-gray-200" v-for="item in dataList" :key="item.Wxid">
<div class="flex items-center gap-x-4 border-b border-gray-900/5 bg-gray-50 p-6">
<img v-if="item.IsOk" src="@/assets/img/status-ok.png" alt="Tuple" class="h-12 w-12 flex-none rounded-lg bg-white object-cover ring-1 ring-gray-900/10">
<img v-else src="@/assets/img/status-fail.png" alt="Tuple" class="h-12 w-12 flex-none rounded-lg bg-white object-cover ring-1 ring-gray-900/10">
<div class="flex-1">
<div class="text-sm font-medium leading-6 text-gray-900">{{ item.Nickname }}</div>
<span v-if="item.IsOk"
class="inline-flex items-center rounded-md bg-green-50 px-2 py-1 text-xs font-medium text-green-700 ring-1 ring-inset ring-green-600/20">在通讯录</span>
<span v-else
class="inline-flex items-center rounded-md bg-red-50 px-2 py-1 text-xs font-medium text-red-700 ring-1 ring-inset ring-red-600/20">不在通讯录</span>
</div>
</div>
<dl class="-my-3 divide-y divide-gray-100 px-6 py-4 text-sm leading-6">
<div class="flex justify-between gap-x-4 py-3">
<dt class="text-gray-500">原始微信Id<br/>微信号</dt>
<dd>
<div class="text-gray-700">{{ item.Wxid }}</div>
<div class="truncate text-gray-500">{{ item.CustomAccount }}</div>
</dd>
</div>
<div class="flex justify-between gap-x-4 py-3">
<dt class="text-gray-500">最后活跃时间</dt>
<dd class="flex items-start gap-x-2">
<div class="font-medium text-gray-900">
{{ item.LastActive }}
</div>
</dd>
</div>
</dl>
</li>
</ul>
</template>

View File

@ -1,12 +0,0 @@
<script setup lang="ts">
defineOptions({
name: "GroupPage"
});
</script>
<template>
<main>
<h1>群组</h1>
</main>
</template>

View File

@ -1,12 +0,0 @@
<script setup lang="ts">
defineOptions({
name: "IndexPage"
});
</script>
<template>
<main>
<h1 class="text-orange-700">首页</h1>
</main>
</template>

View File

@ -1,12 +0,0 @@
/** @type {import('tailwindcss').Config} */
export default {
content: ['./index.html', './src/**/*.{vue,js,ts,jsx,tsx,md}'],
theme: {
container: {
center: true,
padding: '2rem',
},
},
plugins: [require('daisyui'), require('@tailwindcss/forms'),],
}

View File

@ -1,14 +0,0 @@
{
"extends": "@vue/tsconfig/tsconfig.dom.json",
"include": ["env.d.ts", "src/**/*", "src/**/*.vue"],
"exclude": ["src/**/__tests__/*"],
"compilerOptions": {
"composite": true,
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
}
}

View File

@ -1,11 +0,0 @@
{
"files": [],
"references": [
{
"path": "./tsconfig.node.json"
},
{
"path": "./tsconfig.app.json"
}
]
}

View File

@ -1,19 +0,0 @@
{
"extends": "@tsconfig/node20/tsconfig.json",
"include": [
"vite.config.*",
"vitest.config.*",
"cypress.config.*",
"nightwatch.conf.*",
"playwright.config.*"
],
"compilerOptions": {
"composite": true,
"noEmit": true,
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
"module": "ESNext",
"moduleResolution": "Bundler",
"types": ["node"]
}
}

View File

@ -1,28 +0,0 @@
import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
// https://vitejs.dev/config/
export default defineConfig({
server: {
proxy: {
"/api": {
// target: "https://graduate.frps.ltd",
target: "http://127.0.0.1:8080",
changeOrigin: true
// rewrite: path => path.replace(/^\/api/, "")
}
},
},
plugins: [
vue(),
vueJsx(),
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
}
})

71
go.mod
View File

@ -1,44 +1,76 @@
module go-wechat
module wechat-robot
go 1.21
require (
github.com/duke-git/lancet/v2 v2.2.8
gitee.ltd/lxh/logger v1.0.15
github.com/fsnotify/fsnotify v1.7.0
github.com/gin-gonic/gin v1.9.1
github.com/go-co-op/gocron v1.37.0
github.com/go-oauth2/oauth2/v4 v4.5.2
github.com/go-oauth2/redis/v4 v4.1.1
github.com/go-playground/locales v0.14.1
github.com/go-playground/universal-translator v0.18.1
github.com/go-playground/validator/v10 v10.17.0
github.com/go-redis/redis/v8 v8.11.5
github.com/go-resty/resty/v2 v2.11.0
github.com/rabbitmq/amqp091-go v1.9.0
github.com/sashabaranov/go-openai v1.17.11
github.com/google/uuid v1.6.0
github.com/mojocn/base64Captcha v1.3.6
github.com/rabbitmq/amqp091-go v1.2.0
github.com/spf13/viper v1.18.2
golang.org/x/crypto v0.18.0
gorm.io/driver/mysql v1.5.2
gorm.io/gorm v1.25.5
gorm.io/driver/postgres v1.5.4
gorm.io/gorm v1.25.6
gorm.io/plugin/soft_delete v1.2.1
)
require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/bytedance/sonic v1.10.2 // indirect
github.com/caarlos0/env/v6 v6.10.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/chenzhuoyu/iasm v0.9.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.16.0 // indirect
github.com/go-kit/kit v0.13.0 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/go-sql-driver/mysql v1.7.1 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 // indirect
github.com/jackc/pgx/v5 v5.5.2 // indirect
github.com/jackc/puddle/v2 v2.2.1 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/jpillora/backoff v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.6 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/leodido/go-urn v1.3.0 // indirect
github.com/lixh00/loki-client-go v1.0.1 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
github.com/natefinch/lumberjack v2.0.0+incompatible // indirect
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.18.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.46.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/prometheus/prometheus v1.8.2-0.20201028100903-3245b3267b24 // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
@ -47,17 +79,32 @@ require (
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/tidwall/btree v1.7.0 // indirect
github.com/tidwall/buntdb v1.3.0 // indirect
github.com/tidwall/gjson v1.17.0 // indirect
github.com/tidwall/grect v0.1.4 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
github.com/tidwall/rtred v0.1.2 // indirect
github.com/tidwall/tinyqueue v0.1.1 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.26.0 // indirect
golang.org/x/arch v0.7.0 // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3 // indirect
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a // indirect
golang.org/x/image v0.15.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/oauth2 v0.16.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240125205218-1f4bbc51befe // indirect
google.golang.org/grpc v1.61.0 // indirect
google.golang.org/protobuf v1.32.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

1298
go.sum

File diff suppressed because it is too large Load Diff

View File

@ -1,46 +0,0 @@
package initialization
import (
"go-wechat/common/current"
"go-wechat/model/model"
plugin "go-wechat/plugin"
"go-wechat/plugin/plugins"
"go-wechat/service"
)
// Plugin
// @description: 初始化插件
func Plugin() {
// 定义一个处理器
dispatcher := plugin.NewMessageMatchDispatcher()
// 设置为异步处理
dispatcher.SetAsync(true)
// 注册插件
// 保存消息进数据库
dispatcher.RegisterHandler(func(*model.Message) bool {
return true
}, plugins.SaveToDb)
// 私聊指令消息
dispatcher.RegisterHandler(func(m *model.Message) bool {
// 私聊消息 或 群聊艾特机器人并且以/开头的消息
isGroupAt := m.IsAt() && !m.IsAtAll()
return (m.IsPrivateText() || isGroupAt) && m.CleanContentStartWith("/") && service.CheckIsEnableCommand(m.FromUser)
}, plugins.Command)
// AI消息插件
dispatcher.RegisterHandler(func(m *model.Message) bool {
// 群内@或者私聊文字消息
return (m.IsAt() && !m.IsAtAll()) || m.IsPrivateText()
}, plugins.AI)
// 欢迎新成员
dispatcher.RegisterHandler(func(m *model.Message) bool {
return m.IsNewUserJoin()
}, plugins.WelcomeNew)
// 注册消息处理器
current.SetRobotMessageHandler(plugin.DispatchMessage(dispatcher))
}

View File

@ -1,31 +0,0 @@
package initialization
import (
"github.com/go-resty/resty/v2"
"go-wechat/common/current"
"go-wechat/config"
model2 "go-wechat/model/model"
"log"
)
// InitWechatRobotInfo
// @description: 初始化微信机器人信息
func InitWechatRobotInfo() {
// 获取数据
var base model2.Response[model2.RobotUserInfo]
_, err := resty.New().R().
SetHeader("Content-Type", "application/json;chartset=utf-8").
SetResult(&base).
Post(config.Conf.Wechat.GetURL("/api/userInfo"))
if err != nil {
log.Printf("获取机器人信息失败: %s", err.Error())
return
}
log.Printf("机器人Id: %s", base.Data.WxId)
log.Printf("机器人微信号: %s", base.Data.Account)
log.Printf("机器人名称: %s", base.Data.Name)
// 设置为单例
current.SetRobotInfo(base.Data)
}

View File

@ -0,0 +1,49 @@
package database
import (
"gitee.ltd/lxh/logger"
"gitee.ltd/lxh/logger/log"
"gorm.io/driver/mysql"
"gorm.io/driver/postgres"
"gorm.io/gorm"
"os"
"strconv"
"wechat-robot/config"
)
// Client 客户端
var Client *gorm.DB
// Init
// @description: 初始化数据库连接
func Init() {
var dialector gorm.Dialector
switch config.Conf.Database.Type {
case "mysql":
// MySQL
dialector = mysql.Open(config.Conf.Database.GetMysqlDSN())
case "postgresql":
// PostgreSQL
dialector = postgres.Open(config.Conf.Database.GetPostgreSQLDSN())
default:
log.Panic("未配置数据库或数据库类型不支持")
}
// gorm 配置
gormConfig := gorm.Config{
DisableForeignKeyConstraintWhenMigrating: true,
}
// 是否开启调试模式
if flag, _ := strconv.ParseBool(os.Getenv("GORM_DEBUG")); flag {
gormConfig.Logger = logger.DefaultGormLogger()
}
// 初始化连接
conn, err := gorm.Open(dialector, &gormConfig)
if err != nil {
log.Panicf("数据库连接初始化失败: %v", err)
} else {
log.Debug("数据库连接初始化成功")
}
Client = conn
}

View File

@ -0,0 +1,72 @@
package initialize
import (
"errors"
"gitee.ltd/lxh/logger/log"
"gorm.io/gorm"
"wechat-robot/internal/database"
"wechat-robot/model/entity"
"wechat-robot/utils"
)
// initDefaultAdminUser
// @description: 初始化默认后台用户
func initDefaultAdminUser() {
// 如果数据库没有有效用户,初始化一个默认账号
var count int64
if err := database.Client.Model(entity.AdminUser{}).Count(&count).Error; err != nil {
log.Panicf("初始化默认账号失败: %s", err.Error())
}
if count > 0 {
return
}
// 开启事务
var err error
tx := database.Client.Begin()
defer func() {
if recover() != nil {
tx.Rollback()
} else {
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
}
}()
// 判断角色是否存在
var role entity.Role
if err = tx.Where("code = ?", "admin").First(&role).Error; err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
log.Panicf("初始化默认账号失败: %s", err.Error())
return
}
// 如果角色不存在,创建角色
if role.Id == "" {
role.Name = "超级管理员"
role.Code = "admin"
role.Describe = "系统默认超级管理员"
if err = tx.Create(&role).Error; err != nil {
log.Panicf("初始化默认账号失败: %s", err.Error())
return
}
}
// 创建用户
var adminUser entity.AdminUser
adminUser.Username = "admin"
adminUser.Password = "admin123"
utils.PasswordUtils().HashPassword(&adminUser.Password)
if err = tx.Create(&adminUser).Error; err != nil {
log.Panicf("初始化默认账号失败: %s", err.Error())
return
}
// 绑定角色
var userRole entity.AdminUserRole
userRole.RoleId = role.Id
userRole.UserId = adminUser.Id
if err = tx.Create(&userRole).Error; err != nil {
log.Panicf("初始化默认账号失败: %s", err.Error())
return
}
}

View File

@ -1,19 +1,20 @@
package initialization
package initialize
import (
"gitee.ltd/lxh/logger/log"
"github.com/fsnotify/fsnotify"
"github.com/spf13/viper"
"go-wechat/client"
"go-wechat/config"
"log"
"wechat-robot/config"
"wechat-robot/internal/database"
"wechat-robot/internal/redis"
)
// 配置管理工具
var vp *viper.Viper
// InitConfig
// Config
// @description: 初始化配置
func InitConfig() {
func initConfig() {
vp = viper.New()
vp.AddConfigPath(".") // 设置配置文件路径
vp.SetConfigName("config") // 设置配置文件名
@ -26,27 +27,21 @@ func InitConfig() {
if err := vp.Unmarshal(&config.Conf); err != nil {
log.Panicf("配置文件解析失败: %v", err)
}
log.Printf("配置文件解析完成: %+v", config.Conf)
if !config.Conf.Wechat.Check() {
log.Panicf("微信HOOK配置缺失")
}
log.Debugf("配置文件解析完成: %+v", config.Conf)
// 初始化数据库连接
client.InitMySQLClient()
//redis.Init()
database.Init()
redis.Init()
// 下面的代码是配置变动之后自动刷新的
vp.WatchConfig()
vp.OnConfigChange(func(e fsnotify.Event) {
// 绑定配置文件
if err := vp.Unmarshal(&config.Conf); err != nil {
log.Printf("配置文件更新失败: %v", err)
log.Errorf("配置文件更新失败: %v", err)
} else {
if !config.Conf.Wechat.Check() {
log.Panicf("微信HOOK配置缺失")
}
// 初始化数据库连接
client.InitMySQLClient()
//redis.Init()
database.Init()
redis.Init()
}
})
}

View File

@ -0,0 +1,28 @@
package initialize
import (
"gitee.ltd/lxh/logger/log"
"wechat-robot/internal/database"
"wechat-robot/model/entity"
)
// databaseTable
// @description: 初始化数据库表
func databaseTable() {
tables := []any{
new(entity.AdminUser), // 用户表
new(entity.Menu), // 菜单表
new(entity.Role), // 角色表
new(entity.RoleMenu), // 角色菜单表
new(entity.AdminUserRole), // 用户角色表
new(entity.SystemConfig), // 系统配置表
new(entity.Robot), // 机器人表
new(entity.AiAssistant), // AI助手表
new(entity.Message), // 微信消息表
}
// 同步表结构
if err := database.Client.AutoMigrate(tables...); err != nil {
log.Panicf("初始化数据库表失败: %v", err)
}
}

View File

@ -0,0 +1,18 @@
package initialize
import (
"wechat-robot/internal/tasks"
"wechat-robot/mq"
"wechat-robot/pkg/auth"
)
// InitSystem
// @description: 初始化系统
func InitSystem() {
initConfig() // 初始化配置
databaseTable() // 初始化数据库表
initDefaultAdminUser() // 初始化默认管理员用户
auth.InitOAuth2Server() // 初始化OAuth2服务
tasks.StartScheduled() // 启动定时任务
mq.Init() // 初始化MQ
}

View File

@ -0,0 +1,56 @@
package message
import (
"encoding/json"
"log"
"strings"
"time"
"wechat-robot/model/entity"
"wechat-robot/model/robot"
"wechat-robot/pkg/types"
"wechat-robot/service/message"
)
// Message
// @description: 处理消息
// @param msg
// @return err
func Message(msg []byte) (err error) {
var m robot.Message
if err = json.Unmarshal(msg, &m); err != nil {
log.Printf("消息解析失败: %v", err)
log.Printf("消息内容: %d -> %v", len(msg), string(msg))
return
}
// 记录原始数据
m.Raw = string(msg)
// 提取出群成员信息
// Sys类型的消息正文不包含微信 Id所以不需要处理
if m.IsGroup() && m.Type != types.MsgTypeSys {
// 群消息,处理一下消息和发信人
groupUser := strings.Split(m.Content, "\n")[0]
groupUser = strings.ReplaceAll(groupUser, ":", "")
// 如果两个id一致说明是系统发的
if m.FromUser != groupUser {
m.GroupUser = groupUser
}
// 用户的操作单独提出来处理一下
m.Content = strings.Join(strings.Split(m.Content, "\n")[1:], "\n")
}
log.Printf("收到微信消息\n机器人Id: %s\n消息来源: %s\n群成员: %s\n消息类型: %v\n消息内容: %s", m.ToUser, m.FromUser, m.GroupUser, m.Type, m.Content)
// 消息入库
var ent entity.Message
ent.MsgId = m.MsgId
ent.Timestamp = m.CreateTime
ent.MessageTime = time.Unix(int64(m.CreateTime), 0)
ent.Content = m.Content
ent.FromUser = m.FromUser
ent.GroupUser = m.GroupUser
ent.ToUser = m.ToUser
ent.Type = m.Type
ent.DisplayFullContent = m.DisplayFullContent
ent.Raw = m.Raw
err = message.Save(ent)
return
}

30
internal/orm/page.go Normal file
View File

@ -0,0 +1,30 @@
package orm
import "gorm.io/gorm"
// Page
// @description: 分页组件
// @param current
// @param size
// @return func(db *gorm.DB) *gorm.DB
func Page(current, size int) func(db *gorm.DB) *gorm.DB {
// 如果页码是-1就不分页
if current == -1 {
return func(db *gorm.DB) *gorm.DB {
return db
}
}
// 分页
return func(db *gorm.DB) *gorm.DB {
if current == 0 {
current = 1
}
if size < 1 {
size = 10
}
// 计算偏移量
offset := (current - 1) * size
// 返回组装结果
return db.Offset(offset).Limit(size)
}
}

148
internal/orm/sort.go Normal file
View File

@ -0,0 +1,148 @@
package orm
import (
"fmt"
"gitee.ltd/lxh/logger/log"
"gorm.io/gorm"
"slices"
)
// @title checkHasDeletedAt
// @description 检查指定表是否有id_del字段
// @param tx *gorm.DB "已开启的事务对象"
// @param tableName string "表名"
// @return bool "是否包含"
func checkHasDeletedAt(tx *gorm.DB, tableName string) bool {
var columns []string
// SQL语句
sql := fmt.Sprintf("select COLUMN_NAME from information_schema.COLUMNS where table_name = '%s'", tableName)
err := tx.Raw(sql).Scan(&columns).Error
if err != nil {
log.Errorf("查询表字段失败: %v", err.Error())
return false
}
return slices.Contains(columns, "id_del")
}
// @title checkHasUpdatedAt
// @description 检查指定表是否有updated_at字段
// @param tx *gorm.DB "已开启的事务对象"
// @param tableName string "表名"
// @return bool "是否包含"
func checkHasUpdatedAt(tx *gorm.DB, tableName string) bool {
var columns []string
// SQL语句
sql := fmt.Sprintf("select COLUMN_NAME from information_schema.COLUMNS where table_name = '%s'", tableName)
err := tx.Raw(sql).Scan(&columns).Error
if err != nil {
log.Errorf("查询表字段失败: %v", err.Error())
return false
}
return slices.Contains(columns, "updated_at")
}
// UpdateSortBefore
// @description 更新之前处理序号
// @param tx *gorm.DB "已开启的事务对象"
// @param model any "模型对象"
// @return error "错误信息"
func UpdateSortBefore(tx *gorm.DB, tableName, id string, sort int, param string) (err error) {
// 查出原来的排序号
var oldSort int
err = tx.Table(tableName).Select("`sort`").Where("id = ?", id).Scan(&oldSort).Error
if err != nil {
log.Errorf("查询老数据失败: %v", err.Error())
return
}
// 如果相等,啥都不干
if oldSort == sort {
return nil
}
// 查询是否包含 id_del 字段
hasDeletedAt := checkHasDeletedAt(tx, tableName)
// 处理排序
// 如果老的排序号小于新的,(老, 新]之间的排序号都要-1
// 如果老的大于新的,[老, 新)排序号-1
if oldSort < sort {
// 老的小于新的,[老, 新) + 1
sel := tx.Table(tableName).
Where("sort <= ? AND sort > ?", sort, oldSort)
if hasDeletedAt {
sel.Where("id_del = 0")
}
if param != "" {
sel.Where(param) // 自定义条件
}
err = sel.Update("sort", gorm.Expr("sort - 1")).Error
} else {
// 老的大于新的,[新, 老) + 1
sel := tx.Table(tableName).
Where("sort >= ? AND sort < ?", sort, oldSort)
if hasDeletedAt {
sel.Where("id_del = 0")
}
if param != "" {
sel.Where(param) // 自定义条件
}
err = sel.Update("sort", gorm.Expr("sort + 1")).Error
}
return
}
// CreateSortBefore
// @description 新建之前处理序号
// @param tx *gorm.DB "已开启的事务对象"
// @param model any "模型对象"
// @return error "错误信息"
func CreateSortBefore(tx *gorm.DB, tableName string, sort int, param string) (err error) {
// 查询是否包含 id_del 字段
hasDeletedAt := checkHasDeletedAt(tx, tableName)
// 处理排序,如果没有传,就会是在最前面
sel := tx.Table(tableName).Where("sort >= ?", sort)
if hasDeletedAt {
sel.Where("id_del = 0")
}
if param != "" {
sel.Where(param)
}
err = sel.Update("sort", gorm.Expr("sort + 1")).Error
if err != nil {
log.Errorf("处理前置排序失败:%v", err)
}
return
}
// DealSortAfter
// @description 处理序号之后
// @param tx *gorm.DB "已开启的事务对象"
// @param modelName string "表名"
// @return error "错误信息"
func DealSortAfter(tx *gorm.DB, modelName, param string) (err error) {
// 保存成功,刷新排序
if param != "" {
param = " AND " + param
}
// 查询是否包含 id_del 字段
hasDeletedAt := checkHasDeletedAt(tx, modelName)
if hasDeletedAt {
param += " AND id_del = 0"
}
// 如果有更新时间字段,也更新一下值
updateParam := ""
if checkHasUpdatedAt(tx, modelName) {
updateParam = ",updated_at = NOW()"
}
sql := fmt.Sprintf("UPDATE %s a, (SELECT (@i := @i + 1) i, id FROM %s WHERE 1=1 %s order by sort ASC) i, "+
"(SELECT @i := 0) ir SET a.sort = i.i %s WHERE a.id = i.id", modelName, modelName, param, updateParam)
err = tx.Exec(sql).Error
if err != nil {
log.Errorf("刷新排序失败: %v", err.Error())
}
return
}

28
internal/redis/redis.go Normal file
View File

@ -0,0 +1,28 @@
package redis
import (
"context"
"gitee.ltd/lxh/logger/log"
"github.com/go-redis/redis/v8"
"wechat-robot/config"
)
var Client *redis.Client
// Init
// @description: 初始化redis客户端
func Init() {
conf := config.Conf.Redis
// 初始化连接
conn := redis.NewClient(&redis.Options{
Addr: conf.GetDSN(),
Password: conf.Password,
DB: conf.Db,
})
if err := conn.Ping(context.Background()).Err(); err != nil {
log.Panicf("Redis连接初始化失败: %v", err)
} else {
log.Debug("Redis连接初始化成功")
}
Client = conn
}

20
internal/tasks/tasks.go Normal file
View File

@ -0,0 +1,20 @@
package tasks
import (
"github.com/go-co-op/gocron"
"log"
"time"
)
var Scheduler *gocron.Scheduler
// StartScheduled
// @description: 启动定时任务
func StartScheduled() {
// 定时任务发送消息
Scheduler = gocron.NewScheduler(time.Local)
// 开启定时任务
Scheduler.StartAsync()
log.Println("定时任务初始化成功")
}

98
main.go
View File

@ -1,85 +1,49 @@
package main
import (
"gitee.ltd/lxh/logger"
"gitee.ltd/lxh/logger/log"
"github.com/gin-gonic/gin"
"go-wechat/config"
"go-wechat/initialization"
"go-wechat/mq"
"go-wechat/router"
"go-wechat/tasks"
"go-wechat/tcpserver"
"go-wechat/utils"
"html/template"
"log"
"net/http"
"strings"
"time"
"wechat-robot/internal/initialize"
"wechat-robot/pkg/validator"
"wechat-robot/router/admin"
"wechat-robot/router/callback"
"wechat-robot/router/middleware"
)
// init
// @description: 初始系统
func init() {
initialization.InitConfig() // 初始化配置
initialization.InitWechatRobotInfo() // 初始化机器人信息
initialization.Plugin() // 注册插件
tasks.InitTasks() // 初始化定时任务
mq.Init() // 初始化MQ
// 初始化日志工具
logger.InitLogger(logger.LogConfig{Mode: logger.Dev, LokiEnable: false, FileEnable: true})
// 初始化系统
initialize.InitSystem()
}
// main
// @description: 启动入口
func main() {
// 如果启用了自动配置回调,就设置一下
if config.Conf.Wechat.AutoSetCallback {
utils.ClearCallback()
time.Sleep(500 * time.Millisecond) // 休眠五百毫秒再设置
utils.SetCallback(config.Conf.Wechat.Callback)
}
// 启动TCP服务
go tcpserver.Start()
//go tcpserver.Start()
// 启动HTTP服务
// 注册参数绑定错误信息翻译器
validator.Init()
app := gin.Default()
// 自定义模板引擎函数
app.SetFuncMap(template.FuncMap{
"codeToChinese": func(code string) string {
switch code {
case "friend":
return "好友列表"
case "group":
return "群组列表"
case "index":
return "首页"
case "assistant":
return "AI角色"
default:
return "其他页面"
}
},
"boolToChinese": func(flag bool) string {
if flag {
return "是"
}
return "否"
},
})
app.LoadHTMLGlob("views/*.html")
app.Static("/assets", "./views/static")
app.StaticFile("/favicon.ico", "./views/wechat.ico")
// 开启自定义请求方式不允许处理函数
app.HandleMethodNotAllowed = true
// 处理请求方式不对
app.NoMethod(middleware.NoMethodHandler())
// 404返回数据
app.NoRoute(func(ctx *gin.Context) {
if strings.HasPrefix(ctx.Request.URL.Path, "/api") {
ctx.String(404, "接口不存在")
return
}
// 404直接跳转到首页
ctx.Redirect(302, "/404.html")
})
app.NoMethod(func(ctx *gin.Context) {
ctx.String(http.StatusMethodNotAllowed, "不支持的请求方式")
})
// 初始化路由
router.Init(app)
app.NoRoute(middleware.NoRouteHandler())
// 初始化接口路由
admin.InitRoute(app.Group("/admin/v1")) // 后台接口
callback.InitRoute(app.Group("/callback")) // 回调接口
// 启动服务
if err := app.Run(":8080"); err != nil {
log.Panicf("服务启动失败:%v", err)
log.Errorf("服务启动失败:%v", err)
return
}
}

23
model/entity/adminuser.go Normal file
View File

@ -0,0 +1,23 @@
package entity
import "wechat-robot/pkg/types"
// AdminUser
// @description: 用户表
type AdminUser struct {
types.BaseDbModel
Username string `json:"username" gorm:"index:deleted,unique;type:varchar(255); not null; comment:'登录账号'"`
Password string `json:"password" gorm:"type:varchar(255); comment:'密码'"`
Email *string `json:"email" gorm:"type:varchar(255); comment:'邮箱'"`
IsVerified bool `json:"isVerified" gorm:"type:tinyint(1); not null; default:0; comment:'是否验证邮箱'"`
LastLoginAt *types.DateTime `json:"lastLoginAt" gorm:"comment:'最后登录时间'"`
LastLoginIp *string `json:"lastLoginIp" gorm:"type:varchar(255); comment:'最后登录ip'"`
}
// TableName
// @description: 表名
// @receiver User
// @return string
func (AdminUser) TableName() string {
return "t_admin_user"
}

View File

@ -1,21 +1,15 @@
package entity
import (
"github.com/google/uuid"
"go-wechat/common/types"
"gorm.io/gorm"
"strings"
)
import "wechat-robot/pkg/types"
// AiAssistant
// @description: AI助手表
type AiAssistant struct {
Id string `json:"id" gorm:"type:varchar(32);primarykey"`
CreatedAt types.DateTime `json:"createdAt"`
Name string `json:"name" gorm:"type:varchar(10);not null;comment:'名称'"`
Personality string `json:"personality" gorm:"type:varchar(999);not null;comment:'人设'"`
Model string `json:"model" gorm:"type:varchar(50);not null;comment:'使用的模型'"`
Enable bool `json:"enable" gorm:"type:tinyint(1);not null;default:1;comment:'是否启用'"`
types.BaseDbModel
Name string `json:"name" gorm:"type:varchar(10);not null;comment:'名称'"`
Personality string `json:"personality" gorm:"type:varchar(999);not null;comment:'人设'"`
Model string `json:"model" gorm:"type:varchar(50);not null;comment:'使用的模型'"`
Enable bool `json:"enable" gorm:"type:tinyint(1);not null;default:1;comment:'是否启用'"`
}
// TableName
@ -25,15 +19,3 @@ type AiAssistant struct {
func (AiAssistant) TableName() string {
return "t_ai_assistant"
}
// BeforeCreate
// @description: 创建数据库对象之前生成UUID
// @receiver m
// @param *gorm.DB
// @return err
func (m *AiAssistant) BeforeCreate(*gorm.DB) (err error) {
if m.Id == "" {
m.Id = strings.ReplaceAll(uuid.New().String(), "-", "")
}
return
}

View File

@ -1,49 +0,0 @@
package entity
import (
"time"
)
// Friend
// @description: 好友列表
type Friend struct {
Wxid string `json:"wxid"` // 微信原始Id
CustomAccount string `json:"customAccount"` // 微信号
Nickname string `json:"nickname"` // 昵称
Pinyin string `json:"pinyin"` // 昵称拼音大写首字母
PinyinAll string `json:"pinyinAll"` // 昵称全拼
LastActive time.Time `json:"lastActive"` // 最后活跃时间
EnableAi bool `json:"enableAI" gorm:"type:tinyint(1) default 0 not null"` // 是否使用AI
AiModel string `json:"aiModel"` // AI模型
Prompt string `json:"prompt"` // 提示词
EnableChatRank bool `json:"enableChatRank" gorm:"type:tinyint(1) default 0 not null"` // 是否使用聊天排行
EnableWelcome bool `json:"enableWelcome" gorm:"type:tinyint(1) default 0 not null"` // 是否启用迎新
EnableSummary bool `json:"enableSummary" gorm:"type:tinyint(1) default 0 not null"` // 是否启用总结
EnableNews bool `json:"enableNews" gorm:"type:tinyint(1) default 0 not null"` // 是否启用新闻
ClearMember int `json:"clearMember"` // 清理成员配置(多少天未活跃的)
IsOk bool `json:"isOk" gorm:"type:tinyint(1) default 0 not null"` // 是否正常
}
func (Friend) TableName() string {
return "t_friend"
}
// GroupUser
// @description: 群成员
type GroupUser struct {
GroupId string `json:"groupId"` // 群Id
Wxid string `json:"wxid"` // 微信Id
Account string `json:"account"` // 账号
HeadImage string `json:"headImage"` // 头像
Nickname string `json:"nickname"` // 昵称
IsMember bool `json:"isMember" gorm:"type:tinyint(1) default 0 not null"` // 是否群成员
IsAdmin bool `json:"isAdmin" gorm:"type:tinyint(1) default 0 not null"` // 是否群主
JoinTime time.Time `json:"joinTime"` // 加入时间
LastActive time.Time `json:"lastActive"` // 最后活跃时间
LeaveTime *time.Time `json:"leaveTime"` // 离开时间
SkipChatRank bool `json:"skipChatRank" gorm:"type:tinyint(1) default 0 not null"` // 是否跳过聊天排行
}
func (GroupUser) TableName() string {
return "t_group_user"
}

24
model/entity/menu.go Normal file
View File

@ -0,0 +1,24 @@
package entity
import "wechat-robot/pkg/types"
// Menu
// @description: 菜单表
type Menu struct {
types.BaseDbModel
Type types.MenuType `json:"type" gorm:"type:enum('MENU','BUTTON'); default:'MENU'; not null; comment:'菜单类型(菜单或按钮)'"`
Name string `json:"name" gorm:"type:varchar(255);not null;comment:'页面组件名称'"`
Path string `json:"path" gorm:"type:varchar(255);comment:'路径'"`
Title string `json:"title" gorm:"type:varchar(255);not null;comment:'菜单标题'"`
Icon string `json:"icon" gorm:"type:varchar(255);comment:'菜单图标'"`
Sort int `json:"sort" gorm:"type:int(3);not null;comment:'排序值(数字越小约靠前)'"`
ParentId *string `json:"parentId" gorm:"type:varchar(32);comment:'父级菜单ID(0表示顶级菜单)'"`
}
// TableName
// @description: 表名
// @receiver Menu
// @return string
func (Menu) TableName() string {
return "t_menu"
}

View File

@ -1,23 +1,24 @@
package entity
import (
"go-wechat/types"
"time"
"wechat-robot/pkg/types"
)
// Message
// @description: 消息数据库结构体
type Message struct {
MsgId int64 `gorm:"primaryKey"` // 消息Id
CreateTime int // 发送时间戳
CreateAt time.Time // 发送时间
Type types.MessageType // 消息类型
Content string // 内容
DisplayFullContent string // 显示的完整内容
FromUser string // 发送者
GroupUser string // 群成员
ToUser string // 接收者
Raw string // 原始通知字符串
types.BaseDbModelWithReal
MsgId int64 `gorm:"index:idx_msg_id,unique;type:bigint;not null;comment:'微信Id'"` // 消息Id
Timestamp int `gorm:"type:bigint;not null;comment:'消息时间戳'"` // 发送时间戳
MessageTime time.Time `gorm:"type:datetime;not null;comment:'消息时间'"` // 发送时间
Type types.MessageType `gorm:"type:int;not null;comment:'消息类型'"` // 消息类型
Content string `gorm:"type:longtext;not null;comment:'消息内容'"` // 内容
DisplayFullContent string `gorm:"type:longtext;not null;comment:'显示的完整内容'"` // 显示的完整内容
FromUser string `gorm:"type:varchar(100);not null;comment:'发送者'"` // 发送者
GroupUser string `gorm:"type:varchar(100);comment:'群成员'"` // 群成员
ToUser string `gorm:"index:idx_msg_id,unique;type:varchar(100);not null;comment:'接收者'"` // 接收者
Raw string `gorm:"type:longtext;not null;comment:'原始通知字符串'"` // 原始通知字符串
}
func (Message) TableName() string {

View File

@ -1,13 +0,0 @@
package entity
// PluginData
// @description: 插件数据
type PluginData struct {
UserId string `json:"userId"` // 用户Id
PluginCode string `json:"pluginCode"` // 插件编码
Data string `json:"data"` // 数据
}
func (PluginData) TableName() string {
return "t_plugin_data"
}

30
model/entity/robot.go Normal file
View File

@ -0,0 +1,30 @@
package entity
import "wechat-robot/pkg/types"
// Robot
// @description: 机器人信息
type Robot struct {
types.BaseDbModel
WxId string `json:"wxid" gorm:"index:deleted,unique;column:wxid;type:varchar(255);not null;comment:'微信Id'"` // 微信Id
Account string `json:"account" gorm:"type:varchar(255);comment:'微信号'"` // 微信号
Nickname string `json:"name" gorm:"type:varchar(255);comment:'昵称'"` // 昵称
Avatar string `json:"avatar" gorm:"type:varchar(255);comment:'头像'"` // 头像
Mobile string `json:"mobile" gorm:"type:varchar(255);comment:'手机号'"` // 手机
CurrentDataPath string `json:"currentDataPath" gorm:"type:varchar(255);comment:'当前数据目录'"` // 当前数据目录,登录的账号目录
DataSavePath string `json:"dataSavePath" gorm:"type:varchar(255);comment:'微信保存目录'"` // 微信保存目录
DbKey string `json:"dbKey" gorm:"type:varchar(255);comment:'数据库的SQLCipher的加密key'"` // 数据库的SQLCipher的加密key可以使用该key配合decrypt.py解密数据库
HookApi string `json:"hookApi" gorm:"type:varchar(255);comment:'hook接口地址'"` // hook接口地址
Remark string `json:"remark" gorm:"type:varchar(255);comment:'备注'"` // 备注
Version int `json:"version" gorm:"type:int;comment:'版本号'"` // 版本号
VncUrl string `json:"vncUrl" gorm:"type:varchar(255);comment:'vnc地址'"` // vnc地址
Tag string `json:"tag" gorm:"type:varchar(255);comment:'标签'"` // 标签
}
// TableName
// @description: 表名
// @receiver Robot
// @return string
func (Robot) TableName() string {
return "t_robot"
}

56
model/entity/role.go Normal file
View File

@ -0,0 +1,56 @@
package entity
import "wechat-robot/pkg/types"
// Role
// @description: 角色表
type Role struct {
types.BaseDbModel
Name string `json:"name" gorm:"type:varchar(20) not null comment '角色名称'"`
Code string `json:"code" gorm:"type:varchar(20) not null comment '角色代码'"`
Describe string `json:"describe" gorm:"type:varchar(20) not null comment '描述'"`
}
// TableName
// @description: 表名
// @receiver Role
// @return string
func (Role) TableName() string {
return "t_role"
}
// =====================================================================================================================
// RoleMenu
// @description: 角色菜单表
type RoleMenu struct {
types.BaseDbModelWithReal
RoleId string `json:"roleId" gorm:"index:idx_rm_only,unique;type:varchar(32);not null;comment:'角色id'"`
MenuId string `json:"menuId" gorm:"index:idx_rm_only,unique;type:varchar(32);not null;comment:'菜单id'"`
}
// TableName
// @description: 表名
// @receiver RoleMenu
// @return string
func (RoleMenu) TableName() string {
return "t_role_menu"
}
// =====================================================================================================================
// AdminUserRole
// @description: 管理员角色表
type AdminUserRole struct {
types.BaseDbModelWithReal
RoleId string `json:"roleId" gorm:"index:idx_aur_only,unique;type:varchar(32);not null;comment:'角色id'"`
UserId string `json:"menuId" gorm:"index:idx_aur_only,unique;type:varchar(32);not null;comment:'管理员id'"`
}
// TableName
// @description: 表名
// @receiver AdminUserRole
// @return string
func (AdminUserRole) TableName() string {
return "t_admin_user_role"
}

View File

@ -0,0 +1,19 @@
package entity
import "wechat-robot/pkg/types"
// SystemConfig
// @description: 系统配置
type SystemConfig struct {
types.BaseDbModelWithReal
Code string `json:"code" gorm:"type:varchar(255);not null;comment:'配置编码'"`
Content string `json:"content" gorm:"type:text;comment:'配置内容'"`
}
// TableName
// @description: 表名
// @receiver SystemConfig
// @return string
func (SystemConfig) TableName() string {
return "t_system_config"
}

View File

@ -1,73 +0,0 @@
package model
// LeiGodLoginResp
// @description: 雷神登录返回
type LeiGodLoginResp struct {
LoginInfo struct {
AccountToken string `json:"account_token"` // Token
ExpiryTime string `json:"expiry_time"` // 有效期
NnToken string `json:"nn_token"`
} `json:"login_info"`
UserInfo struct {
Nickname string `json:"nickname"`
Email string `json:"email"`
Mobile string `json:"mobile"`
Avatar string `json:"avatar"`
RegionCode int `json:"region_code"`
} `json:"user_info"`
}
// LeiGodUserInfoResp
// @description: 雷神用户信息返回
type LeiGodUserInfoResp struct {
UserPauseTime int `json:"user_pause_time"`
Nickname string `json:"nickname"`
Email string `json:"email"`
CountryCode string `json:"country_code"`
Mobile string `json:"mobile"`
UserName string `json:"user_name"`
MasterAccount string `json:"master_account"`
Birthday string `json:"birthday"`
PublicIp string `json:"public_ip"`
Sex string `json:"sex"`
LastLoginTime string `json:"last_login_time"`
LastLoginIp string `json:"last_login_ip"`
PauseStatus string `json:"pause_status"` // 暂停状态
PauseStatusId int `json:"pause_status_id"` // 暂停状态 0未暂停1已暂停
LastPauseTime string `json:"last_pause_time"` // 最后一次暂停时间
VipLevel string `json:"vip_level"`
Avatar string `json:"avatar"`
AvatarNew string `json:"avatar_new"`
PackageId string `json:"package_id"`
IsSwitchPackage int `json:"is_switch_package"`
PackageTitle string `json:"package_title"`
PackageLevel string `json:"package_level"`
BillingType string `json:"billing_type"`
Lang string `json:"lang"`
StopedRemaining string `json:"stoped_remaining"`
ExpiryTime string `json:"expiry_time"` // 剩余时长
ExpiryTimeSamp int `json:"expiry_time_samp"` // 剩余时长秒数
Address string `json:"address"`
MobileContactType string `json:"mobile_contact_type"`
MobileContactNumber string `json:"mobile_contact_number"`
MobileContactTitle string `json:"mobile_contact_title"`
RegionCode int `json:"region_code"`
IsPayUser string `json:"is_pay_user"`
WallLogSwitch string `json:"wall_log_switch"`
IsSetAdminPass int `json:"is_set_admin_pass"`
ExpiredExperienceTime string `json:"expired_experience_time"`
ExperienceExpiryTime string `json:"experience_expiry_time"`
ExperienceTime int `json:"experience_time"`
FirstInvoiceDiscount int `json:"first_invoice_discount"`
NnNumber string `json:"nn_number"`
UserSignature string `json:"user_signature"`
MobileExpiryTime string `json:"mobile_expiry_time"`
MobileExpiryTimeSamp int `json:"mobile_expiry_time_samp"`
MobilePauseStatus int `json:"mobile_pause_status"`
BlackExpiredTime string `json:"black_expired_time"`
MobileExperienceTime string `json:"mobile_experience_time"`
SuperTime string `json:"super_time"`
NowDate string `json:"now_date"`
NowTimeSamp int `json:"now_time_samp"`
UserEarnMinutes string `json:"user_earn_minutes"`
}

View File

@ -1,18 +0,0 @@
package model
// MorningPost
// @description: 每日早报返回结构体
type MorningPost struct {
Code int `json:"code"`
Msg string `json:"msg"`
Data struct {
Date string `json:"date"` // 新闻日期
News []string `json:"news"` // 新闻标题文字版
WeiYu string `json:"weiyu"` // 微语,就是一句屁话
Image string `json:"image"` // 早报完整图片
HeadImage string `json:"head_image"` // 早报头部图片
} `json:"data"`
Time int `json:"time"`
Usage int `json:"usage"`
LogId string `json:"log_id"`
}

View File

@ -0,0 +1,11 @@
package aiassistant
// Save
// @description: 保存AI助手入参
type Save struct {
Id string `json:"id" form:"id"` // Id
Name string `json:"name" form:"name" binding:"required"` // 名称
Personality string `json:"personality" form:"personality" binding:"required"` // 人设
Model string `json:"model" form:"model" binding:"required"` // 使用的模型
Enable bool `json:"enable" form:"enable"` // 是否启用
}

View File

@ -0,0 +1,7 @@
package aiassistant
// GetAll
// @description: 获取所有AI助手
type GetAll struct {
Keyword string `json:"keyword" form:"keyword"` // 关键字
}

View File

@ -0,0 +1,8 @@
package callback
// RobotHook
// @description: 机器人HOOK后回调
type RobotHook struct {
Robot string `json:"robot" form:"robot"` // 机器人
Status string `json:"status" form:"status"` // 状态
}

Some files were not shown because too many files have changed in this diff Show More