Exemplo n.º 1
0
  /**
   * 获取预约验证码
   *
   * @param request
   */
  @RequestMapping("get_verifyOrder")
  public void getVerifyCode(HttpServletRequest request, ModelMap modelMap) {
    // 取得请求中的预约电话号码
    String orderTel = this.findStringParameterValue(request, "orderTel");
    if (orderTel == null || orderTel == "" || !NumberUtils.isDigits(orderTel)) {
      modelMap.put("success", false);
      modelMap.put("message", "请输入正确的手机号!");
    } else {
      // 生成短信验证码
      try {
        WordGenerator wordGenerator =
            new RandomWordGenerator(ConfigUtil.getConfig("verifycode.acceptchars"));
        String verifyCode = wordGenerator.getWord(4, Locale.getDefault());
        // 将生成的短信验证码保存进Session
        request.getSession().setAttribute(orderTel, verifyCode);

        // 调用短信平台接口发送验证码
        if (sendVerifyCodeMessage(orderTel, verifyCode)) {
          modelMap.put("success", true);
          modelMap.put("verifyCode", verifyCode);
        } else {
          modelMap.put("success", false);
          modelMap.put("message", "验证码取得失败,请重新获取!");
        }
      } catch (Exception e) {
        logger.error("验证码备选字符读取失败!", e);
        modelMap.put("success", false);
        modelMap.put("message", "验证码取得失败,请重新获取!");
      }
    }
  }
 /**
  * Creates a mock censored word generator that produces three words, the first two of which are
  * offensive
  */
 private WordGenerator mockWithTwoOffensiveWords() {
   WordGenerator censored = mock(WordGenerator.class);
   when(censored.getWord(anyInt())).thenReturn("f****r", "dickly", "noprob");
   when(censored.getWord(anyInt(), Locale.class.cast(anyObject())))
       .thenReturn("f****r", "dickly", "noprob");
   return censored;
 }