This commit is contained in:
2025-08-18 17:12:47 +08:00
parent a849ebc34f
commit e2e6911c65

View File

@@ -24,6 +24,14 @@ func convertTianyuanResponse(resp *tianyuanapi.Response) ([]byte, error) {
return json.Marshal(resp.Data)
}
// 生成认证时间范围当前时间前后两天的YYYYMMDD-YYMMDD格式
func generateAuthDateRange() string {
now := time.Now()
start := now.AddDate(0, 0, -2).Format("20060102")
end := now.AddDate(0, 0, 2).Format("20060102")
return fmt.Sprintf("%s-%s", start, end)
}
type ApiRequestService struct {
config config.Config
featureModel model.FeatureModel
@@ -205,7 +213,7 @@ func (a *ApiRequestService) ProcessPersonEnterpriseProRequest(params []byte) ([]
return nil, errors.New("api请求, PersonEnterprisePro, 获取相关参数失败")
}
resp, err := a.tianyuanapi.CallInterface("QYGL6F2D", map[string]interface{}{
resp, err := a.tianyuanapi.CallInterface("QYGLB4C0", map[string]interface{}{
"id_card": idCard.String(),
})
if err != nil {
@@ -534,21 +542,15 @@ func (a *ApiRequestService) ProcesFLXG0V4BRequest(params []byte) ([]byte, error)
name := gjson.GetBytes(params, "name")
idCard := gjson.GetBytes(params, "id_card")
mobile := gjson.GetBytes(params, "mobile")
if !name.Exists() || !idCard.Exists() || !mobile.Exists() {
return nil, errors.New("api请求, BehaviorRiskScan, 获取相关参数失败")
if !name.Exists() || !idCard.Exists() {
return nil, errors.New("api请求, FLXG0V4B, 获取相关参数失败")
}
authDate := func() string {
now := time.Now()
start := now.AddDate(0, 0, -2).Format("20060201")
end := now.AddDate(0, 0, 2).Format("20060201")
return fmt.Sprintf("%s-%s", start, end)
}
resp, err := a.tianyuanapi.CallInterface("FLXG0V4B", map[string]interface{}{
"name": name.String(),
"id_card": idCard.String(),
"mobile": mobile.String(),
"auth_date": authDate(),
"auth_date": generateAuthDateRange(),
})
if err != nil {
@@ -561,56 +563,15 @@ func (a *ApiRequestService) ProcesFLXG0V4BRequest(params []byte) ([]byte, error)
return respBytes, nil
}
// ProcessFLXGC9D1Request 黑灰产
func (a *ApiRequestService) ProcessFLXGC9D1Request(params []byte) ([]byte, error) {
name := gjson.GetBytes(params, "name")
idCard := gjson.GetBytes(params, "id_card")
mobile := gjson.GetBytes(params, "mobile")
if !name.Exists() || !idCard.Exists() || !mobile.Exists() {
return nil, errors.New("api请求, FLXGC9D1, 获取相关参数失败")
}
resp, err := a.tianyuanapi.CallInterface("FLXGC9D1", map[string]interface{}{
"name": name.String(),
"id_card": idCard.String(),
"mobile_no": mobile.String(),
})
if err != nil {
return nil, err
}
respBytes, err := convertTianyuanResponse(resp)
if err != nil {
return nil, err
}
flagBlackgraylevel := gjson.GetBytes(respBytes, "flag_blackgraylevel")
if !flagBlackgraylevel.Exists() || flagBlackgraylevel.String() != "1" {
return nil, fmt.Errorf("自然人黑灰产信息查询失败")
}
bglLevel := gjson.GetBytes(respBytes, "bgl_level")
if !bglLevel.Exists() {
return nil, fmt.Errorf("bgl_level 字段不存在")
}
return []byte(bglLevel.Raw), nil
}
// ProcessFLXG0687Request 反诈反赌核验
func (a *ApiRequestService) ProcessFLXG0687Request(params []byte) ([]byte, error) {
name := gjson.GetBytes(params, "name")
idCard := gjson.GetBytes(params, "id_card")
mobile := gjson.GetBytes(params, "mobile")
if !name.Exists() || !idCard.Exists() || !mobile.Exists() {
if !idCard.Exists() {
return nil, errors.New("api请求, FLXG0687, 获取相关参数失败")
}
resp, err := a.tianyuanapi.CallInterface("FLXG0687", map[string]interface{}{
"name": name.String(),
"id_card": idCard.String(),
"mobile_no": mobile.String(),
})
if err != nil {
@@ -654,19 +615,44 @@ func (a *ApiRequestService) ProcessFLXG3D56Request(params []byte) ([]byte, error
return nil, err
}
// 获取 code 字段
if err != nil {
return nil, err
}
respBytes, err := convertTianyuanResponse(resp)
if err != nil {
return nil, err
}
codeResult := gjson.GetBytes(respBytes, "code")
validCodes := map[string]bool{"1006": true, "1007": true, "1008": true, "1009": true, "1010": true}
if !validCodes[codeResult.String()] {
return nil, fmt.Errorf("查询手机在网时长失败, %s", string(respBytes))
if !codeResult.Exists() {
return nil, fmt.Errorf("code 字段不存在")
}
if codeResult.String() != "00" {
return nil, fmt.Errorf("未匹配到相关结果")
}
data := gjson.GetBytes(respBytes, "data")
if !data.Exists() {
return nil, fmt.Errorf("查询手机在网时长失败, %s", string(respBytes))
// 获取 data 字段
dataResult := gjson.GetBytes(respBytes, "data")
if !dataResult.Exists() {
return nil, fmt.Errorf("data 字段不存在")
}
return []byte(data.Raw), nil
// 将 data 字段解析为 map
var dataMap map[string]interface{}
if err := json.Unmarshal([]byte(dataResult.Raw), &dataMap); err != nil {
return nil, fmt.Errorf("解析 data 字段失败: %v", err)
}
// 删除指定字段
delete(dataMap, "swift_number")
delete(dataMap, "DataStrategy")
// 重新编码为 JSON
modifiedData, err := json.Marshal(dataMap)
if err != nil {
return nil, fmt.Errorf("编码修改后的 data 失败: %v", err)
}
return modifiedData, nil
}
// ProcessIVYZ5733Request 婚姻状况
@@ -1069,17 +1055,10 @@ func (a *ApiRequestService) ProcessFLXG0V4BRequest(params []byte) ([]byte, error
return nil, errors.New("api请求, FLXG0V4B, 获取相关参数失败")
}
authDate := func() string {
now := time.Now()
start := now.AddDate(0, 0, -2).Format("20060201")
end := now.AddDate(0, 0, 2).Format("20060201")
return fmt.Sprintf("%s-%s", start, end)
}
resp, err := a.tianyuanapi.CallInterface("FLXG0V4B", map[string]interface{}{
"name": name.String(),
"id_card": idCard.String(),
"auth_date": authDate(),
"auth_date": generateAuthDateRange(),
}, &tianyuanapi.ApiCallOptions{
Json: true,
})
@@ -1208,53 +1187,23 @@ func (a *ApiRequestService) ProcessBehaviorRiskScanRequest(params []byte) ([]byt
data []byte
err error
}
results := make(chan apiResult, 2) // 2个风险检测项
results := make(chan apiResult, 1) // 1个风险检测项
// 并行调用两个不同的风险检测API
wg.Add(2)
wg.Add(1)
// 黑灰产检测
// go func() {
// defer wg.Done()
// respBytes, err := a.ProcessFLXGC9D1Request(params)
// results <- apiResult{name: "black_gray_level", data: respBytes, err: err}
// }()
// 反赌反诈
go func() {
defer wg.Done()
resp, err := a.tianyuanapi.CallInterface("FLXGC9D1", map[string]interface{}{
"name": name.String(),
"id_card": idCard.String(),
"mobile_no": mobile.String(),
})
if err != nil {
results <- apiResult{name: "black_gray_level", data: nil, err: err}
return
}
respBytes, err := convertTianyuanResponse(resp)
if err != nil {
results <- apiResult{name: "black_gray_level", data: nil, err: err}
return
}
results <- apiResult{name: "black_gray_level", data: respBytes, err: nil}
}()
// 电诈风险预警
go func() {
defer wg.Done()
resp, err := a.tianyuanapi.CallInterface("FLXG0687", map[string]interface{}{
"name": name.String(),
"id_card": idCard.String(),
"mobile_no": mobile.String(),
})
if err != nil {
results <- apiResult{name: "telefraud_level", data: nil, err: err}
return
}
respBytes, err := convertTianyuanResponse(resp)
if err != nil {
results <- apiResult{name: "telefraud_level", data: nil, err: err}
return
}
results <- apiResult{name: "telefraud_level", data: respBytes, err: nil}
respBytes, err := a.ProcessFLXG0687Request(params)
results <- apiResult{name: "anti_fraud_gaming", data: respBytes, err: err}
}()
// 关闭结果通道