f
This commit is contained in:
@@ -872,6 +872,11 @@ type YYSYH6D2Req struct {
|
|||||||
MobileNo string `json:"mobile_no" validate:"required,min=11,max=11,validMobileNo"`
|
MobileNo string `json:"mobile_no" validate:"required,min=11,max=11,validMobileNo"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type YYSYH6F3Req struct {
|
||||||
|
IDCard string `json:"id_card" validate:"required,validIDCard"`
|
||||||
|
Name string `json:"name" validate:"required,min=1,validName"`
|
||||||
|
MobileNo string `json:"mobile_no" validate:"required,min=11,max=11,validMobileNo"`
|
||||||
|
}
|
||||||
type YYSYP0T4Req struct {
|
type YYSYP0T4Req struct {
|
||||||
MobileNo string `json:"mobile_no" validate:"required,min=11,max=11,validMobileNo"`
|
MobileNo string `json:"mobile_no" validate:"required,min=11,max=11,validMobileNo"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ func ProcessYYSYH6D2Request(ctx context.Context, params []byte, deps *processors
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 以表单方式调用数脉 API;参数在 CallAPIForm 内转为 application/x-www-form-urlencoded
|
// 以表单方式调用数脉 API;参数在 CallAPIForm 内转为 application/x-www-form-urlencoded
|
||||||
|
deps.ShumaiService.UseGovernment()
|
||||||
apiPath := "/v4/mobile_three/check" // 接口路径,根据数脉文档填写(如 v4/xxx)
|
apiPath := "/v4/mobile_three/check" // 接口路径,根据数脉文档填写(如 v4/xxx)
|
||||||
respBytes, err := deps.ShumaiService.CallAPIForm(ctx, apiPath, reqFormData)
|
respBytes, err := deps.ShumaiService.CallAPIForm(ctx, apiPath, reqFormData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -41,6 +42,5 @@ func ProcessYYSYH6D2Request(ctx context.Context, params []byte, deps *processors
|
|||||||
return nil, errors.Join(processors.ErrSystem, err)
|
return nil, errors.Join(processors.ErrSystem, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return respBytes, nil
|
return respBytes, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package yysy
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"tyapi-server/internal/domains/api/dto"
|
||||||
|
"tyapi-server/internal/domains/api/services/processors"
|
||||||
|
"tyapi-server/internal/infrastructure/external/shumai"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ProcessYYSYH6F3Request YYSYH6F3 运营商三要素政务版API处理方法
|
||||||
|
func ProcessYYSYH6F3Request(ctx context.Context, params []byte, deps *processors.ProcessorDependencies) ([]byte, error) {
|
||||||
|
var paramsDto dto.YYSYH6F3Req
|
||||||
|
if err := json.Unmarshal(params, ¶msDto); err != nil {
|
||||||
|
return nil, errors.Join(processors.ErrSystem, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := deps.Validator.ValidateStruct(paramsDto); err != nil {
|
||||||
|
return nil, errors.Join(processors.ErrInvalidParam, err)
|
||||||
|
}
|
||||||
|
reqFormData := map[string]interface{}{
|
||||||
|
"idcard": paramsDto.IDCard,
|
||||||
|
"name": paramsDto.Name,
|
||||||
|
"mobile": paramsDto.MobileNo,
|
||||||
|
}
|
||||||
|
|
||||||
|
// 以表单方式调用数脉 API;参数在 CallAPIForm 内转为 application/x-www-form-urlencoded
|
||||||
|
// 走政务接口使用这个
|
||||||
|
|
||||||
|
apiPath := "/v4/mobile_three/check" // 接口路径,根据数脉文档填写(如 v4/xxx)
|
||||||
|
respBytes, err := deps.ShumaiService.CallAPIForm(ctx, apiPath, reqFormData)
|
||||||
|
if err != nil {
|
||||||
|
if errors.Is(err, shumai.ErrDatasource) {
|
||||||
|
// 数据源错误
|
||||||
|
return nil, errors.Join(processors.ErrDatasource, err)
|
||||||
|
} else if errors.Is(err, shumai.ErrSystem) {
|
||||||
|
// 系统错误
|
||||||
|
return nil, errors.Join(processors.ErrSystem, err)
|
||||||
|
} else {
|
||||||
|
// 其他未知错误
|
||||||
|
return nil, errors.Join(processors.ErrSystem, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return respBytes, nil
|
||||||
|
}
|
||||||
@@ -160,7 +160,7 @@ func (s *ShumaiService) CallAPIForm(ctx context.Context, apiPath string, reqForm
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Join(ErrSystem, err)
|
err = errors.Join(ErrSystem, err)
|
||||||
if s.logger != nil {
|
if s.logger != nil {
|
||||||
s.logger.LogError(requestID, transactionID, apiPath, err, reqFormData)
|
s.logger.LogError(requestID, transactionID, apiPath, err, nil)
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -188,7 +188,7 @@ func (s *ShumaiService) CallAPIForm(ctx context.Context, apiPath string, reqForm
|
|||||||
err = errors.Join(ErrSystem, err)
|
err = errors.Join(ErrSystem, err)
|
||||||
}
|
}
|
||||||
if s.logger != nil {
|
if s.logger != nil {
|
||||||
s.logger.LogError(requestID, transactionID, apiPath, err, reqFormData)
|
s.logger.LogError(requestID, transactionID, apiPath, err, nil)
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -199,7 +199,7 @@ func (s *ShumaiService) CallAPIForm(ctx context.Context, apiPath string, reqForm
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Join(ErrSystem, err)
|
err = errors.Join(ErrSystem, err)
|
||||||
if s.logger != nil {
|
if s.logger != nil {
|
||||||
s.logger.LogError(requestID, transactionID, apiPath, err, reqFormData)
|
s.logger.LogError(requestID, transactionID, apiPath, err, nil)
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -207,7 +207,21 @@ func (s *ShumaiService) CallAPIForm(ctx context.Context, apiPath string, reqForm
|
|||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
err = errors.Join(ErrDatasource, fmt.Errorf("HTTP %d", resp.StatusCode))
|
err = errors.Join(ErrDatasource, fmt.Errorf("HTTP %d", resp.StatusCode))
|
||||||
if s.logger != nil {
|
if s.logger != nil {
|
||||||
s.logger.LogError(requestID, transactionID, apiPath, err, reqFormData)
|
var errorResponse interface{} = string(raw)
|
||||||
|
// 尝试解析 JSON 获取 msg
|
||||||
|
var tempResp ShumaiResponse
|
||||||
|
if json.Unmarshal(raw, &tempResp) == nil {
|
||||||
|
msg := tempResp.Msg
|
||||||
|
if msg == "" {
|
||||||
|
msg = tempResp.Message
|
||||||
|
}
|
||||||
|
if msg != "" {
|
||||||
|
errorResponse = map[string]interface{}{
|
||||||
|
"msg": msg,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
s.logger.LogError(requestID, transactionID, apiPath, err, errorResponse)
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -220,7 +234,7 @@ func (s *ShumaiService) CallAPIForm(ctx context.Context, apiPath string, reqForm
|
|||||||
if err := json.Unmarshal(raw, &shumaiResp); err != nil {
|
if err := json.Unmarshal(raw, &shumaiResp); err != nil {
|
||||||
err = errors.Join(ErrSystem, fmt.Errorf("响应解析失败: %w", err))
|
err = errors.Join(ErrSystem, fmt.Errorf("响应解析失败: %w", err))
|
||||||
if s.logger != nil {
|
if s.logger != nil {
|
||||||
s.logger.LogError(requestID, transactionID, apiPath, err, reqFormData)
|
s.logger.LogError(requestID, transactionID, apiPath, err, string(raw))
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -237,7 +251,10 @@ func (s *ShumaiService) CallAPIForm(ctx context.Context, apiPath string, reqForm
|
|||||||
shumaiErr = NewShumaiError(codeStr, msg)
|
shumaiErr = NewShumaiError(codeStr, msg)
|
||||||
}
|
}
|
||||||
if s.logger != nil {
|
if s.logger != nil {
|
||||||
s.logger.LogError(requestID, transactionID, apiPath, shumaiErr, reqFormData)
|
errorResponse := map[string]interface{}{
|
||||||
|
"msg": msg,
|
||||||
|
}
|
||||||
|
s.logger.LogError(requestID, transactionID, apiPath, shumaiErr, errorResponse)
|
||||||
}
|
}
|
||||||
if shumaiErr.IsNoRecord() {
|
if shumaiErr.IsNoRecord() {
|
||||||
return nil, errors.Join(ErrNotFound, shumaiErr)
|
return nil, errors.Join(ErrNotFound, shumaiErr)
|
||||||
@@ -253,7 +270,10 @@ func (s *ShumaiService) CallAPIForm(ctx context.Context, apiPath string, reqForm
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Join(ErrSystem, fmt.Errorf("data 序列化失败: %w", err))
|
err = errors.Join(ErrSystem, fmt.Errorf("data 序列化失败: %w", err))
|
||||||
if s.logger != nil {
|
if s.logger != nil {
|
||||||
s.logger.LogError(requestID, transactionID, apiPath, err, reqFormData)
|
errorResponse := map[string]interface{}{
|
||||||
|
"msg": msg,
|
||||||
|
}
|
||||||
|
s.logger.LogError(requestID, transactionID, apiPath, err, errorResponse)
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user