This commit is contained in:
laodaming 2023-11-06 14:59:23 +08:00
parent 09fcd6c7ab
commit fd86cccdf2
4 changed files with 26 additions and 11 deletions

View File

@ -27,7 +27,7 @@ func TicketWebhookHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
rl := reflect.ValueOf(l) rl := reflect.ValueOf(l)
basic.BeforeLogic(w, r, rl) basic.BeforeLogic(w, r, rl)
resp := l.TicketWebhook(&req, userinfo) resp := l.TicketWebhook(&req, userinfo, w)
if !basic.AfterLogic(w, r, rl, resp) { if !basic.AfterLogic(w, r, rl, resp) {
basic.NormalAfterLogic(w, r, resp) basic.NormalAfterLogic(w, r, resp)

View File

@ -1,8 +1,10 @@
package logic package logic
import ( import (
"encoding/json"
"fusenapi/utils/auth" "fusenapi/utils/auth"
"fusenapi/utils/basic" "fusenapi/utils/basic"
"net/http"
"context" "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) BeforeLogic(w http.ResponseWriter, r *http.Request) {
// } // }
func (l *TicketWebhookLogic) TicketWebhook(req *types.TicketWebhookReq, userinfo *auth.UserInfo) (resp *basic.Response) { func (l *TicketWebhookLogic) TicketWebhook(req *types.TicketWebhookReq, userinfo *auth.UserInfo, w http.ResponseWriter) (resp *basic.Response) {
return resp.SetStatus(basic.CodeOK) //验证连接
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 必须重新处理 // 处理逻辑后 w,r 如:重定向, resp 必须重新处理

View File

@ -6,10 +6,12 @@ import (
) )
type TicketWebhookReq struct { type TicketWebhookReq struct {
Ts string `json:"ts"` //webhook时间 Ts string `json:"ts"` //webhook时间
Uuid string `json:"uuid"` //事件唯一标识 Uuid string `json:"uuid"` //事件唯一标识
Token string `json:"token"` //即Verification Token Token string `json:"token"` //即Verification Token
Event Event `json:"event"` //事件 Event Event `json:"event"` //事件
Challenge string `json:"challenge"` //设置飞书通知接口验证用
Type string `json:"type"` //设置飞书通知接口验证用
} }
type Event struct { type Event struct {

View File

@ -16,10 +16,12 @@ service feishu-sync {
} }
type TicketWebhookReq { type TicketWebhookReq {
Ts string `json:"ts"` //webhook时间 Ts string `json:"ts"` //webhook时间
Uuid string `json:"uuid"` //事件唯一标识 Uuid string `json:"uuid"` //事件唯一标识
Token string `json:"token"` //即Verification Token Token string `json:"token"` //即Verification Token
Event Event `json:"event"` //事件 Event Event `json:"event"` //事件
Challenge string `json:"challenge"` //设置飞书通知接口验证用
Type string `json:"type"` //设置飞书通知接口验证用
} }
type Event { type Event {