new feature

This commit is contained in:
2025-04-24 18:28:24 +08:00
parent 25e60c48b9
commit 7b6d7fcb50
3 changed files with 226 additions and 66 deletions

View File

@@ -206,6 +206,10 @@ var requestProcessors = map[string]func(*ApiRequestService, []byte) ([]byte, err
"G31BJ05": (*ApiRequestService).ProcessG31BJ05Request,
"G32BJ05": (*ApiRequestService).ProcessG32BJ05Request,
"RIS031": (*ApiRequestService).ProcessRIS031Request,
"G09XM02": (*ApiRequestService).ProcessG09XM02Request,
"G10XM02": (*ApiRequestService).ProcessG10XM02Request,
"G11BJ06": (*ApiRequestService).ProcessG11BJ06Request,
"G29BJ05": (*ApiRequestService).ProcessG29BJ05Request,
}
// PreprocessRequestApi 调用指定的请求处理函数
@@ -1624,7 +1628,7 @@ func (a *ApiRequestService) ProcessBehaviorRiskScanRequest(params []byte) ([]byt
results := make(chan apiResult, 5) // 5个风险检测项
// 并行调用五个不同的风险检测API
wg.Add(4)
wg.Add(5)
// 黑灰产检测
go func() {
@@ -1850,3 +1854,224 @@ func (a *ApiRequestService) ProcessRIS031Request(params []byte) ([]byte, error)
return []byte(Value.Raw), nil
}
func (a *ApiRequestService) ProcessG09XM02Request(params []byte) ([]byte, error) {
idCard := gjson.GetBytes(params, "id_card")
name := gjson.GetBytes(params, "name")
if !idCard.Exists() || !name.Exists() {
return nil, errors.New("api请求, G09XM02, 获取相关参数失败")
}
request := map[string]interface{}{
"data": map[string]interface{}{
"idCard": a.westDexService.Encrypt(idCard.String()),
"name": a.westDexService.Encrypt(name.String()),
},
}
resp, err := a.westDexService.CallAPI("G09XM02", request)
if err != nil && resp == nil {
return nil, fmt.Errorf("婚姻状态查询失败: %v", err)
}
result := gjson.GetBytes(resp, "data.data")
if !result.Exists() {
return nil, fmt.Errorf("婚姻状态查询失败")
}
// 获取原始结果
rawResult := result.String()
// 根据结果转换状态码
var statusCode string
switch {
case strings.HasPrefix(rawResult, "INR"):
statusCode = "0" // 匹配不成功
case strings.HasPrefix(rawResult, "IA"):
statusCode = "1" // 结婚
case strings.HasPrefix(rawResult, "IB"):
statusCode = "2" // 离婚
default:
return nil, fmt.Errorf("婚姻状态查询失败,未知状态码: %s", statusCode)
}
// 构建新的返回结果
response := map[string]string{
"status": statusCode,
}
// 序列化为JSON
jsonResponse, err := json.Marshal(response)
if err != nil {
return nil, fmt.Errorf("序列化结果失败: %v", err)
}
return jsonResponse, nil
}
func (a *ApiRequestService) ProcessG10XM02Request(params []byte) ([]byte, error) {
// 提取男方和女方信息
nameMan := gjson.GetBytes(params, "nameMan")
idCardMan := gjson.GetBytes(params, "idCardMan")
nameWoman := gjson.GetBytes(params, "nameWoman")
idCardWoman := gjson.GetBytes(params, "idCardWoman")
// 校验是否存在必要参数
if !nameMan.Exists() || !idCardMan.Exists() || !nameWoman.Exists() || !idCardWoman.Exists() {
return nil, errors.New("请求参数缺失:需要提供男方和女方的姓名及身份证号")
}
// 构造请求数据
request := map[string]interface{}{
"data": map[string]interface{}{
"idCardMan": a.westDexService.Encrypt(idCardMan.String()),
"nameMan": a.westDexService.Encrypt(nameMan.String()),
"idCardWoman": a.westDexService.Encrypt(idCardWoman.String()),
"nameWoman": a.westDexService.Encrypt(nameWoman.String()),
},
}
// 调用 API
resp, callApiErr := a.westDexService.CallAPI("G10XM02", request)
if callApiErr != nil && resp == nil {
return nil, callApiErr
}
result := gjson.GetBytes(resp, "data.data")
if !result.Exists() {
return nil, fmt.Errorf("婚姻状态查询失败")
}
// 获取原始结果
rawResult := result.String()
// 根据结果转换状态码
var statusCode string
switch {
case strings.HasPrefix(rawResult, "INR"):
statusCode = "0" // 匹配不成功
case strings.HasPrefix(rawResult, "IA"):
statusCode = "1" // 结婚
case strings.HasPrefix(rawResult, "IB"):
statusCode = "2" // 离婚
default:
return nil, fmt.Errorf("婚姻状态查询失败,未知状态码: %s", statusCode)
}
// 构建新的返回结果
response := map[string]string{
"status": statusCode,
}
// 序列化为JSON
jsonResponse, err := json.Marshal(response)
if err != nil {
return nil, fmt.Errorf("序列化结果失败: %v", err)
}
return jsonResponse, nil
}
func (a *ApiRequestService) ProcessG11BJ06Request(params []byte) ([]byte, error) {
idCard := gjson.GetBytes(params, "id_card")
name := gjson.GetBytes(params, "name")
if !idCard.Exists() || !name.Exists() {
return nil, errors.New("api请求, G11BJ06, 获取相关参数失败")
}
request := map[string]interface{}{
"data": map[string]interface{}{
"id_card_value": a.westDexService.Encrypt(idCard.String()),
"name_value": a.westDexService.Encrypt(name.String()),
},
}
resp, err := a.westDexService.CallAPI("G11BJ06", request)
if err != nil && resp == nil {
return nil, fmt.Errorf("教育经历核验查询失败: %v", err)
}
// 解析响应
codeResult := gjson.GetBytes(resp, "data.education_background.code")
if !codeResult.Exists() {
return nil, fmt.Errorf("教育经历核验查询失败: 返回数据缺少code字段")
}
code := codeResult.String()
var result map[string]interface{}
switch code {
case "9100":
// 查询成功有结果
eduResultArray := gjson.GetBytes(resp, "data.education_background.data").Array()
var processedEduData []interface{}
// 提取每个元素中Raw字段的实际内容
for _, item := range eduResultArray {
var eduInfo interface{}
if err := json.Unmarshal([]byte(item.Raw), &eduInfo); err != nil {
return nil, fmt.Errorf("解析教育信息失败: %v", err)
}
processedEduData = append(processedEduData, eduInfo)
}
result = map[string]interface{}{
"data": processedEduData,
"status": 1,
}
case "9000":
// 查询成功无结果
result = map[string]interface{}{
"data": []interface{}{},
"status": 0,
}
default:
// 其他情况视为错误
errMsg := gjson.GetBytes(resp, "data.education_background.msg").String()
return nil, fmt.Errorf("教育经历核验查询失败: %s (code: %s)", errMsg, code)
}
// 将结果转为JSON字节
jsonResult, err := json.Marshal(result)
if err != nil {
return nil, fmt.Errorf("处理教育经历查询结果失败: %v", err)
}
return jsonResult, nil
}
func (a *ApiRequestService) ProcessG29BJ05Request(params []byte) ([]byte, error) {
idCard := gjson.GetBytes(params, "id_card")
name := gjson.GetBytes(params, "name")
mobile := gjson.GetBytes(params, "mobile")
if !idCard.Exists() || !name.Exists() || !mobile.Exists() {
return nil, errors.New("api请求, G29BJ05, 获取相关参数失败")
}
request := map[string]interface{}{
"data": map[string]interface{}{
"id": a.westDexService.Encrypt(idCard.String()),
"name": a.westDexService.Encrypt(name.String()),
"cell": a.westDexService.Encrypt(mobile.String()),
},
}
resp, err := a.westDexService.CallAPI("G29BJ05", request)
if err != nil && resp == nil {
return nil, fmt.Errorf("偿贷压力查询失败: %v", err)
}
// 获取响应码和偿贷压力标志
code := gjson.GetBytes(resp, "code").String()
flagDebtRepayStress := gjson.GetBytes(resp, "flag_debtrepaystress").String()
// 判断是否成功
if code != "00" || flagDebtRepayStress != "1" {
return nil, fmt.Errorf("偿贷压力查询失败: %+v", resp)
}
// 获取偿贷压力分数
drsNoDebtScore := gjson.GetBytes(resp, "drs_nodebtscore").String()
// 构建结果
result := map[string]interface{}{
"score": drsNoDebtScore,
}
// 将结果转为JSON
jsonResult, err := json.Marshal(result)
if err != nil {
return nil, fmt.Errorf("处理偿贷压力查询结果失败: %v", err)
}
return jsonResult, nil
}