f
This commit is contained in:
@@ -4,6 +4,8 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"tyapi-server/internal/domains/api/dto"
|
"tyapi-server/internal/domains/api/dto"
|
||||||
"tyapi-server/internal/domains/api/services/processors"
|
"tyapi-server/internal/domains/api/services/processors"
|
||||||
@@ -47,7 +49,7 @@ func ProcessYYSYBE08Request(ctx context.Context, params []byte, deps *processors
|
|||||||
return nil, errors.Join(processors.ErrSystem, aerr)
|
return nil, errors.Join(processors.ErrSystem, aerr)
|
||||||
}
|
}
|
||||||
var aliyunData struct {
|
var aliyunData struct {
|
||||||
Result *int `json:"result"`
|
Result interface{} `json:"result"`
|
||||||
Desc string `json:"desc"`
|
Desc string `json:"desc"`
|
||||||
}
|
}
|
||||||
if err := json.Unmarshal(dataBytes, &aliyunData); err != nil {
|
if err := json.Unmarshal(dataBytes, &aliyunData); err != nil {
|
||||||
@@ -65,23 +67,7 @@ func ProcessYYSYBE08Request(ctx context.Context, params []byte, deps *processors
|
|||||||
return json.Marshal(errorResponse)
|
return json.Marshal(errorResponse)
|
||||||
}
|
}
|
||||||
|
|
||||||
var resultCode, verifyResult, resultMsg string
|
resultCode, verifyResult, resultMsg := mapIDCardCheckResult(aliyunData.Result, aliyunData.Desc)
|
||||||
switch {
|
|
||||||
case aliyunData.Result != nil && *aliyunData.Result == 0:
|
|
||||||
resultCode = "0XXX"
|
|
||||||
verifyResult = "一致"
|
|
||||||
resultMsg = aliyunData.Desc
|
|
||||||
if resultMsg == "" {
|
|
||||||
resultMsg = "成功"
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
resultCode = "5XXX"
|
|
||||||
verifyResult = "不一致"
|
|
||||||
resultMsg = aliyunData.Desc
|
|
||||||
if resultMsg == "" {
|
|
||||||
resultMsg = "不一致"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
response := map[string]interface{}{
|
response := map[string]interface{}{
|
||||||
"ctidRequest": map[string]interface{}{
|
"ctidRequest": map[string]interface{}{
|
||||||
@@ -101,7 +87,7 @@ func ProcessYYSYBE08Request(ctx context.Context, params []byte, deps *processors
|
|||||||
// 解析数脉 /v4/id_card/check 的 data 内容(CallAPIForm 返回的即 data 对象)
|
// 解析数脉 /v4/id_card/check 的 data 内容(CallAPIForm 返回的即 data 对象)
|
||||||
// 数卖响应: result 0-一致 1-不一致 2-无记录(预留); desc 如 "一致"/"不一致"
|
// 数卖响应: result 0-一致 1-不一致 2-无记录(预留); desc 如 "一致"/"不一致"
|
||||||
var shumaiData struct {
|
var shumaiData struct {
|
||||||
Result *int `json:"result"`
|
Result interface{} `json:"result"`
|
||||||
OrderNo string `json:"order_no"`
|
OrderNo string `json:"order_no"`
|
||||||
Desc string `json:"desc"`
|
Desc string `json:"desc"`
|
||||||
Sex string `json:"sex"`
|
Sex string `json:"sex"`
|
||||||
@@ -127,23 +113,7 @@ func ProcessYYSYBE08Request(ctx context.Context, params []byte, deps *processors
|
|||||||
|
|
||||||
// 按数卖 result 验证结果处理: 0-一致 1-不一致 2-无记录(预留)
|
// 按数卖 result 验证结果处理: 0-一致 1-不一致 2-无记录(预留)
|
||||||
// resultCode: 0XXX=一致, 5XXX=不一致/无记录
|
// resultCode: 0XXX=一致, 5XXX=不一致/无记录
|
||||||
var resultCode, verifyResult, resultMsg string
|
resultCode, verifyResult, resultMsg := mapIDCardCheckResult(shumaiData.Result, shumaiData.Desc)
|
||||||
switch {
|
|
||||||
case shumaiData.Result != nil && *shumaiData.Result == 0: // 一致(收费)
|
|
||||||
resultCode = "0XXX"
|
|
||||||
verifyResult = "一致"
|
|
||||||
resultMsg = shumaiData.Desc
|
|
||||||
if resultMsg == "" {
|
|
||||||
resultMsg = "成功"
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
resultCode = "5XXX"
|
|
||||||
verifyResult = "不一致"
|
|
||||||
resultMsg = shumaiData.Desc
|
|
||||||
if resultMsg == "" {
|
|
||||||
resultMsg = "不一致"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 构建目标格式的响应
|
// 构建目标格式的响应
|
||||||
response := map[string]interface{}{
|
response := map[string]interface{}{
|
||||||
@@ -160,3 +130,48 @@ func ProcessYYSYBE08Request(ctx context.Context, params []byte, deps *processors
|
|||||||
|
|
||||||
return json.Marshal(response)
|
return json.Marshal(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func mapIDCardCheckResult(rawResult interface{}, desc string) (resultCode, verifyResult, resultMsg string) {
|
||||||
|
if isResultZero(rawResult) {
|
||||||
|
resultCode = "0XXX"
|
||||||
|
verifyResult = "一致"
|
||||||
|
resultMsg = desc
|
||||||
|
if resultMsg == "" {
|
||||||
|
resultMsg = "成功"
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
resultCode = "5XXX"
|
||||||
|
verifyResult = "不一致"
|
||||||
|
resultMsg = desc
|
||||||
|
if resultMsg == "" {
|
||||||
|
resultMsg = "不一致"
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func isResultZero(v interface{}) bool {
|
||||||
|
switch r := v.(type) {
|
||||||
|
case float64:
|
||||||
|
return r == 0
|
||||||
|
case int:
|
||||||
|
return r == 0
|
||||||
|
case int32:
|
||||||
|
return r == 0
|
||||||
|
case int64:
|
||||||
|
return r == 0
|
||||||
|
case json.Number:
|
||||||
|
n, err := r.Int64()
|
||||||
|
return err == nil && n == 0
|
||||||
|
case string:
|
||||||
|
s := strings.TrimSpace(r)
|
||||||
|
if s == "" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
n, err := strconv.ParseFloat(s, 64)
|
||||||
|
return err == nil && n == 0
|
||||||
|
default:
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -26,30 +26,14 @@ func ProcessYYSYBE08testRequest(ctx context.Context, params []byte, deps *proces
|
|||||||
}
|
}
|
||||||
|
|
||||||
var aliyunData struct {
|
var aliyunData struct {
|
||||||
Result *int `json:"result"`
|
Result interface{} `json:"result"`
|
||||||
Desc string `json:"desc"`
|
Desc string `json:"desc"`
|
||||||
}
|
}
|
||||||
if err := json.Unmarshal(respBytes, &aliyunData); err != nil {
|
if err := json.Unmarshal(respBytes, &aliyunData); err != nil {
|
||||||
return nil, errors.Join(processors.ErrSystem, err)
|
return nil, errors.Join(processors.ErrSystem, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var resultCode, verifyResult, resultMsg string
|
resultCode, verifyResult, resultMsg := mapIDCardCheckResult(aliyunData.Result, aliyunData.Desc)
|
||||||
switch {
|
|
||||||
case aliyunData.Result != nil && *aliyunData.Result == 0:
|
|
||||||
resultCode = "0XXX"
|
|
||||||
verifyResult = "一致"
|
|
||||||
resultMsg = aliyunData.Desc
|
|
||||||
if resultMsg == "" {
|
|
||||||
resultMsg = "成功"
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
resultCode = "5XXX"
|
|
||||||
verifyResult = "不一致"
|
|
||||||
resultMsg = aliyunData.Desc
|
|
||||||
if resultMsg == "" {
|
|
||||||
resultMsg = "不一致"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
response := map[string]interface{}{
|
response := map[string]interface{}{
|
||||||
"ctidRequest": map[string]interface{}{
|
"ctidRequest": map[string]interface{}{
|
||||||
|
|||||||
@@ -97,8 +97,7 @@ func (a *AlicloudService) CallAPI(path string, params map[string]interface{}) (r
|
|||||||
isTimeout := false
|
isTimeout := false
|
||||||
if netErr, ok := err.(interface{ Timeout() bool }); ok && netErr.Timeout() {
|
if netErr, ok := err.(interface{ Timeout() bool }); ok && netErr.Timeout() {
|
||||||
isTimeout = true
|
isTimeout = true
|
||||||
} else if errStr := err.Error();
|
} else if errStr := err.Error(); errStr == "context deadline exceeded" ||
|
||||||
errStr == "context deadline exceeded" ||
|
|
||||||
errStr == "timeout" ||
|
errStr == "timeout" ||
|
||||||
errStr == "Client.Timeout exceeded" ||
|
errStr == "Client.Timeout exceeded" ||
|
||||||
errStr == "net/http: request canceled" {
|
errStr == "net/http: request canceled" {
|
||||||
|
|||||||
Reference in New Issue
Block a user