From cc3f07fbf1b7a17b24c660d9590957a344f9211b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A3=B4=E6=B5=A9=E5=AE=87?= <617594538@qq.com> Date: Tue, 28 May 2024 09:06:02 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20NAS=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/system/SysLoginController.java | 41 +++++++++++-------- .../common/core/domain/entity/SysUser.java | 28 +++++++++++++ 2 files changed, 51 insertions(+), 18 deletions(-) diff --git a/pnkx-admin/src/main/java/com/pnkx/web/controller/system/SysLoginController.java b/pnkx-admin/src/main/java/com/pnkx/web/controller/system/SysLoginController.java index c4cd877..5bf7e30 100644 --- a/pnkx-admin/src/main/java/com/pnkx/web/controller/system/SysLoginController.java +++ b/pnkx-admin/src/main/java/com/pnkx/web/controller/system/SysLoginController.java @@ -21,6 +21,7 @@ import net.sf.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.web.bind.annotation.*; +import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; import org.springframework.web.util.UriComponentsBuilder; @@ -110,24 +111,28 @@ public class SysLoginController { Set roles = permissionService.getRolePermission(user); // 权限集合 Set permissions = permissionService.getMenuPermission(user); - // get请求获取群晖token - // 使用UriComponentsBuilder构建带有查询参数的URL - UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(DSM_LOGIN_URL) - .queryParam("api", "SYNO.API.Auth") - .queryParam("version", "3") - .queryParam("method", "login") - .queryParam("account", "peihaoyu") - .queryParam("passwd", "Phy0316.") - .queryParam("enable_syno_token", "yes"); - // 构建完整的URL - String url = builder.toUriString(); - // 发送GET请求并获取响应 - RestTemplate restTemplate = new RestTemplate(); - String result = restTemplate.getForObject(url, String.class); - logger.info("群晖token:{}", result); - JSONObject jsonObject = JSONObject.fromObject(result); - if (jsonObject.get("success").equals(true)) { - user.setSynoToken(jsonObject.getJSONObject("data").getString("synotoken")); + try { + // get请求获取群晖token + // 使用UriComponentsBuilder构建带有查询参数的URL + UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(DSM_LOGIN_URL) + .queryParam("api", "SYNO.API.Auth") + .queryParam("version", "6") + .queryParam("method", "login") + .queryParam("account", user.getSynoUserName()) + .queryParam("passwd", user.getSynoPassword()) + .queryParam("enable_syno_token", "yes"); + // 构建完整的URL + String url = builder.toUriString(); + // 发送GET请求并获取响应 + RestTemplate restTemplate = new RestTemplate(); + String result = restTemplate.getForObject(url, String.class); + logger.info("群晖token:{}", result); + JSONObject jsonObject = JSONObject.fromObject(result); + if (jsonObject.get("success").equals(true)) { + user.setSynoToken(jsonObject.getJSONObject("data").getString("synotoken")); + } + } catch (RestClientException e) { + logger.error("请求群晖token失败,异常信息", e); } AjaxResult ajax = AjaxResult.success(); ajax.put("user", user); diff --git a/pnkx-common/src/main/java/com/pnkx/common/core/domain/entity/SysUser.java b/pnkx-common/src/main/java/com/pnkx/common/core/domain/entity/SysUser.java index 539e9cd..f193b49 100644 --- a/pnkx-common/src/main/java/com/pnkx/common/core/domain/entity/SysUser.java +++ b/pnkx-common/src/main/java/com/pnkx/common/core/domain/entity/SysUser.java @@ -149,6 +149,14 @@ public class SysUser extends BaseEntity { @Getter private IpLocation location; + // 群晖用户名 + private String synoUserName; + + + // 群晖密码 + private String synoPassword; + + // 群晖token private String synoToken; public SysUser() { @@ -347,6 +355,26 @@ public class SysUser extends BaseEntity { this.location = location; } + public IpLocation getLocation() { + return location; + } + + public String getSynoUserName() { + return synoUserName; + } + + public void setSynoUserName(String synoUserName) { + this.synoUserName = synoUserName; + } + + public String getSynoPassword() { + return synoPassword; + } + + public void setSynoPassword(String synoPassword) { + this.synoPassword = synoPassword; + } + public String getSynoToken() { return synoToken; }