作者 RuoYi

优化代码

@@ -21,6 +21,7 @@ import org.slf4j.Logger; @@ -21,6 +21,7 @@ import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory; 21 import org.slf4j.LoggerFactory;
22 import com.ruoyi.common.constant.Constants; 22 import com.ruoyi.common.constant.Constants;
23 import com.ruoyi.common.utils.StringUtils; 23 import com.ruoyi.common.utils.StringUtils;
  24 +import org.springframework.http.MediaType;
24 25
25 /** 26 /**
26 * 通用http发送方法 27 * 通用http发送方法
@@ -126,6 +127,19 @@ public class HttpUtils @@ -126,6 +127,19 @@ public class HttpUtils
126 */ 127 */
127 public static String sendPost(String url, String param) 128 public static String sendPost(String url, String param)
128 { 129 {
  130 + return sendPost(url, param, MediaType.APPLICATION_FORM_URLENCODED_VALUE);
  131 + }
  132 +
  133 + /**
  134 + * 向指定 URL 发送POST方法的请求
  135 + *
  136 + * @param url 发送请求的 URL
  137 + * @param param 请求参数
  138 + * @param contentType 内容类型
  139 + * @return 所代表远程资源的响应结果
  140 + */
  141 + public static String sendPost(String url, String param, String contentType)
  142 + {
129 PrintWriter out = null; 143 PrintWriter out = null;
130 BufferedReader in = null; 144 BufferedReader in = null;
131 StringBuilder result = new StringBuilder(); 145 StringBuilder result = new StringBuilder();
@@ -138,7 +152,7 @@ public class HttpUtils @@ -138,7 +152,7 @@ public class HttpUtils
138 conn.setRequestProperty("connection", "Keep-Alive"); 152 conn.setRequestProperty("connection", "Keep-Alive");
139 conn.setRequestProperty("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"); 153 conn.setRequestProperty("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64)");
140 conn.setRequestProperty("Accept-Charset", "utf-8"); 154 conn.setRequestProperty("Accept-Charset", "utf-8");
141 - conn.setRequestProperty("contentType", "utf-8"); 155 + conn.setRequestProperty("Content-Type", contentType);
142 conn.setDoOutput(true); 156 conn.setDoOutput(true);
143 conn.setDoInput(true); 157 conn.setDoInput(true);
144 out = new PrintWriter(conn.getOutputStream()); 158 out = new PrintWriter(conn.getOutputStream());
@@ -191,6 +205,11 @@ public class HttpUtils @@ -191,6 +205,11 @@ public class HttpUtils
191 205
192 public static String sendSSLPost(String url, String param) 206 public static String sendSSLPost(String url, String param)
193 { 207 {
  208 + return sendSSLPost(url, param, MediaType.APPLICATION_FORM_URLENCODED_VALUE);
  209 + }
  210 +
  211 + public static String sendSSLPost(String url, String param, String contentType)
  212 + {
194 StringBuilder result = new StringBuilder(); 213 StringBuilder result = new StringBuilder();
195 String urlNameString = url + "?" + param; 214 String urlNameString = url + "?" + param;
196 try 215 try
@@ -204,7 +223,7 @@ public class HttpUtils @@ -204,7 +223,7 @@ public class HttpUtils
204 conn.setRequestProperty("connection", "Keep-Alive"); 223 conn.setRequestProperty("connection", "Keep-Alive");
205 conn.setRequestProperty("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"); 224 conn.setRequestProperty("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64)");
206 conn.setRequestProperty("Accept-Charset", "utf-8"); 225 conn.setRequestProperty("Accept-Charset", "utf-8");
207 - conn.setRequestProperty("contentType", "utf-8"); 226 + conn.setRequestProperty("Content-Type", contentType);
208 conn.setDoOutput(true); 227 conn.setDoOutput(true);
209 conn.setDoInput(true); 228 conn.setDoInput(true);
210 229
@@ -55,7 +55,6 @@ public class ResourcesConfig implements WebMvcConfigurer @@ -55,7 +55,6 @@ public class ResourcesConfig implements WebMvcConfigurer
55 public CorsFilter corsFilter() 55 public CorsFilter corsFilter()
56 { 56 {
57 CorsConfiguration config = new CorsConfiguration(); 57 CorsConfiguration config = new CorsConfiguration();
58 - config.setAllowCredentials(true);  
59 // 设置访问源地址 58 // 设置访问源地址
60 config.addAllowedOriginPattern("*"); 59 config.addAllowedOriginPattern("*");
61 // 设置访问源请求头 60 // 设置访问源请求头
@@ -49,7 +49,7 @@ public class TokenService @@ -49,7 +49,7 @@ public class TokenService
49 49
50 protected static final long MILLIS_MINUTE = 60 * MILLIS_SECOND; 50 protected static final long MILLIS_MINUTE = 60 * MILLIS_SECOND;
51 51
52 - private static final Long MILLIS_MINUTE_TEN = 20 * 60 * 1000L; 52 + private static final Long MILLIS_MINUTE_TWENTY = 20 * 60 * 1000L;
53 53
54 @Autowired 54 @Autowired
55 private RedisCache redisCache; 55 private RedisCache redisCache;
@@ -127,14 +127,14 @@ public class TokenService @@ -127,14 +127,14 @@ public class TokenService
127 /** 127 /**
128 * 验证令牌有效期,相差不足20分钟,自动刷新缓存 128 * 验证令牌有效期,相差不足20分钟,自动刷新缓存
129 * 129 *
130 - * @param loginUser 130 + * @param loginUser 登录信息
131 * @return 令牌 131 * @return 令牌
132 */ 132 */
133 public void verifyToken(LoginUser loginUser) 133 public void verifyToken(LoginUser loginUser)
134 { 134 {
135 long expireTime = loginUser.getExpireTime(); 135 long expireTime = loginUser.getExpireTime();
136 long currentTime = System.currentTimeMillis(); 136 long currentTime = System.currentTimeMillis();
137 - if (expireTime - currentTime <= MILLIS_MINUTE_TEN) 137 + if (expireTime - currentTime <= MILLIS_MINUTE_TWENTY)
138 { 138 {
139 refreshToken(loginUser); 139 refreshToken(loginUser);
140 } 140 }
@@ -365,7 +365,7 @@ public class SysMenuServiceImpl implements ISysMenuService @@ -365,7 +365,7 @@ public class SysMenuServiceImpl implements ISysMenuService
365 /** 365 /**
366 * 获取路由名称,如没有配置路由名称则取路由地址 366 * 获取路由名称,如没有配置路由名称则取路由地址
367 * 367 *
368 - * @param routerName 路由名称 368 + * @param name 路由名称
369 * @param path 路由地址 369 * @param path 路由地址
370 * @return 路由名称(驼峰格式) 370 * @return 路由名称(驼峰格式)
371 */ 371 */