Browse Source

fix(user): 处理API错误响应并抛出异常

- 解析API返回的JSON数据
- 检查errorCode字段是否为空
- 如果存在错误则抛出ApiException异常
- 成功时返回固定的成功消息结构体
- 优化了cURL请求后的数据处理逻辑
master
zhangf@suq.cn 2 days ago
parent
commit
5ca653d9ca
  1. 8
      app/service/user/ApiService.php

8
app/service/user/ApiService.php

@ -84,7 +84,13 @@ class ApiService extends BaseService
curl_setopt($ch, CURLOPT_POSTFIELDS, $result);
$output = curl_exec($ch);
curl_close($ch);
return json_decode($output, true);
$result = json_decode($output, true);
if ($result['errorCode'] != '') {
throw new ApiException($result['message']);
}
return [
'msg' => 'success'
];
}
}
Loading…
Cancel
Save