浏览代码

个微账号登录,绑定,获取信息

吴树波 1 周之前
父节点
当前提交
ca85568dca

+ 24 - 0
fs-company/src/main/java/com/fs/company/controller/company/CompanyWxAccountController.java

@@ -142,4 +142,28 @@ public class CompanyWxAccountController extends BaseController
     public R getLoginStatus(Long accountId){
         return R.ok().put("data", companyWxAccountService.getLoginStatus(accountId));
     }
+    /**
+     * 删除企微账号
+     */
+	@GetMapping("/wakeUpLogin")
+    public R wakeUpLogin(Long accountId){
+        companyWxAccountService.wakeUpLogin(accountId);
+        return R.ok();
+    }
+    /**
+     * 删除企微账号
+     */
+	@GetMapping("/updateWxInfo")
+    public R updateWxInfo(Long accountId){
+        companyWxAccountService.updateWxInfo(accountId);
+        return R.ok().put("data", true);
+    }
+    /**
+     * 删除企微账号
+     */
+	@GetMapping("/wxLoginOut")
+    public R wxLoginOut(Long accountId){
+        companyWxAccountService.wxLoginOut(accountId);
+        return R.ok().put("data", true);
+    }
 }

+ 11 - 0
fs-service/src/main/java/com/fs/company/domain/CompanyWxAccount.java

@@ -1,6 +1,7 @@
 package com.fs.company.domain;
 
 import com.baomidou.mybatisplus.annotation.TableField;
+import com.fasterxml.jackson.annotation.JsonFormat;
 import com.fs.common.annotation.Excel;
 import com.fs.common.core.domain.BaseEntity;
 import lombok.Data;
@@ -25,6 +26,8 @@ public class CompanyWxAccount extends BaseEntity
     @Excel(name = "微信昵称")
     private String wxNickName;
 
+    private String headImgUrl;
+
     /** 电话号码 */
     @Excel(name = "电话号码")
     private String phone;
@@ -55,6 +58,14 @@ public class CompanyWxAccount extends BaseEntity
     private LocalDateTime authTime;
     // 登录状态,0未登录1已登录
     private Integer loginStatus;
+    private String wxnewpass;
+
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private LocalDateTime loginTime;
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private LocalDateTime outTime;
+
+    private String outRemark;
 
 
 

+ 6 - 0
fs-service/src/main/java/com/fs/company/service/ICompanyWxAccountService.java

@@ -74,4 +74,10 @@ public interface ICompanyWxAccountService extends IService<CompanyWxAccount>
     boolean getLoginStatus(Long accountId);
 
     R bindService(Long accountId);
+
+    void wakeUpLogin(Long accountId);
+
+    void updateWxInfo(Long accountId);
+
+    void wxLoginOut(Long accountId);
 }

+ 47 - 6
fs-service/src/main/java/com/fs/company/service/impl/CompanyWxServiceImpl.java

@@ -14,13 +14,19 @@ import com.fs.company.service.ICompanyUserService;
 import com.fs.company.service.ICompanyWxAccountService;
 import com.fs.wxcid.domain.CidIpadServerUser;
 import com.fs.wxcid.dto.login.LoginStatusData;
+import com.fs.wxcid.dto.login.LoginStatusResponseData;
+import com.fs.wxcid.dto.user.UserInfo;
+import com.fs.wxcid.dto.user.UserInfoExt;
+import com.fs.wxcid.dto.user.UserProfileData;
 import com.fs.wxcid.service.AdminLicenseService;
 import com.fs.wxcid.service.ICidIpadServerService;
 import com.fs.wxcid.service.ICidIpadServerUserService;
 import com.fs.wxcid.service.impl.LoginServiceImpl;
+import com.fs.wxcid.service.impl.UserServiceImpl;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.time.LocalDateTime;
 import java.util.Date;
 import java.util.List;
 
@@ -46,6 +52,8 @@ public class CompanyWxServiceImpl extends ServiceImpl<CompanyWxAccountMapper, Co
     private ICidIpadServerUserService cidIpadServerUserService;
     @Autowired
     private AdminLicenseService adminLicenseService;
+    @Autowired
+    private UserServiceImpl userService;
 
     /**
      * 查询企微账号
@@ -156,12 +164,17 @@ public class CompanyWxServiceImpl extends ServiceImpl<CompanyWxAccountMapper, Co
     @Override
     public boolean getLoginStatus(Long accountId) {
         CompanyWxAccount account = getById(accountId);
-        LoginStatusData login = loginService.getLoginStatus(accountId);
-        if(login.getLoginState() == 1){
-            account.setLoginStatus(1);
-            updateById(account);
-            return true;
-        }else{
+        try {
+            LoginStatusResponseData login = loginService.checkLoginStatus(accountId);
+            if(login.getRet() == 0){
+                account.setLoginStatus(1);
+                account.setLoginTime(LocalDateTime.now());
+                updateById(account);
+                return true;
+            }else{
+                return false;
+            }
+        }catch (Exception e){
             return false;
         }
     }
@@ -208,4 +221,32 @@ public class CompanyWxServiceImpl extends ServiceImpl<CompanyWxAccountMapper, Co
         cidIpadServerUserService.save(qwIpadServerUser);
         return null;
     }
+
+    @Override
+    public void wakeUpLogin(Long accountId) {
+        loginService.wakeUpLogin(accountId);
+    }
+
+    @Override
+    public void updateWxInfo(Long accountId) {
+        CompanyWxAccount account = getById(accountId);
+        UserProfileData profile = userService.getProfile(accountId);
+        UserInfo userInfo = profile.getUserInfo();
+        UserInfoExt userInfoExt = profile.getUserInfoExt();
+        account.setWxNickName(userInfo.getNickName().getStr());
+        account.setWxNo(userInfo.getUserName().getStr());
+        account.setHeadImgUrl(userInfoExt.getBigHeadImgUrl());
+        account.setPhone(userInfo.getBindMobile().getStr());
+        updateById(account);
+    }
+
+    @Override
+    public void wxLoginOut(Long accountId) {
+        CompanyWxAccount account = getById(accountId);
+        account.setLoginStatus(0);
+        account.setOutTime(LocalDateTime.now());
+        account.setOutRemark("手动退出");
+        updateById(account);
+        loginService.logOut(accountId);
+    }
 }

+ 1 - 0
fs-service/src/main/java/com/fs/wxcid/dto/user/UserInfo.java

@@ -8,6 +8,7 @@ public class UserInfo {
 
     private StringWrapper userName;
     private StringWrapper nickName;
+    private StringWrapper bindMobile;
 
     private long bindUin;
     private int status;

+ 10 - 0
fs-service/src/main/java/com/fs/wxcid/dto/user/UserInfoExt.java

@@ -0,0 +1,10 @@
+package com.fs.wxcid.dto.user;
+
+import com.fs.wxcid.dto.common.StringWrapper;
+import lombok.Data;
+
+@Data
+public class UserInfoExt {
+
+    private String bigHeadImgUrl;
+}

+ 1 - 0
fs-service/src/main/java/com/fs/wxcid/dto/user/UserProfileData.java

@@ -9,4 +9,5 @@ public class UserProfileData {
     private BaseResponse baseResponse;
 
     private UserInfo userInfo;
+    private UserInfoExt userInfoExt;
 }

+ 3 - 2
fs-service/src/main/java/com/fs/wxcid/service/LoginService.java

@@ -10,14 +10,15 @@ import com.fs.wxcid.dto.login.QrCodeRequest;
  */
 public interface LoginService {
     // 检测扫码是否完成
-    ApiResponseCommon<LoginStatusResponseData> checkLoginStatus(String authKey);
+    LoginStatusResponseData checkLoginStatus(Long accountId);
 
     // 获取当前在线状态
     ApiResponseCommon<LoginStatusData> getLoginStatus(String authKey);
 
     // 退出登录
-    ApiResponseCommon<Void> logOut(String authKey);
+    ApiResponseCommon<Void> logOut(Long accountId);
 
     /// 唤醒登录
     ApiResponseCommon<Void> wakeUpLogin(String authKey, QrCodeRequest request);
+    ApiResponseCommon<Void> wakeUpLogin(Long authKey);
 }

+ 24 - 17
fs-service/src/main/java/com/fs/wxcid/service/impl/LoginServiceImpl.java

@@ -38,19 +38,14 @@ public class LoginServiceImpl implements LoginService {
         return response.getData().getQrCodeUrl();
     }
     @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>>() {}
-        );
-
+    public LoginStatusResponseData checkLoginStatus(Long accountId) {
+        ApiResponseCommon<LoginStatusResponseData> response = serviceUtils.sendGet("/login/CheckLoginStatus", RequestBaseVo.builder().accountId(accountId).build(), new TypeReference<ApiResponseCommon<LoginStatusResponseData>>() {});
         // 只认 text == "账号已登录"
-        if ("账号已登录".equals(response.getText())) {
+        if ("账号已登录".equals(response.getText()) || "登录成功".equals(response.getText())) {
             if (response.getData() == null) {
                 throw new CustomException("登录状态异常:text 显示已登录,但 data 为空");
             }
-            return response;
+            return response.getData();
         } else {
             // 抛出具体的错误原因
             throw new CustomException("检查登录状态失败: " + (response.getText() != null ? response.getText() : "未知错误"));
@@ -84,16 +79,10 @@ public class LoginServiceImpl implements LoginService {
     }
 
 
-    public ApiResponseCommon<Void> logOut(String authKey) {
-        String url = BASE_URL + "/login/LogOut?key=" + authKey;
-        ApiResponseCommon<Void> response = WxWorkHttpUtil.getWithType(
-                url,
-                new TypeReference<ApiResponseCommon<Void>>() {}
-        );
-
+    public ApiResponseCommon<Void> logOut(Long accountId) {
+        ApiResponseCommon<Void> response = serviceUtils.sendGet("/login/LogOut", RequestBaseVo.builder().accountId(accountId).build(), new TypeReference<ApiResponseCommon<Void>>() {});
         String text = response.getText();
         int code = response.getCode();
-
         //真正的成功退出
         if (code == 200 && "退出成功!".equals(text)) {
             return response;
@@ -127,4 +116,22 @@ public class LoginServiceImpl implements LoginService {
             throw new CustomException("唤醒登录失败: " + errorMsg);
         }
     }
+
+    @Override
+    public ApiResponseCommon<Void> wakeUpLogin(Long accountId) {
+        QrCodeRequest request = new QrCodeRequest();
+        request.setCheck(false);
+        request.setIpadOrmac("ipad");
+        request.setProxy(serviceUtils.getProxy(accountId));
+        ApiResponseCommon<Void> response = serviceUtils.sendPost("/login/WakeUpLogin", RequestBaseVo.builder().accountId(accountId).data(request).build(), new TypeReference<ApiResponseCommon<Void>>() {});
+        String text = response.getText();
+        int code = response.getCode();
+        if (code == 200) {
+            return response;
+        }
+        else {
+            String errorMsg = text != null ? text : "唤醒登录失败,未知错误";
+            throw new CustomException("唤醒登录失败: " + errorMsg);
+        }
+    }
 }

+ 1 - 2
fs-service/src/main/java/com/fs/wxcid/service/impl/UserServiceImpl.java

@@ -18,13 +18,12 @@ import org.springframework.stereotype.Service;
 @Slf4j
 @Service
 public class UserServiceImpl implements UserService {
-    private static final String BASE_URL = "http://114.117.215.244:7006";
     @Autowired
     private ServiceUtils serviceUtils;
     @Override
     public UserProfileData getProfile(Long accountId) {
         try {
-            ApiResponseCommon<UserProfileData> response = serviceUtils.sendGet("/login/GetLoginStatus", RequestBaseVo.builder().accountId(accountId).data(null).build(), new TypeReference<ApiResponseCommon<UserProfileData>>() {});
+            ApiResponseCommon<UserProfileData> response = serviceUtils.sendGet("/user/GetProfile", RequestBaseVo.builder().accountId(accountId).data(null).build(), new TypeReference<ApiResponseCommon<UserProfileData>>() {});
             return response.getData();
         }catch (Exception e){
             return new UserProfileData();