diff --git a/server/feishu-sync/internal/handler/ticketwebhookhandler.go b/server/feishu-sync/internal/handler/ticketwebhookhandler.go index 2c07f46c..0351028e 100644 --- a/server/feishu-sync/internal/handler/ticketwebhookhandler.go +++ b/server/feishu-sync/internal/handler/ticketwebhookhandler.go @@ -27,7 +27,7 @@ func TicketWebhookHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { rl := reflect.ValueOf(l) basic.BeforeLogic(w, r, rl) - resp := l.TicketWebhook(&req, userinfo) + resp := l.TicketWebhook(&req, userinfo, w) if !basic.AfterLogic(w, r, rl, resp) { basic.NormalAfterLogic(w, r, resp) diff --git a/server/feishu-sync/internal/logic/ticketwebhooklogic.go b/server/feishu-sync/internal/logic/ticketwebhooklogic.go index d7cc596b..52862844 100644 --- a/server/feishu-sync/internal/logic/ticketwebhooklogic.go +++ b/server/feishu-sync/internal/logic/ticketwebhooklogic.go @@ -1,8 +1,10 @@ package logic import ( + "encoding/json" "fusenapi/utils/auth" "fusenapi/utils/basic" + "net/http" "context" @@ -30,8 +32,17 @@ func NewTicketWebhookLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Tic // func (l *TicketWebhookLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { // } -func (l *TicketWebhookLogic) TicketWebhook(req *types.TicketWebhookReq, userinfo *auth.UserInfo) (resp *basic.Response) { - return resp.SetStatus(basic.CodeOK) +func (l *TicketWebhookLogic) TicketWebhook(req *types.TicketWebhookReq, userinfo *auth.UserInfo, w http.ResponseWriter) (resp *basic.Response) { + //验证连接 + if req.Type == "url_verification" { + challengeRsp := map[string]string{ + "challenge": req.Challenge, + } + b, _ := json.Marshal(challengeRsp) + w.Write(b) + return + } + return resp.SetStatusWithMessage(basic.CodeOK, "success") } // 处理逻辑后 w,r 如:重定向, resp 必须重新处理 diff --git a/server/feishu-sync/internal/types/types.go b/server/feishu-sync/internal/types/types.go index 87b1c618..089ebe5b 100644 --- a/server/feishu-sync/internal/types/types.go +++ b/server/feishu-sync/internal/types/types.go @@ -6,10 +6,12 @@ import ( ) type TicketWebhookReq struct { - Ts string `json:"ts"` //webhook时间 - Uuid string `json:"uuid"` //事件唯一标识 - Token string `json:"token"` //即Verification Token - Event Event `json:"event"` //事件 + Ts string `json:"ts"` //webhook时间 + Uuid string `json:"uuid"` //事件唯一标识 + Token string `json:"token"` //即Verification Token + Event Event `json:"event"` //事件 + Challenge string `json:"challenge"` //设置飞书通知接口验证用 + Type string `json:"type"` //设置飞书通知接口验证用 } type Event struct { diff --git a/server_api/feishu-sync.api b/server_api/feishu-sync.api index 207ea8c3..f1f8e3c6 100644 --- a/server_api/feishu-sync.api +++ b/server_api/feishu-sync.api @@ -16,10 +16,12 @@ service feishu-sync { } type TicketWebhookReq { - Ts string `json:"ts"` //webhook时间 - Uuid string `json:"uuid"` //事件唯一标识 - Token string `json:"token"` //即Verification Token - Event Event `json:"event"` //事件 + Ts string `json:"ts"` //webhook时间 + Uuid string `json:"uuid"` //事件唯一标识 + Token string `json:"token"` //即Verification Token + Event Event `json:"event"` //事件 + Challenge string `json:"challenge"` //设置飞书通知接口验证用 + Type string `json:"type"` //设置飞书通知接口验证用 } type Event {