예제 #1
0
 @RequestMapping(value = "/apply.do")
 @ResponseBody
 public AjaxJson apply(String telephone) { // 进行申请
   AjaxJson j = new AjaxJson();
   String message = "";
   j.setSuccess(false);
   try {
     String validTel = GZipUtils.gzip_decompress(telephone);
     if (WechatConstant.validate_none.equals(validTel)) {
       message = "还没有进行验证,首先进行验证操作";
     } else if (WechatConstant.validate_failure.equals(validTel)) {
       message = "号码验证失败,请重新验证";
     } else {
       if (wechatRegisterServiceImpl.hasGet(validTel)) {
         message = "hasget";
         j.setSuccess(true);
       } else {
         WechatRegHasget get = new WechatRegHasget();
         get.setTelephone(validTel);
         get.setGetTime(DateProcess.geTimestamp());
         wechatRegisterServiceImpl.saveHasGet(get);
         message = "已经有" + wechatRegisterServiceImpl.getRegisterNums() + "人参与了流量申请";
         j.setSuccess(true);
       }
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
   j.setMsg(message);
   return j;
 }
예제 #2
0
  /*
   * 请求验证码
   */
  @RequestMapping(value = "/code.do")
  @ResponseBody
  public AjaxJson code(HttpServletRequest request, String telephone) {
    AjaxJson j = new AjaxJson();
    logger.info("合肥移动手机号为" + telephone + "请求验证码");
    j.setSuccess(false);

    String openId =
        (String) request.getSession().getAttribute(WechatConstant.register_session_openId);
    if ((WechatConstant.has_register).equals(openId)) {
      j.setMsg("您已经登记过了,不需要再次登记");
      return j;
    }
    try {
      if (wechatRegisterServiceImpl.validateRegisterBytel(telephone)) {
        j.setMsg("这个号码已经登记过了,不需要重新登记");
        return j;
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    Map<String, Object> map = smsServiceImpl.SendRegisterMessage(telephone);
    String validateCode = map.get("validateCode").toString();
    String statusCode = map.get("statusCode").toString();
    System.out.println(validateCode + "发送状态码为:" + statusCode);
    if (statusCode.equals(MessageConstant.success_code)) {
      j.setSuccess(true);
      request.getSession().setAttribute(WechatConstant.validate_session_code, validateCode);
    } else {
      j.setMsg("短信发送失败,请重新获取");
    }
    return j;
  }
예제 #3
0
 @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;
 }
예제 #4
0
 @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;
 }