import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* 验证是否是手机访问
* @param request
* @return
*/
public static boolean judgeIsPhone(HttpServletRequest request) {
boolean isPhone = false;
if (StringUtils.isNotBlank(request.getHeader("User-Agent"))) {
String userAgent = request.getHeader("User-Agent").toLowerCase();
Pattern padPattern = Pattern.compile(ipadReg, Pattern.CASE_INSENSITIVE);
Matcher padMatcher = padPattern.matcher(userAgent);
//是不是pad
if (!padMatcher.find()) {
Pattern androidPattern = Pattern.compile(androidReg, Pattern.CASE_INSENSITIVE);
Matcher androidMatcher = androidPattern.matcher(userAgent);
if (androidMatcher.find()) {
Pattern mobilePattern = Pattern.compile(mobileReg, Pattern.CASE_INSENSITIVE);
Matcher mobileMatcher = mobilePattern.matcher(userAgent);
//是否是android手机
if (mobileMatcher.find()) {
isPhone = true;
}
} else {
//是否是其它手机
Pattern pattern = Pattern.compile(phoneReg, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(userAgent);
if(matcher.find()){
isPhone = true;
}
}
}
}
return isPhone;
}