@ResponseBody
  @RequestMapping(value = "/core/getAccessToken", method = RequestMethod.POST)
  public ResponseResult getAccessToken(HttpServletRequest request, HttpServletResponse response) {
    ResponseResult result = new ResponseResult();
    try {
      String loginID = request.getParameter("loginID");
      String password = request.getParameter("password");

      result.checkFieldRequired("loginID", loginID);
      result.checkFieldRequired("password", password);
      if (result.getMessages().size() > 0) {
        result.setStatus(ResponseStatus.ValidateFailed.getCode());
        return result;
      }

      SecurityAccessToken accessToken =
          this.securityUserService.getAccessTokenByLogin(loginID, password);
      if (accessToken == null) {
        result.checkQueryEmpty(MessageConstant.QUERY_EMPTY_WRONG_LOGIN);
      } else {
        result.setStatus(ResponseStatus.OK.getCode());
        result.setData(accessToken);
      }

    } catch (Exception e) {
      e.printStackTrace();
      logger.fatal(e);
      result.checkException(e);
    }
    return result;
  }
  @ResponseBody
  @RequestMapping(value = "/core/getUserByToken", method = RequestMethod.POST)
  public ResponseResult getUserByToken(HttpServletRequest request, HttpServletResponse response) {
    ResponseResult result = new ResponseResult();
    try {
      String accessToken = request.getParameter("accessToken");

      result.checkFieldRequired("accessToken", accessToken);
      if (result.getMessages().size() > 0) {
        result.setStatus(ResponseStatus.ValidateFailed.getCode());
        return result;
      }

      SecurityUser securityUser = this.securityUserService.getSecurityUserByToken(accessToken);
      if (securityUser == null) {
        result.checkQueryEmpty(MessageConstant.QUERY_EMPTY_WRONG_TOKEN);
      } else {
        ServletContext sc = request.getServletContext();
        // 这个用户的可访问资源获取
        Object roleResourceMapObj = sc.getAttribute(ServletConstant.ROLE_RESOURCE_MAP);
        if (roleResourceMapObj != null) {
          @SuppressWarnings("unchecked")
          Map<Integer, List<SecurityResource>> roleResourceMap =
              (Map<Integer, List<SecurityResource>>) roleResourceMapObj;
          for (SecurityRole item : securityUser.getRoleList()) {
            List<SecurityResource> resourceList = roleResourceMap.get(item.getRoleID());
            for (SecurityResource securityResource : resourceList) {
              securityUser.getResUrlList().add(securityResource.getResURL());
            }
          }
        }

        result.setStatus(ResponseStatus.OK.getCode());
        result.setData(securityUser);
      }

    } catch (Exception e) {
      e.printStackTrace();
      logger.fatal(e);
      result.checkException(e);
    }
    return result;
  }
  @ResponseBody
  @RequestMapping(value = "/core/sendVerifyCode", method = RequestMethod.POST)
  public ResponseResult sendVerifyCode(HttpServletRequest request, HttpServletResponse response) {
    ResponseResult result = new ResponseResult();
    try {
      String email = request.getParameter("email");
      System.out.println("sendVerifyCode email: " + email);
      result.checkFieldRequired("email", email);
      result.checkFieldEmail("email", email);
      if (result.getMessages().size() > 0) {
        result.setStatus(ResponseStatus.ValidateFailed.getCode());
        return result;
      }

      String verifyCode = StringUtil.getRandomNumber(4, 9);

      ServletContext sc = request.getServletContext();
      Properties mailProperties = (Properties) sc.getAttribute("mail.properties");

      String content = "亲爱的毒电波用户," + verifyCode + " 是您的验证码,5分钟内有效。";
      if (!MailUtil.sendMail(mailProperties, content, email)) {
        result.setStatus(ResponseStatus.Failed.getCode());
      } else {
        result.setStatus(ResponseStatus.OK.getCode());
        this.verifyCodeMap.put(email, verifyCode);

        System.out.println("sendVerifyCode verifyCodeMap: " + verifyCodeMap);
        verifyCodeTimeTask(email);
      }

    } catch (Exception e) {
      e.printStackTrace();
      logger.fatal(e);
      result.checkException(e);
    }
    return result;
  }
  @ResponseBody
  @RequestMapping(value = "/core/getAccessTokenByMail", method = RequestMethod.POST)
  public ResponseResult getAccessTokenByMail(
      HttpServletRequest request, HttpServletResponse response) {
    ResponseResult result = new ResponseResult();
    try {
      String email = request.getParameter("email");
      String verifyCode = request.getParameter("verifyCode");

      System.out.println("getAccessTokenByMail mail:" + email);
      System.out.println("getAccessTokenByMail verifyCode:" + verifyCode);
      System.out.println("getAccessTokenByMail verifyCodeMap:" + verifyCodeMap);
      if (result.checkFieldRequired("email", email)
          && result.checkFieldRequired("verifyCode", verifyCode)) {
        result.checkVerifyCode(verifyCodeMap, email, verifyCode);
      }
      if (result.getMessages().size() > 0) {
        result.setStatus(ResponseStatus.ValidateFailed.getCode());
        return result;
      }

      SecurityAccessToken accessToken = this.securityUserService.getAccessTokenByEmail(email);
      if (accessToken == null) {
        result.checkQueryEmpty(MessageConstant.QUERY_EMPTY_WRONG_LOGIN);
      } else {
        result.setStatus(ResponseStatus.OK.getCode());
        result.setData(accessToken);
        verifyCodeMap.remove(email);
      }

    } catch (Exception e) {
      e.printStackTrace();
      logger.fatal(e);
      result.checkException(e);
    }
    return result;
  }