fix
This commit is contained in:
parent
71f7be0149
commit
03af6aa70e
|
@ -2,8 +2,6 @@ package handler
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"reflect"
|
||||
|
||||
|
@ -21,7 +19,7 @@ func WebhookHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||
if err != nil {
|
||||
return
|
||||
}
|
||||
//验证连接
|
||||
//验证连接(直接返回)
|
||||
if req.Type == "url_verification" {
|
||||
challengeRsp := map[string]string{
|
||||
"challenge": req.Challenge,
|
||||
|
@ -30,9 +28,6 @@ func WebhookHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|||
w.Write(b)
|
||||
return
|
||||
}
|
||||
b, _ := io.ReadAll(r.Body)
|
||||
log.Println("收到body信息:", string(b))
|
||||
log.Println("收到头消息:", r.Header)
|
||||
// 创建一个业务逻辑层实例
|
||||
l := logic.NewWebhookLogic(r.Context(), svcCtx)
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
|
@ -29,8 +30,43 @@ func NewWebhookLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WebhookLo
|
|||
// 处理进入前逻辑w,r
|
||||
// func (l *WebhookLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
||||
// }
|
||||
// webhook消息事件基础信息
|
||||
type BaseWebhookMsgHeaderType struct {
|
||||
EventId string `json:"event_id"` //事件id(可作为消息唯一性确认)
|
||||
EventType string `json:"event_type"` //事件类型
|
||||
CreateTime string `json:"create_time"` //创建时间
|
||||
Token string `json:"token"` //事件token
|
||||
AppId string `json:"app_id"` //app id
|
||||
TenantKey string `json:"tenant_key"` //租户key
|
||||
}
|
||||
|
||||
func (l *WebhookLogic) Webhook(req *types.WebhookReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
var msgHeader BaseWebhookMsgHeaderType
|
||||
if req.Event["header"] == nil {
|
||||
logx.Error("invalid request")
|
||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid request")
|
||||
}
|
||||
if err := json.Unmarshal([]byte(req.Event["header"].(string)), &msgHeader); err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusAddMessage(basic.CodeJsonErr, "failed to parse params")
|
||||
}
|
||||
logx.Info("收到事件:" + msgHeader.EventType)
|
||||
switch msgHeader.EventType {
|
||||
case "contact.custom_attr_event.updated_v3": //成员字段管理属性变更事件
|
||||
case "contact.department.created_v3": //部门新建
|
||||
case "contact.department.deleted_v3": //部门删除
|
||||
case "contact.department.updated_v3": //部门信息变化
|
||||
case "contact.employee_type_enum.actived_v3": //启动人员类型事件
|
||||
case "contact.employee_type_enum.created_v3": //新建人员类型事件
|
||||
case "contact.employee_type_enum.deactivated_v3": //停用人员类型事件
|
||||
case "contact.employee_type_enum.deleted_v3": //删除人员类型事件
|
||||
case "contact.employee_type_enum.updated_v3": //修改人员类型名称事件
|
||||
case "contact.scope.updated_v3": //通讯录范围权限被更新
|
||||
case "contact.user.created_v3": //员工入职
|
||||
case "contact.user.deleted_v3": //员工离职
|
||||
case "contact.user.updated_v3": //员工信息变化
|
||||
|
||||
}
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
}
|
||||
|
||||
|
|
|
@ -6,10 +6,9 @@ import (
|
|||
)
|
||||
|
||||
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"` //事件
|
||||
Schema string `json:"schema"`
|
||||
Header map[string]interface{} `json:"header"`
|
||||
Event map[string]interface{} `json:"event"`
|
||||
Challenge string `json:"challenge,optional"` //设置飞书通知接口验证用
|
||||
Type string `json:"type,optional"` //设置飞书通知接口验证用
|
||||
}
|
||||
|
|
|
@ -16,10 +16,9 @@ service feishu-sync {
|
|||
}
|
||||
|
||||
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"` //事件
|
||||
Schema string `json:"schema"`
|
||||
Header map[string]interface{} `json:"header"`
|
||||
Event map[string]interface{} `json:"event"`
|
||||
Challenge string `json:"challenge,optional"` //设置飞书通知接口验证用
|
||||
Type string `json:"type,optional"` //设置飞书通知接口验证用
|
||||
}
|
Loading…
Reference in New Issue
Block a user