java服务端返回关闭当前支付宝/微信h5窗口

String userAgent = request.getHeader("user-agent").toLowerCase();
PrintWriter writer = response.getWriter();
StringBuilder sb = new StringBuilder();

//微信客户端
if(userAgent.indexOf("micromessenger") != -1){
    sb.append("<html>");
    sb.append("<script type='text/javascript' src='https://cdn.bootcss.com/jquery/1.9.1/jquery.min.js'></script>");
    sb.append("<script type='text/javascript' src='https://res.wx.qq.com/open/js/jweixin-1.2.0.js'></script>");
    sb.append("<script>");
    sb.append("if(typeof window.WeixinJSBridge=='undefined'){$(document).on('WeixinJSBridgeReady',function(){WeixinJSBridge.call('closeWindow')})}");
    sb.append("</script>");
    sb.append("</html>");
}
//支付宝
else if(userAgent.indexOf("alipay") != -1){
    sb.append("<html>");
    sb.append("<script type='text/javascript' src='https://cdn.bootcss.com/jquery/1.9.1/jquery.min.js'></script>");
    sb.append("<script type='text/javascript' src='https://a.alipayobjects.com/g/h5-lib/alipayjsapi/3.0.6/alipayjsapi.min.js'></script>");
    sb.append("<script>");
    sb.append("if(typeof window.AlipayJSBridge=='undefined'){$(document).on('AlipayJSBridgeReady',function(){AlipayJSBridge.call('closeWebview')})}");
    sb.append("</script>");
    sb.append("</html>");
}
writer.write(sb.toString());

 

上一篇:Web前端学习第五天——————HTML篇.019页面布局练习


下一篇:JavaWebDay01(Junit单元测试、注解)019