微信浏览器跳转手机默认浏览器 -- 源码

GoogleVip8 1年前 ⋅ 435 阅读
/**
 * 微信浏览器跳转手机默认浏览器
 *
 * @param request
 * @param response
 * @return
 */
@RequestMapping("/jumpOut")
public String jumpOut(HttpServletRequest request, HttpServletResponse response) {

    String userAgent = request.getHeader("user-agent");

    // 是否是微信浏览器中打开
    if (userAgent != null && userAgent.contains("MicroMessenger")) {

        response.setHeader("Content-Disposition", "attachment;filename='open.apk'");
        response.setHeader("Content-Type", "text/plain; charset=utf-8");
        response.setStatus(HttpStatus.SC_PARTIAL_CONTENT);
      	// 实际上只要设置以上内容就可以了
        response.setHeader("Accept-Ranges", "bytes");
        response.setHeader("Content-Range", "bytes 0-1/1");
        response.setHeader("Content-Length", "0");
        response.setHeader("ETag", "W/\"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk\"");
        response.setHeader("X-Powered-By", "Express");
        response.setHeader("Proxy-Connection", "keep-alive");

        // 不能跳转页面
        return null;
    }
    // 打开页面
    return "jumpOut";
}

全部评论: 0

    我有话说: