diff --git a/admin/server/model/gaia/request/system.go b/admin/server/model/gaia/request/system.go index 7cee9ddd1..939a64187 100644 --- a/admin/server/model/gaia/request/system.go +++ b/admin/server/model/gaia/request/system.go @@ -27,3 +27,37 @@ type SystemOAuth2Request struct { Test bool `json:"test" gorm:"default:0;comment:是否测试链接联通性"` // 是否测试链接联通性 Code string `json:"code" gorm:"default:0;comment:code代码"` // code代码 } + +// AuthorizationConfig 认证配置 +type AuthorizationConfig struct { + Type string `json:"type"` // none | bearer | basic + Token string `json:"token"` // Bearer Token + Username string `json:"username"` // Basic Auth用户名 + Password string `json:"password"` // Basic Auth密码 +} + +// BodyData Body数据配置 +type BodyData struct { + FormData []map[string]string `json:"form_data"` // form-data格式数据 + Urlencoded []map[string]string `json:"urlencoded"` // x-www-form-urlencoded格式数据 + Raw string `json:"raw"` // raw JSON字符串 +} + +// EmailApiConfig 第三方邮箱API配置 +type EmailApiConfig struct { + Enabled bool `json:"enabled"` // 是否启用 + URL string `json:"url"` // API地址 + Method string `json:"method"` // HTTP方法 + RequestParamField string `json:"request_param_field"` // 请求参数字段名 + BodyType string `json:"body_type"` // Body类型: form-data | x-www-form-urlencoded | raw + Headers map[string]string `json:"headers"` // 请求头 + Authorization AuthorizationConfig `json:"authorization"` // 认证配置 + BodyData BodyData `json:"body_data"` // Body数据 + ResponseEmailField string `json:"response_email_field"` // 响应邮箱字段路径 +} + +// DingTalkConfigRequest 钉钉集成配置 +type DingTalkConfigRequest struct { + EmailApi EmailApiConfig `json:"email_api"` // 第三方邮箱API配置 +} + diff --git a/admin/server/service/gaia/system.go b/admin/server/service/gaia/system.go index 671fde1f4..b1c03d1cd 100644 --- a/admin/server/service/gaia/system.go +++ b/admin/server/service/gaia/system.go @@ -157,6 +157,11 @@ func (e *SystemIntegratedService) TestConnection(integrate gaia.SystemIntegratio if _, err := e.DingTalkConfigAvailable(integrate); err != nil { return errors.New("钉钉链接失败: " + err.Error()) } + // 验证第三方邮箱API配置 + if err := e.ValidateEmailApiConfig(integrate); err != nil { + global.GVA_LOG.Warn("第三方邮箱API配置验证失败", zap.Error(err)) + // 不阻止保存,只记录警告 + } return nil case gaia.SystemIntegrationOAuth2: // 测试OAuth2连接 @@ -166,6 +171,79 @@ func (e *SystemIntegratedService) TestConnection(integrate gaia.SystemIntegratio } } +// ValidateEmailApiConfig 验证第三方邮箱API配置 +// @Tags System Integrated +// @Summary 验证第三方邮箱API配置 +// @param: integrate gaia.SystemIntegration +// @return: error +func (e *SystemIntegratedService) ValidateEmailApiConfig(integrate gaia.SystemIntegration) error { + // 解析Config字段 + if integrate.Config == "" { + return nil // 配置为空不算错误 + } + + var configMap request.DingTalkConfigRequest + if err := json.Unmarshal([]byte(integrate.Config), &configMap); err != nil { + return fmt.Errorf("解析配置失败: %s", err.Error()) + } + + // 检查是否启用邮箱API + if !configMap.EmailApi.Enabled { + return nil // 未启用不需要验证 + } + + // 验证必填字段 + if configMap.EmailApi.URL == "" { + return errors.New("邮箱API URL不能为空") + } + + if configMap.EmailApi.Method == "" { + configMap.EmailApi.Method = "GET" + } + + if configMap.EmailApi.RequestParamField == "" { + return errors.New("邮箱请求字段不能为空") + } + + if configMap.EmailApi.ResponseEmailField == "" { + return errors.New("邮箱信息提取字段不能为空") + } + + // 验证Body类型(仅POST/PUT/DELETE需要) + if configMap.EmailApi.Method != "GET" { + bodyType := strings.ToLower(configMap.EmailApi.BodyType) + if bodyType == "" { + configMap.EmailApi.BodyType = "raw" // 默认raw + } else if bodyType != "form-data" && bodyType != "x-www-form-urlencoded" && bodyType != "raw" { + return fmt.Errorf("不支持的Body类型: %s,支持的类型: form-data, x-www-form-urlencoded, raw", bodyType) + } + } + + // 验证Authorization配置 + authType := strings.ToLower(configMap.EmailApi.Authorization.Type) + if authType != "" && authType != "none" { + if authType == "bearer" { + if configMap.EmailApi.Authorization.Token == "" { + return errors.New("Bearer Token不能为空") + } + } else if authType == "basic" { + if configMap.EmailApi.Authorization.Username == "" || configMap.EmailApi.Authorization.Password == "" { + return errors.New("Basic Auth需要填写Username和Password") + } + } else { + return fmt.Errorf("不支持的Authorization类型: %s,支持的类型: none, bearer, basic", authType) + } + } + + global.GVA_LOG.Info("第三方邮箱API配置验证通过", + zap.String("url", configMap.EmailApi.URL), + zap.String("method", configMap.EmailApi.Method), + zap.String("body_type", configMap.EmailApi.BodyType), + zap.String("auth_type", configMap.EmailApi.Authorization.Type)) + + return nil +} + // TestOAuth2Connection 测试OAuth2连接 // @Tags System Integrated // @Summary 测试OAuth2连接 diff --git a/admin/web/src/view/systemIntegrated/dingTalk/index.vue b/admin/web/src/view/systemIntegrated/dingTalk/index.vue index a62a7e540..92ec1099c 100644 --- a/admin/web/src/view/systemIntegrated/dingTalk/index.vue +++ b/admin/web/src/view/systemIntegrated/dingTalk/index.vue @@ -87,7 +87,253 @@ 测试连接 - + +
+
+ + + + +
+
+ 第三方邮箱配置 +
+
+ +
+ 邮箱详情的URL: + + {{ emailApiConfig.url || '未配置' }} +
+
+ HTTP方法: + + + + + + + {{ emailApiConfig.method || 'GET' }} +
+ + +
+ + + +
+
+ + + +
+ + 添加Header + +
+
+ + + +
+
+ + form-data + x-www-form-urlencoded + raw (JSON) + +
+ + +
+
+ + + + 系统字段 +
+ + 添加字段 + +
+ + +
+
+ + + + 系统字段 +
+ + 添加字段 + +
+ + +
+ +
+
+
+ + + +
+
+ + None + Bearer Token + Basic Auth + +
+ + +
+ +
+ + +
+ + +
+
+
+
+
+ + +
+
+
Headers:
+
+ {{ key }}: + {{ value }} +
+
+
+
Authorization:
+ {{ emailApiConfig.authorization.type === 'bearer' ? 'Bearer Token' : 'Basic Auth' }} +
+
+ + +
+ 邮箱请求字段: + + {{ emailApiConfig.request_param_field || 'userId' }} +
+
+ 邮箱信息提取: + + + + {{ emailApiConfig.response_email_field || 'data[0].userName' }} +
+
+ 保存
@@ -124,8 +370,9 @@