This commit is contained in:
laodaming 2023-11-06 15:17:29 +08:00
parent deed8bb14c
commit 1965692f0f
7 changed files with 21 additions and 116 deletions

View File

@ -21,9 +21,9 @@ type FsPreprocessLogo struct {
IsBranch *int64 `gorm:"default:0;" json:"is_branch"` // 是否分店
Metadata *[]byte `gorm:"default:'';" json:"metadata"` //
Source *string `gorm:"index;default:'';" json:"source"` //
IsDel *int64 `gorm:"index;default:0;" json:"is_del"` // 是否删除
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"` //
IsDel *int64 `gorm:"index;default:0;" json:"is_del"` // 是否删除
}
type FsPreprocessLogoModel struct {
db *gorm.DB

View File

@ -49,6 +49,7 @@ type AllModelsGen struct {
FsFactoryProduct *FsFactoryProductModel // fs_factory_product 工厂生产表(废弃)
FsFactoryShipTmp *FsFactoryShipTmpModel // fs_factory_ship_tmp
FsFaq *FsFaqModel // fs_faq 常见问题
FsFeishuConfig *FsFeishuConfigModel // fs_feishu_config 飞书app配置表
FsFont *FsFontModel // fs_font 字体配置
FsGerent *FsGerentModel // fs_gerent 管理员表
FsGuest *FsGuestModel // fs_guest 游客表
@ -167,6 +168,7 @@ func NewAllModels(gdb *gorm.DB) *AllModelsGen {
FsFactoryProduct: NewFsFactoryProductModel(gdb),
FsFactoryShipTmp: NewFsFactoryShipTmpModel(gdb),
FsFaq: NewFsFaqModel(gdb),
FsFeishuConfig: NewFsFeishuConfigModel(gdb),
FsFont: NewFsFontModel(gdb),
FsGerent: NewFsGerentModel(gdb),
FsGuest: NewFsGuestModel(gdb),

View File

@ -14,8 +14,8 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
[]rest.Route{
{
Method: http.MethodPost,
Path: "/api/feishu/ticket_webhook",
Handler: TicketWebhookHandler(serverCtx),
Path: "/api/feishu/webhook",
Handler: WebhookHandler(serverCtx),
},
},
)

View File

@ -1,43 +0,0 @@
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 TicketWebhookHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.TicketWebhookReq
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.NewTicketWebhookLogic(r.Context(), svcCtx)
rl := reflect.ValueOf(l)
basic.BeforeLogic(w, r, rl)
resp := l.TicketWebhook(&req, userinfo, w)
if !basic.AfterLogic(w, r, rl, resp) {
basic.NormalAfterLogic(w, r, resp)
}
}
}

View File

@ -1,42 +0,0 @@
package logic
import (
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"net/http"
"context"
"fusenapi/server/feishu-sync/internal/svc"
"fusenapi/server/feishu-sync/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type TicketWebhookLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewTicketWebhookLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TicketWebhookLogic {
return &TicketWebhookLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
// 处理进入前逻辑w,r
// func (l *TicketWebhookLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
// }
func (l *TicketWebhookLogic) TicketWebhook(req *types.TicketWebhookReq, userinfo *auth.UserInfo, w http.ResponseWriter) (resp *basic.Response) {
return resp.SetStatusWithMessage(basic.CodeOK, "success")
}
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
// func (l *TicketWebhookLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
// // httpx.OkJsonCtx(r.Context(), w, resp)
// }

View File

@ -5,19 +5,13 @@ import (
"fusenapi/utils/basic"
)
type TicketWebhookReq struct {
Ts string `json:"ts,optional"` //webhook时间
Uuid string `json:"uuid,optional"` //事件唯一标识
Token string `json:"token,optional"` //即Verification Token
Event Event `json:"event,optional"` //事件
Challenge string `json:"challenge,optional"` //设置飞书通知接口验证用
Type string `json:"type,optional"` //设置飞书通知接口验证用
}
type Event struct {
AppId string `json:"app_id"`
AppTicket string `json:"app_ticket"`
Type string `json:"type"`
type WebhookReq struct {
Ts string `json:"ts,optional"` //webhook时间
Uuid string `json:"uuid,optional"` //事件唯一标识
Token string `json:"token,optional"` //即Verification Token
Event map[string]interface{} `json:"event,optional"` //事件
Challenge string `json:"challenge,optional"` //设置飞书通知接口验证用
Type string `json:"type,optional"` //设置飞书通知接口验证用
}
type Request struct {

View File

@ -11,21 +11,15 @@ import "basic.api"
service feishu-sync {
//飞书ticket webhook事件接口
@handler TicketWebhookHandler
post /api/feishu/ticket_webhook (TicketWebhookReq) returns (response);
@handler WebhookHandler
post /api/feishu/webhook (WebhookReq) returns (response);
}
type TicketWebhookReq {
Ts string `json:"ts,optional"` //webhook时间
Uuid string `json:"uuid,optional"` //事件唯一标识
Token string `json:"token,optional"` //即Verification Token
Event Event `json:"event,optional"` //事件
Challenge string `json:"challenge,optional"` //设置飞书通知接口验证用
Type string `json:"type,optional"` //设置飞书通知接口验证用
}
type Event {
AppId string `json:"app_id"`
AppTicket string `json:"app_ticket"`
Type string `json:"type"`
type WebhookReq {
Ts string `json:"ts,optional"` //webhook时间
Uuid string `json:"uuid,optional"` //事件唯一标识
Token string `json:"token,optional"` //即Verification Token
Event map[string]interface{} `json:"event,optional"` //事件
Challenge string `json:"challenge,optional"` //设置飞书通知接口验证用
Type string `json:"type,optional"` //设置飞书通知接口验证用
}