From f1b075d77dbe39e3c829d77605324e8a5d4800df Mon Sep 17 00:00:00 2001 From: liangzai <2440983361@qq.com> Date: Mon, 9 Feb 2026 15:12:43 +0800 Subject: [PATCH] f --- .../api/internal/service/apirequestService.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/app/main/api/internal/service/apirequestService.go b/app/main/api/internal/service/apirequestService.go index 5009d0f..f5c1f28 100644 --- a/app/main/api/internal/service/apirequestService.go +++ b/app/main/api/internal/service/apirequestService.go @@ -1662,7 +1662,7 @@ func (a *ApiRequestService) ProcessCOMBCZGRRequest(params []byte) ([]byte, error return a.comboResponseToAPIResponseData(resp) } -// ProcessCOMBCZDQRequest 组合包 COMBCZDQ:一次请求返回多个模块数据。必传 name, mobile_no, authorization_url, authorized, id_card +// ProcessCOMBCZDQRequest 组合包 COMBCZDQ:一次请求返回多个模块数据。必传 name, mobile_no, authorization_url, id_card;authorized 可选,默认 "1" func (a *ApiRequestService) ProcessCOMBCZDQRequest(params []byte) ([]byte, error) { name := gjson.GetBytes(params, "name") mobileNo := gjson.GetBytes(params, "mobile_no") @@ -1670,18 +1670,17 @@ func (a *ApiRequestService) ProcessCOMBCZDQRequest(params []byte) ([]byte, error mobileNo = gjson.GetBytes(params, "mobile") } authorizationURL := gjson.GetBytes(params, "authorization_url") - authorized := gjson.GetBytes(params, "authorized") idCard := gjson.GetBytes(params, "id_card") if !name.Exists() || !mobileNo.Exists() || !authorizationURL.Exists() || authorizationURL.String() == "" || - !authorized.Exists() || authorized.String() == "" || !idCard.Exists() { - return nil, errors.New("api请求, COMBCZDQ, 缺少必填参数: name / mobile_no(mobile) / authorization_url / authorized / id_card") + !idCard.Exists() { + return nil, errors.New("api请求, COMBCZDQ, 缺少必填参数: name / mobile_no(mobile) / authorization_url / id_card") } reqParams := map[string]interface{}{ "name": name.String(), "mobile_no": mobileNo.String(), "authorization_url": authorizationURL.String(), - "authorized": authorized.String(), + "authorized": "1", "id_card": idCard.String(), } @@ -1722,10 +1721,20 @@ func (a *ApiRequestService) ProcessCOMBCZQYRequest(params []byte) ([]byte, error // comboResponseToAPIResponseData 将组合包接口解密后的 Data 转为 []APIResponseData 并返回 JSON func (a *ApiRequestService) comboResponseToAPIResponseData(resp *tianyuanapi.Response) ([]byte, error) { + if resp == nil { + return nil, fmt.Errorf("组合包响应为空") + } dataBytes, err := json.Marshal(resp.Data) if err != nil { return nil, fmt.Errorf("组合包响应序列化失败: %w", err) } + if len(dataBytes) == 0 || string(dataBytes) == "null" { + return nil, fmt.Errorf("组合包响应 Data 为空,无法解析") + } + // 若上游返回空字符串等导致非对象,无法解析为 ComboPackageResponse + if len(dataBytes) >= 1 && (dataBytes[0] != '[' && dataBytes[0] != '{') { + return nil, fmt.Errorf("组合包响应格式无效: %s", string(dataBytes)) + } var combo ComboPackageResponse if err := json.Unmarshal(dataBytes, &combo); err != nil { return nil, fmt.Errorf("组合包响应解析失败: %w", err)