new fieature

This commit is contained in:
liangzai 2025-04-25 02:44:39 +08:00
parent b995855180
commit 594c238a99

View File

@ -1867,11 +1867,42 @@ func (a *ApiRequestService) ProcessG09XM02Request(params []byte) ([]byte, error)
},
}
resp, err := a.westDexService.CallAPI("G09XM02", request)
if err != nil {
if err != nil && resp == nil {
return nil, fmt.Errorf("婚姻状态查询失败: %v", err)
}
// gjson.GetBytes(resp, "maritalStatus")
return resp, nil
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) {
@ -1898,11 +1929,43 @@ func (a *ApiRequestService) ProcessG10XM02Request(params []byte) ([]byte, error)
// 调用 API
resp, callApiErr := a.westDexService.CallAPI("G10XM02", request)
if callApiErr != nil {
if callApiErr != nil && resp == nil {
return nil, callApiErr
}
return resp, nil
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")
@ -1917,10 +1980,58 @@ func (a *ApiRequestService) ProcessG11BJ06Request(params []byte) ([]byte, error)
},
}
resp, err := a.westDexService.CallAPI("G11BJ06", request)
if err != nil {
if err != nil && resp == nil {
return nil, fmt.Errorf("教育经历核验查询失败: %v", err)
}
return resp, nil
// 解析响应
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")