Commit 079b7eeecf59589d713261c51cbe806be905acae

Authored by RuoYi
1 parent ba240107

优化代码

ruoyi-common/src/main/java/com/ruoyi/common/utils/http/HttpUtils.java
... ... @@ -21,6 +21,7 @@ import org.slf4j.Logger;
21 21 import org.slf4j.LoggerFactory;
22 22 import com.ruoyi.common.constant.Constants;
23 23 import com.ruoyi.common.utils.StringUtils;
  24 +import org.springframework.http.MediaType;
24 25  
25 26 /**
26 27 * 通用http发送方法
... ... @@ -126,6 +127,19 @@ public class HttpUtils
126 127 */
127 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 143 PrintWriter out = null;
130 144 BufferedReader in = null;
131 145 StringBuilder result = new StringBuilder();
... ... @@ -138,7 +152,7 @@ public class HttpUtils
138 152 conn.setRequestProperty("connection", "Keep-Alive");
139 153 conn.setRequestProperty("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64)");
140 154 conn.setRequestProperty("Accept-Charset", "utf-8");
141   - conn.setRequestProperty("contentType", "utf-8");
  155 + conn.setRequestProperty("Content-Type", contentType);
142 156 conn.setDoOutput(true);
143 157 conn.setDoInput(true);
144 158 out = new PrintWriter(conn.getOutputStream());
... ... @@ -191,6 +205,11 @@ public class HttpUtils
191 205  
192 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 213 StringBuilder result = new StringBuilder();
195 214 String urlNameString = url + "?" + param;
196 215 try
... ... @@ -204,7 +223,7 @@ public class HttpUtils
204 223 conn.setRequestProperty("connection", "Keep-Alive");
205 224 conn.setRequestProperty("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64)");
206 225 conn.setRequestProperty("Accept-Charset", "utf-8");
207   - conn.setRequestProperty("contentType", "utf-8");
  226 + conn.setRequestProperty("Content-Type", contentType);
208 227 conn.setDoOutput(true);
209 228 conn.setDoInput(true);
210 229  
... ...
ruoyi-framework/src/main/java/com/ruoyi/framework/config/ResourcesConfig.java
... ... @@ -55,7 +55,6 @@ public class ResourcesConfig implements WebMvcConfigurer
55 55 public CorsFilter corsFilter()
56 56 {
57 57 CorsConfiguration config = new CorsConfiguration();
58   - config.setAllowCredentials(true);
59 58 // 设置访问源地址
60 59 config.addAllowedOriginPattern("*");
61 60 // 设置访问源请求头
... ...
ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java
... ... @@ -25,7 +25,7 @@ import io.jsonwebtoken.SignatureAlgorithm;
25 25  
26 26 /**
27 27 * token验证处理
28   - *
  28 + *
29 29 * @author ruoyi
30 30 */
31 31 @Component
... ... @@ -49,14 +49,14 @@ public class TokenService
49 49  
50 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 54 @Autowired
55 55 private RedisCache redisCache;
56 56  
57 57 /**
58 58 * 获取用户身份信息
59   - *
  59 + *
60 60 * @return 用户信息
61 61 */
62 62 public LoginUser getLoginUser(HttpServletRequest request)
... ... @@ -107,7 +107,7 @@ public class TokenService
107 107  
108 108 /**
109 109 * 创建令牌
110   - *
  110 + *
111 111 * @param loginUser 用户信息
112 112 * @return 令牌
113 113 */
... ... @@ -126,15 +126,15 @@ public class TokenService
126 126  
127 127 /**
128 128 * 验证令牌有效期,相差不足20分钟,自动刷新缓存
129   - *
130   - * @param loginUser
  129 + *
  130 + * @param loginUser 登录信息
131 131 * @return 令牌
132 132 */
133 133 public void verifyToken(LoginUser loginUser)
134 134 {
135 135 long expireTime = loginUser.getExpireTime();
136 136 long currentTime = System.currentTimeMillis();
137   - if (expireTime - currentTime <= MILLIS_MINUTE_TEN)
  137 + if (expireTime - currentTime <= MILLIS_MINUTE_TWENTY)
138 138 {
139 139 refreshToken(loginUser);
140 140 }
... ... @@ -142,7 +142,7 @@ public class TokenService
142 142  
143 143 /**
144 144 * 刷新令牌有效期
145   - *
  145 + *
146 146 * @param loginUser 登录信息
147 147 */
148 148 public void refreshToken(LoginUser loginUser)
... ... @@ -156,7 +156,7 @@ public class TokenService
156 156  
157 157 /**
158 158 * 设置用户代理信息
159   - *
  159 + *
160 160 * @param loginUser 登录信息
161 161 */
162 162 public void setUserAgent(LoginUser loginUser)
... ...
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java
... ... @@ -365,7 +365,7 @@ public class SysMenuServiceImpl implements ISysMenuService
365 365 /**
366 366 * 获取路由名称,如没有配置路由名称则取路由地址
367 367 *
368   - * @param routerName 路由名称
  368 + * @param name 路由名称
369 369 * @param path 路由地址
370 370 * @return 路由名称(驼峰格式)
371 371 */
... ...