fix
This commit is contained in:
@@ -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),
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
// }
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user