private void updateUserInfo(Map<String, String> loginInfo) { Session session = HBUtil.getSession(); UserInfoEntity userInfo = (UserInfoEntity) session.get(UserInfoEntity.class, loginInfo.get("openid")); session.beginTransaction(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // �������ڸ�ʽ userInfo.setStoredCookie(loginInfo.get("cookie")); userInfo.setGenDate(java.sql.Date.valueOf(sdf.format(new Date()))); session.save(userInfo); session.getTransaction().commit(); session.close(); }
private LoginRstCode tryLogin(Map<String, String> loginInfo) { NetworkManager nm = new NetworkManager(); HashMap<String, String> params = new HashMap<String, String>(); String lgRstPage, stuMainPage; Matcher codeVaileMatcher, xmMatcher; UserInfoEntity user = HBEntityUtil.getUserInfo(loginInfo.get("openid")); /** ��1����get��¼ҳ�� ����ҳ�棺�õ�ҳ���е�ViewStateֵ */ String viewStateNew = loginInfo.get("viewState").replaceAll("[+]", "%2B"); /** ��2�������ݵ�¼��Ϣ������post�������������ѧ�á����롢��֤�� ����ҳ�棺ȡ����Ӧͷ�е�Set-Cookie���ݡ� */ params.put("__VIEWSTATE", viewStateNew); params.put("txtUserName", user.getStuNumber()); params.put("TextBox2", user.getStuPassword()); params.put("txtSecretCode", loginInfo.get("checkCode")); params.put("RadioButtonList1", "ѧ��"); params.put("Button1", ""); params.put("lbLanguage", ""); params.put("hidPdrs", ""); params.put("hidsc", ""); nm.clearSpecialHeader(); nm.addSpecialHeader( "Accept", "image/gif, image/jpeg, image/pjpeg, application/x-ms-application, application/xaml+xml, application/x-ms-xbap, */*"); nm.addSpecialHeader("Content-Type", "application/x-www-form-urlencoded"); nm.addSpecialHeader("Cache-Control", "max-age=0"); nm.addSpecialHeader("Host", "jwgl.fjnu.edu.cn"); nm.addSpecialHeader("Referer", "http://jwgl.fjnu.edu.cn/"); nm.addSpecialHeader("Cookie", loginInfo.get("cookie")); nm.addSpecialHeader("Accept-Encoding", "gzip, deflate"); nm.addSpecialHeader("Accept-Language", "zh-CN,en,*"); lgRstPage = nm.sendPost("http://jwgl.fjnu.edu.cn/default2.aspx", params); // System.out.println(nm.sendPost("http://jwgl.fjnu.edu.cn/default2.aspx", params)); stuMainPage = nm.sendGet("http://jwgl.fjnu.edu.cn/xs_main.aspx?xh=" + user.getStuNumber(), ""); if (lgRstPage == null || stuMainPage == null) return LoginRstCode.SERVER_ERROR; codeVaileMatcher = Pattern.compile("��֤�벻��ȷ").matcher(lgRstPage); if (codeVaileMatcher.find()) { // ��֤�벻��ȷ return LoginRstCode.CHECKCODE_ERROR; } System.out.println("\n" + user.getStuNumber() + user.getStuPassword() + "\n"); // System.out.println(stuMainPage); xmMatcher = Pattern.compile("<span id=\"xhxm\">(.{0,12})ͬѧ</span>").matcher(stuMainPage); if (xmMatcher.find()) { xmStr = xmMatcher.group(1); updateUserInfo(loginInfo); return LoginRstCode.SUCCESS; } else { return LoginRstCode.SERVER_ERROR; } }