f
This commit is contained in:
@@ -1662,7 +1662,7 @@ func (a *ApiRequestService) ProcessCOMBCZGRRequest(params []byte) ([]byte, error
|
|||||||
return a.comboResponseToAPIResponseData(resp)
|
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) {
|
func (a *ApiRequestService) ProcessCOMBCZDQRequest(params []byte) ([]byte, error) {
|
||||||
name := gjson.GetBytes(params, "name")
|
name := gjson.GetBytes(params, "name")
|
||||||
mobileNo := gjson.GetBytes(params, "mobile_no")
|
mobileNo := gjson.GetBytes(params, "mobile_no")
|
||||||
@@ -1670,18 +1670,17 @@ func (a *ApiRequestService) ProcessCOMBCZDQRequest(params []byte) ([]byte, error
|
|||||||
mobileNo = gjson.GetBytes(params, "mobile")
|
mobileNo = gjson.GetBytes(params, "mobile")
|
||||||
}
|
}
|
||||||
authorizationURL := gjson.GetBytes(params, "authorization_url")
|
authorizationURL := gjson.GetBytes(params, "authorization_url")
|
||||||
authorized := gjson.GetBytes(params, "authorized")
|
|
||||||
idCard := gjson.GetBytes(params, "id_card")
|
idCard := gjson.GetBytes(params, "id_card")
|
||||||
if !name.Exists() || !mobileNo.Exists() || !authorizationURL.Exists() || authorizationURL.String() == "" ||
|
if !name.Exists() || !mobileNo.Exists() || !authorizationURL.Exists() || authorizationURL.String() == "" ||
|
||||||
!authorized.Exists() || authorized.String() == "" || !idCard.Exists() {
|
!idCard.Exists() {
|
||||||
return nil, errors.New("api请求, COMBCZDQ, 缺少必填参数: name / mobile_no(mobile) / authorization_url / authorized / id_card")
|
return nil, errors.New("api请求, COMBCZDQ, 缺少必填参数: name / mobile_no(mobile) / authorization_url / id_card")
|
||||||
}
|
}
|
||||||
|
|
||||||
reqParams := map[string]interface{}{
|
reqParams := map[string]interface{}{
|
||||||
"name": name.String(),
|
"name": name.String(),
|
||||||
"mobile_no": mobileNo.String(),
|
"mobile_no": mobileNo.String(),
|
||||||
"authorization_url": authorizationURL.String(),
|
"authorization_url": authorizationURL.String(),
|
||||||
"authorized": authorized.String(),
|
"authorized": "1",
|
||||||
"id_card": idCard.String(),
|
"id_card": idCard.String(),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1722,10 +1721,20 @@ func (a *ApiRequestService) ProcessCOMBCZQYRequest(params []byte) ([]byte, error
|
|||||||
|
|
||||||
// comboResponseToAPIResponseData 将组合包接口解密后的 Data 转为 []APIResponseData 并返回 JSON
|
// comboResponseToAPIResponseData 将组合包接口解密后的 Data 转为 []APIResponseData 并返回 JSON
|
||||||
func (a *ApiRequestService) comboResponseToAPIResponseData(resp *tianyuanapi.Response) ([]byte, error) {
|
func (a *ApiRequestService) comboResponseToAPIResponseData(resp *tianyuanapi.Response) ([]byte, error) {
|
||||||
|
if resp == nil {
|
||||||
|
return nil, fmt.Errorf("组合包响应为空")
|
||||||
|
}
|
||||||
dataBytes, err := json.Marshal(resp.Data)
|
dataBytes, err := json.Marshal(resp.Data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("组合包响应序列化失败: %w", err)
|
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
|
var combo ComboPackageResponse
|
||||||
if err := json.Unmarshal(dataBytes, &combo); err != nil {
|
if err := json.Unmarshal(dataBytes, &combo); err != nil {
|
||||||
return nil, fmt.Errorf("组合包响应解析失败: %w", err)
|
return nil, fmt.Errorf("组合包响应解析失败: %w", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user