f
This commit is contained in:
@@ -1,20 +0,0 @@
|
||||
{
|
||||
"scoreywbase": "728"
|
||||
}
|
||||
{
|
||||
"result": {
|
||||
"score": "40.49"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
{
|
||||
"result": {
|
||||
"score": "50.46"
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
"scoreywbase": "665"
|
||||
}
|
||||
@@ -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, ¶msDto); 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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user