diff --git a/internal/domains/api/dto/api_request_dto.go b/internal/domains/api/dto/api_request_dto.go index 19314df..0f8a483 100644 --- a/internal/domains/api/dto/api_request_dto.go +++ b/internal/domains/api/dto/api_request_dto.go @@ -219,3 +219,8 @@ type COMB86PMReq struct { type QCXG7A2BReq struct { IDCard string `json:"id_card" validate:"required,validIDCard"` } + +type COMENT01Req struct { + EntName string `json:"ent_name" validate:"required,min=1,validName"` + EntCode string `json:"ent_code" validate:"required,validUSCI"` +} diff --git a/internal/domains/api/services/api_request_service.go b/internal/domains/api/services/api_request_service.go index ff882a2..5933065 100644 --- a/internal/domains/api/services/api_request_service.go +++ b/internal/domains/api/services/api_request_service.go @@ -103,6 +103,7 @@ func registerAllProcessors(combService *comb.CombService) { "QYGL8271": qygl.ProcessQYGL8271Request, "QYGLB4C0": qygl.ProcessQYGLB4C0Request, "QYGL23T7": qygl.ProcessQYGL23T7Request, // 企业三要素验证 + "COMENT01": qygl.ProcessCOMENT01Request, // 企业风险报告 // YYSY系列处理器 "YYSYD50F": yysy.ProcessYYSYD50FRequest, diff --git a/internal/domains/api/services/processors/flxg/flxg0v4b_processor.go b/internal/domains/api/services/processors/flxg/flxg0v4b_processor.go index c47cfec..fa22dac 100644 --- a/internal/domains/api/services/processors/flxg/flxg0v4b_processor.go +++ b/internal/domains/api/services/processors/flxg/flxg0v4b_processor.go @@ -5,6 +5,7 @@ import ( "encoding/json" "errors" "fmt" + "log" "tyapi-server/internal/domains/api/dto" "tyapi-server/internal/domains/api/services/processors" @@ -48,6 +49,7 @@ func ProcessFLXG0V4BRequest(ctx context.Context, params []byte, deps *processors "inquired_auth": fmt.Sprintf("authed:%s", paramsDto.AuthDate), }, } + log.Println("reqData", reqData) respBytes, err := deps.WestDexService.CallAPI("G22SC01", reqData) if err != nil { // 数据源错误 diff --git a/internal/domains/api/services/processors/qygl/coment01_processor.go b/internal/domains/api/services/processors/qygl/coment01_processor.go new file mode 100644 index 0000000..bd2a2cb --- /dev/null +++ b/internal/domains/api/services/processors/qygl/coment01_processor.go @@ -0,0 +1,68 @@ +package qygl + +import ( + "context" + "encoding/json" + "fmt" + "io" + "net/http" + "strings" + + "tyapi-server/internal/domains/api/dto" + "tyapi-server/internal/domains/api/services/processors" +) + +// ProcessCOMENT01Request COMENT01 API处理方法 - 企业风险报告 +func ProcessCOMENT01Request(ctx context.Context, params []byte, deps *processors.ProcessorDependencies) ([]byte, error) { + var paramsDto dto.COMENT01Req + if err := json.Unmarshal(params, ¶msDto); err != nil { + return nil, fmt.Errorf("%s: %w", processors.ErrSystem, err) + } + + if err := deps.Validator.ValidateStruct(paramsDto); err != nil { + return nil, fmt.Errorf("%s: %w", processors.ErrInvalidParam, err) + } + + // 构建请求体 + requestBody := map[string]string{ + "company_name": paramsDto.EntName, + "credit_code": paramsDto.EntCode, + } + + requestBodyBytes, err := json.Marshal(requestBody) + if err != nil { + return nil, fmt.Errorf("%s: %w", processors.ErrSystem, err) + } + + // 创建HTTP请求 + url := "https://api.v1.tybigdata.com/api/v1/enterprise/risk-report" + req, err := http.NewRequestWithContext(ctx, "POST", url, strings.NewReader(string(requestBodyBytes))) + if err != nil { + return nil, fmt.Errorf("%s: %w", processors.ErrSystem, err) + } + + // 设置请求头 + req.Header.Set("Content-Type", "application/json") + req.Header.Set("apikey", "1000000$BUsWYV5DQ3CSvPWYYegkr3$TZmMl7WZ29Zj5gcRmgieoqVs1oBjOt3BPWGq7iTSF5o") + + // 发送请求 + client := &http.Client{} + resp, err := client.Do(req) + if err != nil { + return nil, fmt.Errorf("%s: %w", processors.ErrDatasource, err) + } + defer resp.Body.Close() + + // 检查HTTP状态码 + if resp.StatusCode != http.StatusOK { + return nil, fmt.Errorf("%s: HTTP状态码异常: %d", processors.ErrDatasource, resp.StatusCode) + } + + // 读取响应 + respBody, err := io.ReadAll(resp.Body) + if err != nil { + return nil, fmt.Errorf("%s: %w", processors.ErrSystem, err) + } + + return respBody, nil +}