@RequestMapping(value = "/validate.do") @ResponseBody public AjaxJson validate(String telephone) { // 验证手机号码 AjaxJson j = new AjaxJson(); String message = WechatConstant.validate_failed; // 验证失败时候提示 try { if (wechatRegisterServiceImpl.validateRegisterBytel(telephone)) { message = WechatConstant.validate_success; // 验证成功时候提供 j.setObj(GZipUtils.gzip_compress(telephone)); j.setSuccess(true); } else { j.setObj(GZipUtils.gzip_compress(WechatConstant.validate_failure)); j.setSuccess(false); } } catch (Exception e) { e.printStackTrace(); } j.setMsg(message); return j; }
@RequestMapping(value = "/submit.do") @ResponseBody public AjaxJson submit(HttpServletRequest request, RegisterEntity register, String validateCode) { AjaxJson j = new AjaxJson(); String message = ""; String openId = (String) request.getSession().getAttribute(WechatConstant.register_session_openId); String code = (String) request .getSession() .getAttribute( // 获取session中的code WechatConstant.validate_session_code); j.setSuccess(false); if (code == null) { message = "验证码已经过期,请重新获取"; } else if (!validateCode.equals(code)) { message = "验证码不正确!请重新输入"; } else { if ((WechatConstant.has_register).equals(openId)) { message = "您已经登记过了,不需要再次登记"; } else { register.setOpenId(openId); register.setBindTime(DateProcess.geTimestamp()); try { wechatRegisterServiceImpl.saveRegisterInfo(register); } catch (Exception e) { e.printStackTrace(); } j.setObj(register.getTelephone()); // message = WechatConstant.register_success; message = "恭喜你登记成功,点击\"确定\"跳转到大学生寒假特惠活动链接"; j.setSuccess(true); remove(request); // 最后登记成功后删除session释放内存 } } j.setMsg(message); return j; }