This commit is contained in:
laodaming 2023-11-06 15:19:14 +08:00
parent ee06eef1d3
commit 21f62035cf
4 changed files with 114 additions and 0 deletions

View File

@ -0,0 +1,25 @@
package gmodel
import (
"gorm.io/gorm"
"time"
)
// fs_feishu_config 飞书app配置表
type FsFeishuConfig struct {
Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // ID
AppId *string `gorm:"default:'';" json:"app_id"` // app_id
AppSecret *string `gorm:"default:'';" json:"app_secret"` // app密钥
EncryptKey *string `gorm:"default:'';" json:"encrypt_key"` //
TicketMetdata *string `gorm:"default:'';" json:"ticket_metdata"` // ticket元数据
Ctime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"ctime"` //
Utime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"utime"` //
}
type FsFeishuConfigModel struct {
db *gorm.DB
name string
}
func NewFsFeishuConfigModel(db *gorm.DB) *FsFeishuConfigModel {
return &FsFeishuConfigModel{db: db, name: "fs_feishu_config"}
}

View File

@ -0,0 +1,2 @@
package gmodel
// TODO: 使用model的属性做你想做的

View File

@ -0,0 +1,44 @@
package handler
import (
"encoding/json"
"net/http"
"reflect"
"fusenapi/utils/basic"
"fusenapi/server/feishu-sync/internal/logic"
"fusenapi/server/feishu-sync/internal/svc"
"fusenapi/server/feishu-sync/internal/types"
)
func WebhookHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.WebhookReq
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
if err != nil {
return
}
//验证连接
if req.Type == "url_verification" {
challengeRsp := map[string]string{
"challenge": req.Challenge,
}
b, _ := json.Marshal(challengeRsp)
w.Write(b)
return
}
// 创建一个业务逻辑层实例
l := logic.NewWebhookLogic(r.Context(), svcCtx)
rl := reflect.ValueOf(l)
basic.BeforeLogic(w, r, rl)
resp := l.Webhook(&req, userinfo)
if !basic.AfterLogic(w, r, rl, resp) {
basic.NormalAfterLogic(w, r, resp)
}
}
}

View File

@ -0,0 +1,43 @@
package logic
import (
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"context"
"fusenapi/server/feishu-sync/internal/svc"
"fusenapi/server/feishu-sync/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type WebhookLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewWebhookLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WebhookLogic {
return &WebhookLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
// 处理进入前逻辑w,r
// func (l *WebhookLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
// }
func (l *WebhookLogic) Webhook(req *types.WebhookReq, userinfo *auth.UserInfo) (resp *basic.Response) {
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
// userinfo 传入值时, 一定不为null
return resp.SetStatus(basic.CodeOK)
}
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
// func (l *WebhookLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
// // httpx.OkJsonCtx(r.Context(), w, resp)
// }