perf:空指针调整

This commit is contained in:
曾文豪
2024-09-18 17:25:19 +08:00
parent d38077b0f8
commit 0470ca0b9a
4 changed files with 22 additions and 4 deletions

View File

@@ -23,6 +23,21 @@ public class ServletKit extends ServletUtil {
return null;
}
/**
* 获取请求头
*
* @param name 请求头
* @return 请求头
*/
public static String getHeader(String name) {
HttpServletRequest request = getRequest();
if (request == null) {
return "";
}
return getHeader(request, name, "utf-8");
}
/**
* 获取客户端IP
*

View File

@@ -84,7 +84,7 @@ public class TsCacheService {
* 验证 图片验证码
*/
public void verifyCaptcha(String value) {
String captchaKey = ServletUtil.getHeader(ServletKit.getRequest(), "captcha", "utf-8");
String captchaKey = ServletKit.getHeader("captcha");
String cache = get(captchaKey);
if (StrUtil.isEmpty(cache) || !StrUtil.equals(cache, value)) {
throw new ApiException("验证码不正确");