fix
This commit is contained in:
parent
ee06eef1d3
commit
21f62035cf
25
model/gmodel/fs_feishu_config_gen.go
Normal file
25
model/gmodel/fs_feishu_config_gen.go
Normal 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"}
|
||||
}
|
2
model/gmodel/fs_feishu_config_logic.go
Normal file
2
model/gmodel/fs_feishu_config_logic.go
Normal file
|
@ -0,0 +1,2 @@
|
|||
package gmodel
|
||||
// TODO: 使用model的属性做你想做的
|
44
server/feishu-sync/internal/handler/webhookhandler.go
Normal file
44
server/feishu-sync/internal/handler/webhookhandler.go
Normal 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)
|
||||
}
|
||||
}
|
||||
}
|
43
server/feishu-sync/internal/logic/webhooklogic.go
Normal file
43
server/feishu-sync/internal/logic/webhooklogic.go
Normal 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)
|
||||
// }
|
Loading…
Reference in New Issue
Block a user