f
This commit is contained in:
@@ -10,6 +10,20 @@ import (
|
||||
"tyapi-server/internal/infrastructure/external/shumai"
|
||||
)
|
||||
|
||||
// 数脉 H5 活体结果查询中,以下 msg 表示检测不通过但属于正常业务响应,需返回 result=1 并扣费。
|
||||
var ivyzX5Q2BillableFailMsgs = map[string]struct{}{
|
||||
"动作中检测不到人脸": {},
|
||||
"用户拒绝打开摄像头": {},
|
||||
"未检测到人脸": {},
|
||||
}
|
||||
|
||||
type ivyzX5Q2Resp struct {
|
||||
OrderNo string `json:"order_no,omitempty"`
|
||||
Result int `json:"result"`
|
||||
CodeDesc string `json:"codeDesc"`
|
||||
FaceUrl string `json:"faceUrl,omitempty"`
|
||||
}
|
||||
|
||||
// ProcessIVYZX5Q2Request IVYZX5Q2 活体识别步骤二API处理方法
|
||||
func ProcessIVYZX5Q2Request(ctx context.Context, params []byte, deps *processors.ProcessorDependencies) ([]byte, error) {
|
||||
var paramsDto dto.IVYZX5Q2Req
|
||||
@@ -29,6 +43,15 @@ func ProcessIVYZX5Q2Request(ctx context.Context, params []byte, deps *processors
|
||||
apiPath := "/v4/liveness/h5/v4/result" // 接口路径,根据数脉文档填写(如 v4/xxx)
|
||||
respBytes, err := deps.ShumaiService.CallAPIForm(ctx, apiPath, reqFormData)
|
||||
if err != nil {
|
||||
if shumaiErr := shumai.GetShumaiError(err); shumaiErr != nil && shumaiErr.IsParamError() {
|
||||
if _, ok := ivyzX5Q2BillableFailMsgs[shumaiErr.Message]; ok {
|
||||
resp, marshalErr := buildIVYZX5Q2FailResponse(ctx, shumaiErr.Message)
|
||||
if marshalErr != nil {
|
||||
return nil, errors.Join(processors.ErrSystem, marshalErr)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
}
|
||||
if errors.Is(err, shumai.ErrNotFound) {
|
||||
// 查无记录情况
|
||||
return nil, errors.Join(processors.ErrNotFound, err)
|
||||
@@ -55,3 +78,14 @@ func ProcessIVYZX5Q2Request(ctx context.Context, params []byte, deps *processors
|
||||
|
||||
return respBytes, nil
|
||||
}
|
||||
|
||||
func buildIVYZX5Q2FailResponse(ctx context.Context, codeDesc string) ([]byte, error) {
|
||||
resp := ivyzX5Q2Resp{
|
||||
Result: 1,
|
||||
CodeDesc: codeDesc,
|
||||
}
|
||||
if orderNo, ok := ctx.Value("transaction_id").(string); ok && orderNo != "" {
|
||||
resp.OrderNo = orderNo
|
||||
}
|
||||
return json.Marshal(resp)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user