优化代码

pull/987/head
RuoYi 2025-03-01 15:17:01 +08:00
parent ba24010709
commit 079b7eeecf
4 changed files with 31 additions and 13 deletions

View File

@ -21,6 +21,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.http.MediaType;
/**
* http
@ -125,6 +126,19 @@ public class HttpUtils
* @return
*/
public static String sendPost(String url, String param)
{
return sendPost(url, param, MediaType.APPLICATION_FORM_URLENCODED_VALUE);
}
/**
* URL POST
*
* @param url URL
* @param param
* @param contentType
* @return
*/
public static String sendPost(String url, String param, String contentType)
{
PrintWriter out = null;
BufferedReader in = null;
@ -138,7 +152,7 @@ public class HttpUtils
conn.setRequestProperty("connection", "Keep-Alive");
conn.setRequestProperty("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64)");
conn.setRequestProperty("Accept-Charset", "utf-8");
conn.setRequestProperty("contentType", "utf-8");
conn.setRequestProperty("Content-Type", contentType);
conn.setDoOutput(true);
conn.setDoInput(true);
out = new PrintWriter(conn.getOutputStream());
@ -190,6 +204,11 @@ public class HttpUtils
}
public static String sendSSLPost(String url, String param)
{
return sendSSLPost(url, param, MediaType.APPLICATION_FORM_URLENCODED_VALUE);
}
public static String sendSSLPost(String url, String param, String contentType)
{
StringBuilder result = new StringBuilder();
String urlNameString = url + "?" + param;
@ -204,7 +223,7 @@ public class HttpUtils
conn.setRequestProperty("connection", "Keep-Alive");
conn.setRequestProperty("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64)");
conn.setRequestProperty("Accept-Charset", "utf-8");
conn.setRequestProperty("contentType", "utf-8");
conn.setRequestProperty("Content-Type", contentType);
conn.setDoOutput(true);
conn.setDoInput(true);

View File

@ -55,7 +55,6 @@ public class ResourcesConfig implements WebMvcConfigurer
public CorsFilter corsFilter()
{
CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true);
// 设置访问源地址
config.addAllowedOriginPattern("*");
// 设置访问源请求头

View File

@ -25,7 +25,7 @@ import io.jsonwebtoken.SignatureAlgorithm;
/**
* token
*
*
* @author ruoyi
*/
@Component
@ -49,14 +49,14 @@ public class TokenService
protected static final long MILLIS_MINUTE = 60 * MILLIS_SECOND;
private static final Long MILLIS_MINUTE_TEN = 20 * 60 * 1000L;
private static final Long MILLIS_MINUTE_TWENTY = 20 * 60 * 1000L;
@Autowired
private RedisCache redisCache;
/**
*
*
*
* @return
*/
public LoginUser getLoginUser(HttpServletRequest request)
@ -107,7 +107,7 @@ public class TokenService
/**
*
*
*
* @param loginUser
* @return
*/
@ -126,15 +126,15 @@ public class TokenService
/**
* 20
*
* @param loginUser
*
* @param loginUser
* @return
*/
public void verifyToken(LoginUser loginUser)
{
long expireTime = loginUser.getExpireTime();
long currentTime = System.currentTimeMillis();
if (expireTime - currentTime <= MILLIS_MINUTE_TEN)
if (expireTime - currentTime <= MILLIS_MINUTE_TWENTY)
{
refreshToken(loginUser);
}
@ -142,7 +142,7 @@ public class TokenService
/**
*
*
*
* @param loginUser
*/
public void refreshToken(LoginUser loginUser)
@ -156,7 +156,7 @@ public class TokenService
/**
*
*
*
* @param loginUser
*/
public void setUserAgent(LoginUser loginUser)

View File

@ -365,7 +365,7 @@ public class SysMenuServiceImpl implements ISysMenuService
/**
*
*
* @param routerName
* @param name
* @param path
* @return
*/