From 868d1f136a0b6547afcda5029f597912830a5f48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A3=B4=E6=B5=A9=E5=AE=87?= <617594538@qq.com> Date: Mon, 27 May 2024 19:00:29 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BE=A4=E6=99=96token?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/system/SysLoginController.java | 30 ++++++++++++++++++- .../common/core/domain/entity/SysUser.java | 10 +++++++ .../com/pnkx/common/utils/ip/IpUtils.java | 13 ++++---- 3 files changed, 45 insertions(+), 8 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 55194f1..3b4023a 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 @@ -17,9 +17,17 @@ import com.pnkx.framework.web.service.TokenService; import com.pnkx.service.IPxLikeRecordService; import com.pnkx.system.service.ISysMenuService; import com.pnkx.system.service.ISysUserService; +import net.sf.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpEntity; +import org.springframework.http.ResponseEntity; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; import org.springframework.web.bind.annotation.*; +import org.springframework.web.client.RestTemplate; +import org.springframework.web.util.UriComponentsBuilder; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; @@ -37,6 +45,8 @@ public class SysLoginController { private static final Logger logger = LoggerFactory.getLogger(SysLoginController.class); + private static final String DSM_LOGIN_URL = "http://192.168.31.104:5000/webapi/auth.cgi"; + @Resource private SysLoginService loginService; @Resource @@ -50,7 +60,6 @@ public class SysLoginController { @Resource private ISysUserService userService; - /** * 登录方法 * @@ -106,6 +115,25 @@ 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")); + } AjaxResult ajax = AjaxResult.success(); ajax.put("user", user); ajax.put("roles", roles); 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 737a932..3838b4f 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,8 @@ public class SysUser extends BaseEntity { @Getter private IpLocation location; + private String SynoToken; + public SysUser() { } @@ -345,6 +347,14 @@ public class SysUser extends BaseEntity { this.location = location; } + public String getSynoToken() { + return SynoToken; + } + + public void setSynoToken(String synoToken) { + SynoToken = synoToken; + } + @Override public String toString() { return "SysUser{" + diff --git a/pnkx-common/src/main/java/com/pnkx/common/utils/ip/IpUtils.java b/pnkx-common/src/main/java/com/pnkx/common/utils/ip/IpUtils.java index 3af869d..1094feb 100644 --- a/pnkx-common/src/main/java/com/pnkx/common/utils/ip/IpUtils.java +++ b/pnkx-common/src/main/java/com/pnkx/common/utils/ip/IpUtils.java @@ -1,15 +1,8 @@ package com.pnkx.common.utils.ip; -import java.io.InputStream; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.regex.Pattern; -import javax.servlet.http.HttpServletRequest; - import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSONObject; import com.pnkx.common.utils.StringUtils; -import com.pnkx.common.utils.html.EscapeUtil; import lombok.extern.slf4j.Slf4j; import org.apache.commons.io.IOUtils; import org.lionsoul.ip2region.xdb.Searcher; @@ -17,6 +10,12 @@ import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import org.springframework.web.client.RestTemplate; +import javax.servlet.http.HttpServletRequest; +import java.io.InputStream; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.regex.Pattern; + import static java.math.BigDecimal.ZERO; /**