refactor(api): 优化接口响应处理逻辑和返回类型
- 移除`checkApiResponse`方法中不必要的状态码检查 - 统一修改`WxLoginController`中接口返回类型为`OutputData`,简化响应处理逻辑
This commit is contained in:
parent
e18463279b
commit
17f5807af6
|
@ -20,9 +20,9 @@ public class WxLoginController {
|
||||||
|
|
||||||
@PostMapping("/logout")
|
@PostMapping("/logout")
|
||||||
@ApiOperation(value = "用户退出登录")
|
@ApiOperation(value = "用户退出登录")
|
||||||
public ResponseDTO<Ab98ApiUtil.LogoutResponse> logout(@RequestParam @NotBlank String token) {
|
public ResponseDTO<Ab98ApiUtil.LogoutData> logout(@RequestParam @NotBlank String token) {
|
||||||
try {
|
try {
|
||||||
return ResponseDTO.ok(Ab98ApiUtil.doLogout(token));
|
return ResponseDTO.ok(Ab98ApiUtil.doLogout(token).getOutputData());
|
||||||
} catch (ApiException e) {
|
} catch (ApiException e) {
|
||||||
return ResponseDTO.fail(e);
|
return ResponseDTO.fail(e);
|
||||||
}
|
}
|
||||||
|
@ -46,9 +46,9 @@ public class WxLoginController {
|
||||||
*/
|
*/
|
||||||
@GetMapping("/getToken")
|
@GetMapping("/getToken")
|
||||||
@ApiOperation(value = "获取临时令牌", notes = "用于后续登录流程")
|
@ApiOperation(value = "获取临时令牌", notes = "用于后续登录流程")
|
||||||
public ResponseDTO<Ab98ApiUtil.TokenResponse> getToken(@RequestParam String appName) {
|
public ResponseDTO<Ab98ApiUtil.TokenData> getToken(@RequestParam String appName) {
|
||||||
try {
|
try {
|
||||||
return ResponseDTO.ok(Ab98ApiUtil.getToken(appName));
|
return ResponseDTO.ok(Ab98ApiUtil.getToken(appName).getOutputData());
|
||||||
} catch (ApiException e) {
|
} catch (ApiException e) {
|
||||||
return ResponseDTO.fail(e);
|
return ResponseDTO.fail(e);
|
||||||
}
|
}
|
||||||
|
@ -58,11 +58,11 @@ public class WxLoginController {
|
||||||
* 发送短信验证码
|
* 发送短信验证码
|
||||||
*/
|
*/
|
||||||
@PostMapping("/sendSms")
|
@PostMapping("/sendSms")
|
||||||
public ResponseDTO<Ab98ApiUtil.SmsSendResponse> sendSms(
|
public ResponseDTO<Ab98ApiUtil.SmsResult> sendSms(
|
||||||
@RequestParam String token,
|
@RequestParam String token,
|
||||||
@RequestParam String tel) {
|
@RequestParam String tel) {
|
||||||
try {
|
try {
|
||||||
return ResponseDTO.ok(Ab98ApiUtil.sendLoginSms(token, tel));
|
return ResponseDTO.ok(Ab98ApiUtil.sendLoginSms(token, tel).getOutputData());
|
||||||
} catch (ApiException e) {
|
} catch (ApiException e) {
|
||||||
return ResponseDTO.fail(e);
|
return ResponseDTO.fail(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,7 +140,7 @@ public class Ab98ApiUtil {
|
||||||
* 检查接口响应状态
|
* 检查接口响应状态
|
||||||
*/
|
*/
|
||||||
private static void checkApiResponse(BaseResponse response) {
|
private static void checkApiResponse(BaseResponse response) {
|
||||||
if (response.getStateCode() != 200 || !"ok".equals(response.getState())) {
|
if (!"ok".equals(response.getState())) {
|
||||||
log.error("接口调用失败: {}", response);
|
log.error("接口调用失败: {}", response);
|
||||||
throw new ApiException(ErrorCode.FAILED, "第三方接口调用失败");
|
throw new ApiException(ErrorCode.FAILED, "第三方接口调用失败");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue