add
This commit is contained in:
@@ -29,6 +29,8 @@ type FormConfig struct {
|
||||
// FormConfigService 表单配置服务接口
|
||||
type FormConfigService interface {
|
||||
GetFormConfig(ctx context.Context, apiCode string) (*FormConfig, error)
|
||||
// RequiresIdentityInput 该 API 入参是否要求身份证(id_card / idCard 为必填)
|
||||
RequiresIdentityInput(ctx context.Context, apiCode string) bool
|
||||
}
|
||||
|
||||
// FormConfigServiceImpl 表单配置服务实现
|
||||
@@ -72,6 +74,35 @@ func (s *FormConfigServiceImpl) GetFormConfig(ctx context.Context, apiCode strin
|
||||
return config, nil
|
||||
}
|
||||
|
||||
// RequiresIdentityInput 判断 API 是否以身份证为必填入参。
|
||||
// api_codes 为 ["*"] 时,仅对此类接口生效;无 id_card 必填字段的接口不会被拦截。
|
||||
func (s *FormConfigServiceImpl) RequiresIdentityInput(ctx context.Context, apiCode string) bool {
|
||||
if len(apiCode) >= 4 && strings.EqualFold(apiCode[:4], "COMB") {
|
||||
// 组合包是否拦截由请求入参是否含 id_card 决定(在 QueryWhitelist 上层已校验)
|
||||
return true
|
||||
}
|
||||
dtoStruct, err := s.getDTOStruct(ctx, apiCode)
|
||||
if err != nil || dtoStruct == nil {
|
||||
return false
|
||||
}
|
||||
return dtoStructRequiresIdentityInput(dtoStruct)
|
||||
}
|
||||
|
||||
func dtoStructRequiresIdentityInput(dtoStruct interface{}) bool {
|
||||
t := reflect.TypeOf(dtoStruct).Elem()
|
||||
for i := 0; i < t.NumField(); i++ {
|
||||
field := t.Field(i)
|
||||
jsonTag := strings.Split(field.Tag.Get("json"), ",")[0]
|
||||
if jsonTag != "id_card" && jsonTag != "idCard" {
|
||||
continue
|
||||
}
|
||||
if strings.Contains(field.Tag.Get("validate"), "required") {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// getDTOStruct 根据API代码获取对应的DTO结构体
|
||||
func (s *FormConfigServiceImpl) getDTOStruct(ctx context.Context, apiCode string) (interface{}, error) {
|
||||
// 建立API代码到DTO结构体的映射
|
||||
|
||||
Reference in New Issue
Block a user