feat(main): add mp-weixin

This commit is contained in:
2025-01-18 22:34:27 +08:00
parent 9a31ec15a4
commit 9459d51501
28 changed files with 1580 additions and 71 deletions

View File

@@ -42,6 +42,7 @@ func NewApiRequestService(c config.Config, westDexService *WestDexService, yusha
type APIResponseData struct {
ApiID string `json:"apiID"`
Data json.RawMessage `json:"data"` // 这里用 RawMessage 来存储原始的 data
Sort int64 `json:"sort"`
Success bool `json:"success"`
Timestamp string `json:"timestamp"`
Error string `json:"error,omitempty"`
@@ -59,8 +60,12 @@ func (a *ApiRequestService) ProcessRequests(params []byte, productID int64) ([]b
return nil, findProductFeatureErr
}
var featureIDs []int64
isImportantMap := make(map[int64]int64, len(productFeatureList))
sortMap := make(map[int64]int64, len(productFeatureList)) // 新增
for _, pf := range productFeatureList {
featureIDs = append(featureIDs, pf.FeatureId)
isImportantMap[pf.FeatureId] = pf.IsImportant
sortMap[pf.FeatureId] = pf.Sort // 新增
}
if len(featureIDs) == 0 {
return nil, errors.New("featureIDs 是空的")
@@ -78,7 +83,8 @@ func (a *ApiRequestService) ProcessRequests(params []byte, productID int64) ([]b
resultsCh = make(chan APIResponseData, len(featureList))
errorsCh = make(chan error, len(featureList))
errorCount int32
errorLimit = 1
errorLimit = len(featureList)
retryNum = 5
)
for i, feature := range featureList {
@@ -94,10 +100,28 @@ func (a *ApiRequestService) ProcessRequests(params []byte, productID int64) ([]b
result := APIResponseData{
ApiID: feature.ApiId,
Success: false,
Sort: sortMap[feature.Id],
}
// 请求参数预处理
resp, preprocessErr := a.PreprocessRequestApi(params, feature.ApiId)
timestamp := time.Now().Format("2006-01-02 15:04:05")
var (
resp json.RawMessage
preprocessErr error
)
// 若 isImportantMap[feature.ID] == 1则表示需要在出错时重试
isImportant := isImportantMap[feature.Id] == 1
tryCount := 0
for {
tryCount++
resp, preprocessErr = a.PreprocessRequestApi(params, feature.ApiId)
if preprocessErr == nil {
break
}
if isImportant && tryCount < retryNum {
continue
} else {
break
}
}
if preprocessErr != nil {
result.Timestamp = timestamp
result.Error = preprocessErr.Error()
@@ -166,6 +190,11 @@ var requestProcessors = map[string]func(*ApiRequestService, []byte) ([]byte, err
"G02BJ02": (*ApiRequestService).ProcessG02BJ02Request,
"G19BJ02": (*ApiRequestService).ProcessG19BJ02Request,
"G20GZ01": (*ApiRequestService).ProcessG20GZ01Request,
"CAR074": (*ApiRequestService).ProcessCAR074Request,
"CAR058": (*ApiRequestService).ProcessCAR058Request,
"CAR079": (*ApiRequestService).ProcessCAR079Request,
"CAR066": (*ApiRequestService).ProcessCAR066Request,
"CAR100": (*ApiRequestService).ProcessCAR100Request,
}
// PreprocessRequestApi 调用指定的请求处理函数
@@ -710,6 +739,97 @@ func (a *ApiRequestService) ProcessP_C_B332Request(params []byte) ([]byte, error
return resp, nil
}
// 车辆出险信息
func (a *ApiRequestService) ProcessCAR074Request(params []byte) ([]byte, error) {
vinCode := gjson.GetBytes(params, "vin_code")
if !vinCode.Exists() {
return nil, errors.New("api请求, CAR074, 获取相关参数失败")
}
request := map[string]interface{}{
"vin": vinCode.String(),
}
resp, err := a.yushanService.request("CAR074", request)
if err != nil {
return nil, fmt.Errorf("人车核验查询失败: %+v", err)
}
return resp, nil
}
// 车辆维保记录
func (a *ApiRequestService) ProcessCAR058Request(params []byte) ([]byte, error) {
vinCode := gjson.GetBytes(params, "vin_code")
carType := gjson.GetBytes(params, "car_driving_permit")
if !vinCode.Exists() || !carType.Exists() {
return nil, errors.New("api请求, CAR058, 获取相关参数失败")
}
request := map[string]interface{}{
"vin": vinCode,
"image": carType,
"notifyUrl": "",
}
resp, err := a.yushanService.request("CAR058", request)
if err != nil {
return nil, fmt.Errorf("人车核验查询失败: %+v", err)
}
return resp, nil
}
// 车架号查车
func (a *ApiRequestService) ProcessCAR079Request(params []byte) ([]byte, error) {
vinCode := gjson.GetBytes(params, "vin_code")
if !vinCode.Exists() {
return nil, errors.New("api请求, CAR079, 获取相关参数失败")
}
request := map[string]interface{}{
"vin": vinCode.String(),
}
resp, err := a.yushanService.request("CAR079", request)
if err != nil {
return nil, fmt.Errorf("车架号查车查询失败: %+v", err)
}
return resp, nil
}
// 车辆过户次数
func (a *ApiRequestService) ProcessCAR066Request(params []byte) ([]byte, error) {
vinCode := gjson.GetBytes(params, "vin_code")
if !vinCode.Exists() {
return nil, errors.New("api请求, CAR066, 获取相关参数失败")
}
request := map[string]interface{}{
"vin": vinCode.String(),
}
resp, err := a.yushanService.request("CAR066", request)
if err != nil {
return nil, fmt.Errorf("车辆过户次数查询失败: %+v", err)
}
return resp, nil
}
// 车辆估值
func (a *ApiRequestService) ProcessCAR100Request(params []byte) ([]byte, error) {
vinCode := gjson.GetBytes(params, "vin_code")
carLicense := gjson.GetBytes(params, "car_license")
if !vinCode.Exists() || !carLicense.Exists() {
return nil, errors.New("api请求, CAR100, 获取相关参数失败")
}
request := map[string]interface{}{
"vin": vinCode.String(),
"carNumber": carLicense.String(),
"cardNo": "",
}
resp, err := a.yushanService.request("CAR100", request)
if err != nil {
return nil, fmt.Errorf("车辆估值查询失败: %+v", err)
}
return resp, nil
}
// 银行卡黑名单
func (a *ApiRequestService) ProcessFIN019Request(params []byte) ([]byte, error) {
name := gjson.GetBytes(params, "name")