liveb登录
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
JSONObject jsono=WxHelper.OAuth(request, response);
System.out.println(jsono);
int flag=0;
if(jsono!=null&&!"".equals(jsono)&&!"null".equals(jsono)&&"0".equals(jsono.get("errcode").toString())){
try {
// System.out.println(C3p0Util.queryCountForInt("select count(1) from userwxh where wxh='"+jsono.get("weixinid")+"'"));
if(C3p0Util.queryCountForInt("select count(1) from userwxh where wxh='"+jsono.get("weixinid")+"'")>0){
//微信注册过
Map<String,Cookie> cookieMap=WxHelper.ReadCookieMap(request);
if(cookieMap.containsKey("WxTokenTo"+jsono.get("weixinid"))){
//有cookie
//验证用户名密码
String pwd=URLDecoder.decode(cookieMap.get("WxTokenTo"+jsono.get("weixinid")).getValue(), "utf-8");
String sql="select t.userid from tuser t where t.userid=(select userid from userwxh where wxh='"+jsono.get("weixinid")+"') and t.password='"+C3p0Util.getMd5(pwd)+"'";
String userid=C3p0Util.queryForString(sql);
if(null!=userid&&!"".equals(userid)){
//密码正确,直接验证登录
Cookie wxtokento=cookieMap.get("WxTokenTo"+jsono.get("weixinid"));
// wxtokento.setMaxAge(3600*24);
// response.addCookie(wxtokento);
response.getWriter().print("正在调转...");
// System.out.println("http://218.56.106.137:20000/PageLogin?userId="+userid+"&pass="+wxtokento.getValue());
response.sendRedirect("http://bx.lzcb.com/PageLogin?userId="+userid+"&pass="+wxtokento.getValue());
}else{
flag=1;//重新登录
System.out.println("用户名或密码错误");
request.setAttribute("msg", "ERROR Incorrect Username Or Password !!!");
}
}else{
flag=1;//没cookie,手动登录
System.out.println("登录失效");
request.setAttribute("msg", "Login Expire!");
}
}else{
flag=1;//微信没注册过,手动登录
System.out.println("初次登录");
}
if(flag==1){
request.getRequestDispatcher("JSP/Login.jsp?userinfo="+jsono.get("weixinid")+"&userinfo2="+jsono.get("userid")).forward(request, response);
}
} catch (Exception e) {
e.printStackTrace();// TODO: handle exception
}
}
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String userid=request.getParameter("userid");
String pwd=request.getParameter("pass");
String wxid=request.getParameter("userinfo");
String wxrz=request.getParameter("userinfo2");
int limittype=Integer.parseInt(request.getParameter("limit"));
// System.out.println(C3p0Util.queryCountForInt("select count(1) from tuser where userid='"+userid+"' and password='"+C3p0Util.getMd5(pwd)+"'"));
if(C3p0Util.queryCountForInt("select count(1) from tuser where userid='"+userid+"' and password='"+C3p0Util.getMd5(pwd)+"'")>0){
//登录成功
//登记微信号
if(limittype!=1){
C3p0Util.update("update wxglryxx set wxh='"+wxid+"' , wxrz='"+wxrz+"' where id=(select t.glwxglry from tuser t where userid='"+userid+"')");
C3p0Util.update("update wxryxx set wxh='"+wxid+"' , wxrz='"+wxrz+"' where id=(select t.glwxry from tuser t where userid='"+userid+"')");
C3p0Util.update("update jzs set wxh='"+wxid+"' , wxrz='"+wxrz+"' where id=(select t.gljzgry from tuser t where userid='"+userid+"')");
C3p0Util.update("update xsxx set wxh='"+wxid+"' , wxrz='"+wxrz+"' where id=(select t.glxs from tuser t where userid='"+userid+"')");
C3p0Util.update("update ckglry set wxh='"+wxid+"' , wxrz='"+wxrz+"' where id=(select t.glckglry from tuser t where userid='"+userid+"')");
}
//写cookie
Cookie wxtokento=new Cookie("WxTokenTo"+wxid,pwd);
int age=-1;
switch (limittype){
case 2:age=3600*24;break;
case 3:age=3600*24*7;break;
case 4:age=3600*24*15;break;
case 5:age=3600*24*30;break;
default:age=-1;break;
}
wxtokento.setMaxAge(age);
response.addCookie(wxtokento);
response.getWriter().print("登录成功!正在跳转...");
//登录livebos
response.sendRedirect("http://bx.lzcb.com/PageLogin?userId="+userid+"&pass="+pwd);
}else{
request.setAttribute("msg", "ERROR Incorrect Username Or Password !!!");
request.getRequestDispatcher("JSP/Login.jsp").forward(request, response);
}
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}