package com.github.wxiaoqi.security.common.util;

import javax.servlet.http.HttpServletRequest;

public class UserAgentUtil {
	/**
	 * 关键字: 微信浏览器
	 */
	public static final String KEY_WEIXIN_BROWSER = "micromessenger";

	/**
	 * 判断是否微信浏览器
	 * 
	 * @param user_agent
	 * @return
	 */
	public static boolean isWexinBrowser(HttpServletRequest request) {
		// 可能会出现npe
		String user_agent = "";
		user_agent = request.getHeader("user-agent");
		// 修改如下
		return user_agent != null && user_agent.toLowerCase().indexOf(KEY_WEIXIN_BROWSER) > 0;
	}
}
