f
This commit is contained in:
@@ -7,7 +7,7 @@ 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"
|
||||
)
|
||||
|
||||
// ProcessIVYZRAX1Request IVYZRAX1 API处理方法 - 融安信用分
|
||||
@@ -21,45 +21,34 @@ func ProcessIVYZRAX1Request(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)
|
||||
// }
|
||||
|
||||
// encryptedIDCard, err := deps.ZhichaService.Encrypt(paramsDto.IDCard)
|
||||
// if err != nil {
|
||||
// return nil, errors.Join(processors.ErrSystem, err)
|
||||
// }
|
||||
// encryptedMoblie, err := deps.ZhichaService.Encrypt(paramsDto.MobileNo)
|
||||
// if err != nil {
|
||||
// return nil, errors.Join(processors.ErrSystem, err)
|
||||
// }
|
||||
|
||||
md5Name := deps.ZhichaService.MD5(paramsDto.Name)
|
||||
md5IDCard := deps.ZhichaService.MD5(paramsDto.IDCard)
|
||||
md5Mobile := deps.ZhichaService.MD5(paramsDto.MobileNo)
|
||||
|
||||
reqData := map[string]interface{}{
|
||||
// "name": encryptedName,
|
||||
// "idCard": encryptedIDCard,
|
||||
// "phone": encryptedMoblie,
|
||||
"authorized": paramsDto.Authorized,
|
||||
"name": md5Name,
|
||||
"idCard": md5IDCard,
|
||||
"phone": md5Mobile,
|
||||
body := map[string]string{
|
||||
"name": paramsDto.Name,
|
||||
"idCard": paramsDto.IDCard,
|
||||
"mobile": paramsDto.MobileNo,
|
||||
}
|
||||
|
||||
respData, err := deps.ZhichaService.CallAPI(ctx, "ZCI084", reqData)
|
||||
nuoerDoCheckAPIKey := "zhiTongModelG"
|
||||
ApiPath := "/v1/doCheck"
|
||||
|
||||
resp, err := deps.NuoerService.CallAPI(ctx, nuoerDoCheckAPIKey, ApiPath, body)
|
||||
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)
|
||||
rawData, ok := resp.Data.(map[string]interface{})
|
||||
if !ok {
|
||||
return processors.MarshalRawResponse(resp.Data)
|
||||
}
|
||||
|
||||
result := mapNuoerZhiTongModelGToIVYZRAX1Response(rawData)
|
||||
|
||||
respBytes, err := json.Marshal(result)
|
||||
if err != nil {
|
||||
return nil, errors.Join(processors.ErrSystem, err)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
package ivyz
|
||||
|
||||
import (
|
||||
"math"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
const (
|
||||
rax1ScoreYwBaseMin = 300
|
||||
rax1ScoreYwBaseMax = 1000
|
||||
rax1ScoreYwBaseIntercept = 984.0
|
||||
rax1ScoreYwBaseSlope = 6.32
|
||||
)
|
||||
|
||||
// mapNuoerZhiTongModelGToIVYZRAX1Response 将 nuoer zhiTongModelG 响应转为 IVYZRAX1 对外结构。
|
||||
// nuoer score 为百分制(0~100,越低越安全),映射为 scoreywbase 千分制(300~1000,越高越安全)。
|
||||
// 同分下 scoreywbase 高于 JRZQ0L85 的 score_120_General。未匹配到数据时返回空对象 {}。
|
||||
func mapNuoerZhiTongModelGToIVYZRAX1Response(data map[string]interface{}) map[string]interface{} {
|
||||
score, ok := extractRax1Score(data)
|
||||
if !ok {
|
||||
return map[string]interface{}{}
|
||||
}
|
||||
return map[string]interface{}{
|
||||
"scoreywbase": mapRax1ScoreToScoreYwBase(score),
|
||||
}
|
||||
}
|
||||
|
||||
func extractRax1Score(data map[string]interface{}) (float64, bool) {
|
||||
if data == nil {
|
||||
return 0, false
|
||||
}
|
||||
payload := data
|
||||
if result, ok := data["result"].(map[string]interface{}); ok {
|
||||
payload = result
|
||||
}
|
||||
return parseRax1Score(payload["score"])
|
||||
}
|
||||
|
||||
func parseRax1Score(v interface{}) (float64, bool) {
|
||||
if v == nil {
|
||||
return 0, false
|
||||
}
|
||||
switch val := v.(type) {
|
||||
case float64:
|
||||
return val, true
|
||||
case int:
|
||||
return float64(val), true
|
||||
case int64:
|
||||
return float64(val), true
|
||||
case string:
|
||||
if val == "" {
|
||||
return 0, false
|
||||
}
|
||||
f, err := strconv.ParseFloat(val, 64)
|
||||
if err != nil {
|
||||
return 0, false
|
||||
}
|
||||
return f, true
|
||||
default:
|
||||
return 0, false
|
||||
}
|
||||
}
|
||||
|
||||
// mapRax1ScoreToScoreYwBase 百分制 score 转千分制 scoreywbase。
|
||||
// 样本标定:40.49→728,50.46→665,即 round(984 - score*6.32),结果钳制到 [300, 1000]。
|
||||
func mapRax1ScoreToScoreYwBase(score float64) string {
|
||||
v := int(math.Round(rax1ScoreYwBaseIntercept - score*rax1ScoreYwBaseSlope))
|
||||
if v < rax1ScoreYwBaseMin {
|
||||
v = rax1ScoreYwBaseMin
|
||||
} else if v > rax1ScoreYwBaseMax {
|
||||
v = rax1ScoreYwBaseMax
|
||||
}
|
||||
return strconv.Itoa(v)
|
||||
}
|
||||
Reference in New Issue
Block a user