diff --git a/config.yaml b/config.yaml index 57cf45a..87ac3ab 100644 --- a/config.yaml +++ b/config.yaml @@ -62,7 +62,7 @@ jwt: refresh_expires_in: 168h api: - domain: "apitest.tianyuanapi.com" + domain: "api.tianyuanapi.com" sms: access_key_id: "LTAI5tKGB3TVJbMHSoZN3yr9" diff --git a/configs/env.production.yaml b/configs/env.production.yaml index f2ecd28..c256ea6 100644 --- a/configs/env.production.yaml +++ b/configs/env.production.yaml @@ -98,7 +98,7 @@ jwt: secret: JwT8xR4mN9vP2sL7kH3oB6yC1zA5uF0qE9tW api: - domain: "apitest.tianyuanapi.com" + domain: "api.tianyuanapi.com" # =========================================== # 📁 存储服务配置 - 七牛云 # =========================================== diff --git a/internal/domains/api/services/processors/flxg/flxg0v4b_processor.go b/internal/domains/api/services/processors/flxg/flxg0v4b_processor.go index 62b4b11..c47cfec 100644 --- a/internal/domains/api/services/processors/flxg/flxg0v4b_processor.go +++ b/internal/domains/api/services/processors/flxg/flxg0v4b_processor.go @@ -33,6 +33,9 @@ func ProcessFLXG0V4BRequest(ctx context.Context, params []byte, deps *processors if err != nil { return nil, fmt.Errorf("%s: %w", processors.ErrSystem, err) } + if deps.CallContext.ContractCode == "" { + return nil, fmt.Errorf("%s: %w", processors.ErrSystem, errors.New("合同编号不能为空")) + } encryptedAuthAuthorizeFileCode, err := deps.WestDexService.Encrypt(deps.CallContext.ContractCode) if err != nil { return nil, fmt.Errorf("%s: %w", processors.ErrSystem, err) diff --git a/internal/domains/api/services/processors/flxg/flxg5b2e_processor.go b/internal/domains/api/services/processors/flxg/flxg5b2e_processor.go index 1c2a428..1b5a10f 100644 --- a/internal/domains/api/services/processors/flxg/flxg5b2e_processor.go +++ b/internal/domains/api/services/processors/flxg/flxg5b2e_processor.go @@ -9,6 +9,8 @@ import ( "tyapi-server/internal/domains/api/dto" "tyapi-server/internal/domains/api/services/processors" "tyapi-server/internal/infrastructure/external/westdex" + + "github.com/tidwall/gjson" ) // ProcessFLXG5B2ERequest FLXG5B2E API处理方法 @@ -31,21 +33,56 @@ func ProcessFLXG5B2ERequest(ctx context.Context, params []byte, deps *processors if err != nil { return nil, fmt.Errorf("%s: %w", processors.ErrSystem, err) } + if deps.CallContext.ContractCode == "" { + return nil, fmt.Errorf("%s: %w", processors.ErrSystem, errors.New("合同编号不能为空")) + } + encryptedAuthAuthorizeFileCode, err := deps.WestDexService.Encrypt(deps.CallContext.ContractCode) + if err != nil { + return nil, fmt.Errorf("%s: %w", processors.ErrSystem, err) + } reqData := map[string]interface{}{ "data": map[string]interface{}{ - "name": encryptedName, - "idcard": encryptedIDCard, + "name": encryptedName, + "idcard": encryptedIDCard, + "auth_authorizeFileCode": encryptedAuthAuthorizeFileCode, }, } respBytes, err := deps.WestDexService.CallAPI("G36SC01", reqData) if err != nil { if errors.Is(err, westdex.ErrDatasource) { + // 如果有返回内容,优先解析返回内容 + if respBytes != nil { + parsed, parseErr := ParseJsonResponse(respBytes) + if parseErr == nil { + // 通过gjson获取指定路径的数据 + contentResult := gjson.GetBytes(parsed, "G36SC0101.G36SC0102.content") + if contentResult.Exists() { + return []byte(contentResult.Raw), fmt.Errorf("%s: %w", processors.ErrDatasource, err) + } + return parsed, fmt.Errorf("%s: %w", processors.ErrDatasource, err) + } + // 解析失败,返回原始内容和系统错误 + return respBytes, fmt.Errorf("%s: %w", processors.ErrSystem, parseErr) + } + // 没有返回内容,直接返回数据源错误 return nil, fmt.Errorf("%s: %w", processors.ErrDatasource, err) } else { return nil, fmt.Errorf("%s: %w", processors.ErrSystem, err) } } - return respBytes, nil -} \ No newline at end of file + // 正常返回 - 不管有没有deps.Options.Json都进行ParseJsonResponse + parsed, parseErr := ParseJsonResponse(respBytes) + if parseErr != nil { + return nil, fmt.Errorf("%s: %w", processors.ErrSystem, parseErr) + } + + // 通过gjson获取指定路径的数据 + contentResult := gjson.GetBytes(parsed, "G36SC0101.G36SC0102.content") + if contentResult.Exists() { + return []byte(contentResult.Raw), nil + } else { + return nil, fmt.Errorf("%s: %w", processors.ErrDatasource, err) + } +} diff --git a/internal/domains/api/services/processors/flxg/flxg8a3f_processor.go b/internal/domains/api/services/processors/flxg/flxg8a3f_processor.go index d4ae650..6f8afe5 100644 --- a/internal/domains/api/services/processors/flxg/flxg8a3f_processor.go +++ b/internal/domains/api/services/processors/flxg/flxg8a3f_processor.go @@ -9,6 +9,8 @@ import ( "tyapi-server/internal/domains/api/dto" "tyapi-server/internal/domains/api/services/processors" "tyapi-server/internal/infrastructure/external/westdex" + + "github.com/tidwall/gjson" ) // ProcessFLXG8A3FRequest FLXG8A3F API处理方法 @@ -31,22 +33,55 @@ func ProcessFLXG8A3FRequest(ctx context.Context, params []byte, deps *processors if err != nil { return nil, fmt.Errorf("%s: %w", processors.ErrSystem, err) } - + if deps.CallContext.ContractCode == "" { + return nil, fmt.Errorf("%s: %w", processors.ErrSystem, errors.New("合同编号不能为空")) + } + encryptedAuthAuthorizeFileCode, err := deps.WestDexService.Encrypt(deps.CallContext.ContractCode) + if err != nil { + return nil, fmt.Errorf("%s: %w", processors.ErrSystem, err) + } reqData := map[string]interface{}{ "data": map[string]interface{}{ - "name": encryptedName, - "idcard": encryptedIDCard, + "name": encryptedName, + "idcard": encryptedIDCard, + "auth_authorizeFileCode": encryptedAuthAuthorizeFileCode, }, } respBytes, err := deps.WestDexService.CallAPI("G37SC01", reqData) if err != nil { if errors.Is(err, westdex.ErrDatasource) { + // 如果有返回内容,优先解析返回内容 + if respBytes != nil { + parsed, parseErr := ParseJsonResponse(respBytes) + if parseErr == nil { + // 通过gjson获取指定路径的数据 + contentResult := gjson.GetBytes(parsed, "G37SC0101.G37SC0102.content") + if contentResult.Exists() { + return []byte(contentResult.Raw), fmt.Errorf("%s: %w", processors.ErrDatasource, err) + } + return parsed, fmt.Errorf("%s: %w", processors.ErrDatasource, err) + } + // 解析失败,返回原始内容和系统错误 + return respBytes, fmt.Errorf("%s: %w", processors.ErrSystem, parseErr) + } + // 没有返回内容,直接返回数据源错误 return nil, fmt.Errorf("%s: %w", processors.ErrDatasource, err) } else { return nil, fmt.Errorf("%s: %w", processors.ErrSystem, err) } } + // 正常返回 - 不管有没有deps.Options.Json都进行ParseJsonResponse + parsed, parseErr := ParseJsonResponse(respBytes) + if parseErr != nil { + return nil, fmt.Errorf("%s: %w", processors.ErrSystem, parseErr) + } - return respBytes, nil + // 通过gjson获取指定路径的数据 + contentResult := gjson.GetBytes(parsed, "G37SC0101.G37SC0102.content") + if contentResult.Exists() { + return []byte(contentResult.Raw), nil + } else { + return nil, fmt.Errorf("%s: %w", processors.ErrDatasource, err) + } } diff --git a/internal/domains/api/services/processors/qygl/qygl8271_processor.go b/internal/domains/api/services/processors/qygl/qygl8271_processor.go index 4981634..267e456 100644 --- a/internal/domains/api/services/processors/qygl/qygl8271_processor.go +++ b/internal/domains/api/services/processors/qygl/qygl8271_processor.go @@ -33,6 +33,9 @@ func ProcessQYGL8271Request(ctx context.Context, params []byte, deps *processors if err != nil { return nil, fmt.Errorf("%s: %w", processors.ErrSystem, err) } + if deps.CallContext.ContractCode == "" { + return nil, fmt.Errorf("%s: %w", processors.ErrSystem, errors.New("合同编号不能为空")) + } encryptedAuthAuthorizeFileCode, err := deps.WestDexService.Encrypt(deps.CallContext.ContractCode) if err != nil { return nil, fmt.Errorf("%s: %w", processors.ErrSystem, err)