|
@@ -1,86 +1,107 @@
|
|
|
package com.fs.wxcid.service.impl;
|
|
package com.fs.wxcid.service.impl;
|
|
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.TypeReference;
|
|
|
|
|
+import com.fs.common.exception.CustomException;
|
|
|
import com.fs.wxcid.dto.common.ApiResponse;
|
|
import com.fs.wxcid.dto.common.ApiResponse;
|
|
|
-import com.fs.wxcid.dto.login.LoginRequest;
|
|
|
|
|
-import com.fs.wxcid.dto.login.QrCodeRequest;
|
|
|
|
|
-import com.fs.wxcid.dto.login.SlideVerifyRequest;
|
|
|
|
|
-import com.fs.wxcid.dto.login.VerifyCodeRequest;
|
|
|
|
|
|
|
+import com.fs.wxcid.dto.common.ApiResponseCommon;
|
|
|
|
|
+import com.fs.wxcid.dto.login.*;
|
|
|
import com.fs.wxcid.service.LoginService;
|
|
import com.fs.wxcid.service.LoginService;
|
|
|
import com.fs.wxwork.utils.WxWorkHttpUtil;
|
|
import com.fs.wxwork.utils.WxWorkHttpUtil;
|
|
|
-import com.alibaba.fastjson.TypeReference;
|
|
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
-import java.util.HashMap;
|
|
|
|
|
-import java.util.Map;
|
|
|
|
|
-
|
|
|
|
|
|
|
+@Slf4j
|
|
|
@Service
|
|
@Service
|
|
|
public class LoginServiceImpl implements LoginService {
|
|
public class LoginServiceImpl implements LoginService {
|
|
|
|
|
|
|
|
private static final String BASE_URL = "http://114.117.215.244:7006";
|
|
private static final String BASE_URL = "http://114.117.215.244:7006";
|
|
|
|
|
|
|
|
- // ------------------ 账号密码登录 ------------------
|
|
|
|
|
-
|
|
|
|
|
- public ApiResponse a16Login(String authKey, LoginRequest request) {
|
|
|
|
|
- return post("/login/A16Login", authKey, request);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public ApiResponse deviceLogin(String authKey, LoginRequest request) {
|
|
|
|
|
- return post("/login/DeviceLogin", authKey, request);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // ------------------ 二维码登录 ------------------
|
|
|
|
|
|
|
|
|
|
- public ApiResponse getLoginQrCodeNew(String authKey, QrCodeRequest request) {
|
|
|
|
|
- return post("/login/GetLoginQrCodeNew", authKey, request);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public ApiResponse getLoginQrCodeNewDirect(String authKey, QrCodeRequest request) {
|
|
|
|
|
- return post("/login/GetLoginQrCodeNewDirect", authKey, request);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public ApiResponse macLogin(String authKey, QrCodeRequest request) {
|
|
|
|
|
- return post("/login/MacLogin", authKey, request);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public ApiResponse carLogin(String authKey, QrCodeRequest request) {
|
|
|
|
|
- return post("/login/CarLogin", authKey, request);
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public ApiResponseCommon<LoginQrCodeResponseData> getLoginQrCodeNewDirect(String authKey, QrCodeRequest request) {
|
|
|
|
|
+ String url = BASE_URL + "/login/GetLoginQrCodeNewDirect?key=" + authKey;
|
|
|
|
|
+ ApiResponseCommon<LoginQrCodeResponseData> loginQrCodeResponseDataApiResponseCommon = WxWorkHttpUtil.postWithType(
|
|
|
|
|
+ url,
|
|
|
|
|
+ request,
|
|
|
|
|
+ new TypeReference<ApiResponseCommon<LoginQrCodeResponseData>>() {
|
|
|
|
|
+ }
|
|
|
|
|
+ );
|
|
|
|
|
+ log.info("二维码照片url: {}", loginQrCodeResponseDataApiResponseCommon.getData().getQrCodeUrl());
|
|
|
|
|
+ return loginQrCodeResponseDataApiResponseCommon;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
public ApiResponse wakeUpLogin(String authKey, QrCodeRequest request) {
|
|
public ApiResponse wakeUpLogin(String authKey, QrCodeRequest request) {
|
|
|
return post("/login/WakeUpLogin", authKey, request);
|
|
return post("/login/WakeUpLogin", authKey, request);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// ------------------ 状态检测 ------------------
|
|
// ------------------ 状态检测 ------------------
|
|
|
|
|
|
|
|
- public ApiResponse checkCanSetAlias(String authKey) {
|
|
|
|
|
- return get("/login/CheckCanSetAlias", authKey);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public ApiResponse checkLoginStatus(String authKey) {
|
|
|
|
|
- return get("/login/CheckLoginStatus", authKey);
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public ApiResponseCommon<LoginStatusResponseData> checkLoginStatus(String authKey) {
|
|
|
|
|
+ String url = BASE_URL + "/login/CheckLoginStatus?key=" + authKey;
|
|
|
|
|
+ ApiResponseCommon<LoginStatusResponseData> response = WxWorkHttpUtil.getWithType(
|
|
|
|
|
+ url,
|
|
|
|
|
+ new TypeReference<ApiResponseCommon<LoginStatusResponseData>>() {}
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ // 只认 text == "账号已登录"
|
|
|
|
|
+ if ("账号已登录".equals(response.getText())) {
|
|
|
|
|
+ if (response.getData() == null) {
|
|
|
|
|
+ throw new CustomException("登录状态异常:text 显示已登录,但 data 为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ return response;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 抛出具体的错误原因
|
|
|
|
|
+ throw new CustomException("检查登录状态失败: " + (response.getText() != null ? response.getText() : "未知错误"));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public ApiResponseCommon<LoginStatusData> getLoginStatus(String authKey) {
|
|
|
|
|
+ String url = BASE_URL + "/login/GetLoginStatus?key=" + authKey;
|
|
|
|
|
+ ApiResponseCommon<LoginStatusData> response = WxWorkHttpUtil.getWithType(
|
|
|
|
|
+ url,
|
|
|
|
|
+ new TypeReference<ApiResponseCommon<LoginStatusData>>() {}
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ //核心判断:只有 code=200 且 data 不为 null 才算成功
|
|
|
|
|
+ if (response.getCode() != 200 || response.getData() == null) {
|
|
|
|
|
+ String errorMsg = response.getText() != null
|
|
|
|
|
+ ? response.getText()
|
|
|
|
|
+ : "获取登录状态失败,未知错误";
|
|
|
|
|
+ throw new CustomException("账号未登录或状态异常: " + errorMsg);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return response;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public ApiResponseCommon<Void> logOut(String authKey) {
|
|
|
|
|
+ String url = BASE_URL + "/login/LogOut?key=" + authKey;
|
|
|
|
|
+ ApiResponseCommon<Void> response = WxWorkHttpUtil.getWithType(
|
|
|
|
|
+ url,
|
|
|
|
|
+ new TypeReference<ApiResponseCommon<Void>>() {}
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ String text = response.getText();
|
|
|
|
|
+ int code = response.getCode();
|
|
|
|
|
+
|
|
|
|
|
+ //真正的成功退出
|
|
|
|
|
+ if (code == 200 && "退出成功!".equals(text)) {
|
|
|
|
|
+ return response;
|
|
|
|
|
+ }
|
|
|
|
|
+ //已经退出过了(幂等,视为成功)
|
|
|
|
|
+ else if (code == 300 && "你已退出登录".equals(text)) {
|
|
|
|
|
+ return response; // 也可记录日志:log.debug("重复登出,忽略");
|
|
|
|
|
+ }
|
|
|
|
|
+ //其他情况一律视为失败
|
|
|
|
|
+ else {
|
|
|
|
|
+ String errorMsg = text != null ? text : "退出登录失败,未知错误";
|
|
|
|
|
+ throw new CustomException("退出登录失败: " + errorMsg);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public ApiResponse getLoginStatus(String authKey) {
|
|
|
|
|
- return get("/login/GetLoginStatus", authKey);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public ApiResponse get62Data(String authKey) {
|
|
|
|
|
- return get("/login/Get62Data", authKey);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public ApiResponse logOut(String authKey) {
|
|
|
|
|
- return get("/login/LogOut", authKey);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // ------------------ 验证 ------------------
|
|
|
|
|
-
|
|
|
|
|
- public ApiResponse verifyCode(String authKey, VerifyCodeRequest request) {
|
|
|
|
|
- return post("/login/VerifyCode", authKey, request);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public ApiResponse verifyCodeSlide(String authKey, SlideVerifyRequest request) {
|
|
|
|
|
- return post("/login/VerifyCodeSlide", authKey, request);
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
// ------------------ 工具方法 ------------------
|
|
// ------------------ 工具方法 ------------------
|
|
|
/**
|
|
/**
|
|
@@ -95,19 +116,4 @@ public class LoginServiceImpl implements LoginService {
|
|
|
String url = BASE_URL + path + "?key=" + authKey;
|
|
String url = BASE_URL + path + "?key=" + authKey;
|
|
|
return WxWorkHttpUtil.postWithType(url, request, new TypeReference<ApiResponse>() {});
|
|
return WxWorkHttpUtil.postWithType(url, request, new TypeReference<ApiResponse>() {});
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 通用 GET 请求方法(无请求体)
|
|
|
|
|
- *
|
|
|
|
|
- * @param path 接口路径
|
|
|
|
|
- * @param authKey 账号唯一标识
|
|
|
|
|
- * @return 统一响应结果
|
|
|
|
|
- */
|
|
|
|
|
- private ApiResponse get(String path, String authKey) {
|
|
|
|
|
- String url = BASE_URL + path;
|
|
|
|
|
- Map<String, Object> params = new HashMap<>();
|
|
|
|
|
- params.put("authKey", authKey);
|
|
|
|
|
- String resp = WxWorkHttpUtil.get(url, params);
|
|
|
|
|
- return com.alibaba.fastjson.JSON.parseObject(resp, ApiResponse.class);
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|