This commit is contained in:
Mrx
2026-06-02 12:26:22 +08:00
parent aed109d589
commit 6d892643ba
9 changed files with 228 additions and 65 deletions

View File

@@ -1,20 +0,0 @@
{
"scoreywbase": "728"
}
{
"result": {
"score": "40.49"
}
}
{
"result": {
"score": "50.46"
}
}
{
"scoreywbase": "665"
}

View File

@@ -7,10 +7,10 @@ import (
"tyapi-server/internal/domains/api/dto"
"tyapi-server/internal/domains/api/services/processors"
"tyapi-server/internal/infrastructure/external/zhicha"
"tyapi-server/internal/infrastructure/external/nuoer"
)
// ProcessJRZQ3c9RRequest JRZQ3c9R API处理方法 - 支付行为指数
// ProcessJRZQ3c9RRequest JRZQ3C9R API处理方法 - 支付行为指数
func ProcessJRZQ3C9RRequest(ctx context.Context, params []byte, deps *processors.ProcessorDependencies) ([]byte, error) {
var paramsDto dto.JRZQ3C9RReq
if err := json.Unmarshal(params, &paramsDto); err != nil {
@@ -21,42 +21,37 @@ func ProcessJRZQ3C9RRequest(ctx context.Context, params []byte, deps *processors
return nil, errors.Join(processors.ErrInvalidParam, err)
}
encryptedName, err := deps.ZhichaService.Encrypt(paramsDto.Name)
if err != nil {
return nil, errors.Join(processors.ErrSystem, err)
body := map[string]string{
"name": paramsDto.Name,
"idCard": paramsDto.IDCard,
"mobile": paramsDto.MobileNo,
}
encryptedIDCard, err := deps.ZhichaService.Encrypt(paramsDto.IDCard)
if err != nil {
return nil, errors.Join(processors.ErrSystem, err)
}
nuoerDoCheckAPIKey := "paymentTagS26"
ApiPath := "/v1/doCheck"
encryptedMobileNo, err := deps.ZhichaService.Encrypt(paramsDto.MobileNo)
resp, err := deps.NuoerService.CallAPI(ctx, nuoerDoCheckAPIKey, ApiPath, body)
if err != nil {
return nil, errors.Join(processors.ErrSystem, err)
}
reqData := map[string]interface{}{
"name": encryptedName,
"idCard": encryptedIDCard,
"phone": encryptedMobileNo,
"authorized": paramsDto.Authorized,
}
respData, err := deps.ZhichaService.CallAPI(ctx, "ZCI036", reqData)
if err != nil {
if errors.Is(err, zhicha.ErrDatasource) {
if errors.Is(err, nuoer.ErrDatasource) {
return nil, errors.Join(processors.ErrDatasource, err)
} else {
return nil, errors.Join(processors.ErrSystem, err)
}
if errors.Is(err, nuoer.ErrNotFound) {
return nil, errors.Join(processors.ErrNotFound, err)
}
return nil, errors.Join(processors.ErrSystem, err)
}
// 将响应数据转换为JSON字节
respBytes, err := json.Marshal(respData)
// 将响应数据序列化为 JSON
respBytes, err := json.Marshal(resp.Data)
if err != nil {
return nil, errors.Join(processors.ErrSystem, err)
}
return respBytes, nil
// 使用 transform 函数转换响应数据,展开 result 字段
transformedBytes, err := JRZQ3C9RTransformResponseFromBytes(respBytes)
if err != nil {
return nil, errors.Join(processors.ErrSystem, err)
}
return transformedBytes, nil
}

View File

@@ -0,0 +1,20 @@
package jrzq
import (
"github.com/tidwall/gjson"
)
// JRZQ3C9RTransformResponseFromBytes 从字节数组转换响应数据,将 result 字段展开到根级别
// respBytes: 原始响应数据的字节数组
// Returns: 转换后的数据字节数组
func JRZQ3C9RTransformResponseFromBytes(respBytes []byte) ([]byte, error) {
// 使用 gjson 获取 result 字段
resultResult := gjson.GetBytes(respBytes, "result")
if !resultResult.Exists() {
// 如果没有 result 字段,直接返回原始数据
return respBytes, nil
}
// 返回 result 字段的原始 JSON
return []byte(resultResult.Raw), nil
}