下面列出了org.apache.commons.lang.RandomStringUtils#randomNumeric ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void sendMail(String email) {
String code = RandomStringUtils.randomNumeric(6);
String subject = VerifyCodeScenes.EMAIL_CHANGE.getName();
String content = null;
try {
Template template = configuration.getTemplate("email/reset_email.html");
StringWriter result = new StringWriter();
template.process(MapUtils.create().set("code", code), result);
content = result.toString(); // FreeMarkerTemplateUtils.processTemplateIntoString(template,)
} catch (IOException | TemplateException e) {
e.printStackTrace();
}
VerifyCode verifyCode = this.save(email, code, VerifyCodeScenes.EMAIL_CHANGE, VerifyCodeType.EMAIL, null);
applicationContext.publishEvent(EmailEvent.EmailEventBuilder
.builder()
.setSubject(subject)
.setContent(content)
.setTo(email)
.build());
// timedDestruction(verifyCode);
}
@ApiOperation(notes = "发送验证码 :\n" +
"\n account账号," +
" codeType:1 注册 2 重置密码 3 安全验证 4 支付密码设置 5 提币 6手机号绑定 7手机号验证", value = "发送验证码")
@RequestMapping(value = "getTelCode", method = RequestMethod.GET)
@ResponseBody
public Map<String, Object> getTelVcode(TelCodeTypeVO telCodeTypeVO, HttpServletRequest request, HttpServletResponse response) {
String account = telCodeTypeVO.getAccount();
Byte codeType = telCodeTypeVO.getCodeType();
if (StringUtils.isBlank(account) ||!TelCodeTypeEnum.CODES.contains(codeType) ) {
throw new CommonException(ResponseMsg.MISS_PARAM);
}
//短信存储到redis
if(!redisUtils.isCanSendTwoSms(account,codeType)){
throw new CommonException(ResponseMsg.SMS_NO_TIME_MINUTE_1);
}
//检查验证码类型
checkTelCodeType(telCodeTypeVO);
// 获取随机码
String telVcode = RandomStringUtils.randomNumeric(myConfiguration.getCodeLength());
telVcode = "123456";
try {
NetWordBuildParam netWordBuildParam = new NetWordBuildParam();
netWordBuildParam.setMobile(account);
netWordBuildParam.setCode(telVcode);
// 发送短信
String yzm = "1";//NetWordBuildSendUtil.send(netWordBuildParam);
// 判断短信发送状态
if (Integer.parseInt(yzm) == 1) {
redisUtils.setSmsRedisHashValue(codeType,account,telVcode);
return ResponseUtil.getSuccessMap("验证码发送成功");
} else {
return ResponseUtil.getNotNormalMap(ChinaToBuild.map.get(yzm));
}
} catch (Exception e) {
throw new CommonException("短信发送失败:" + e.getMessage());
}
}
@RequestMapping("/order")
public DeferredResult<String> order() throws Exception {
logger.info("主线程开始");
String orderNumber = RandomStringUtils.randomNumeric(8);
//设置订单号
mockQueue.setPlaceOrder(orderNumber);
DeferredResult<String> result = new DeferredResult<>();
//订单号和返回结果绑定
deferredResultHolder.getMap().put(orderNumber,result);
logger.info("主线程返回");
return result;
}
public static CrudOrderB createRandomCrudOrder(int userId) {
CrudOrderB co = new CrudOrderB();
String id = RandomStringUtils.randomNumeric(10);
int price = 100;
co.setId(id);
co.setUserId(userId);
co.setPrice(price);
return co;
}
protected void testAddingBrownGroupSaveSubmit() throws Exception {
selectFrameIframePortlet();
waitAndCreateNew();
String docId = waitForDocId();
String random = RandomStringUtils.randomNumeric(4);
String organizationDocumentNumber = "ORD" + random;
String groupDescription = "GD" + random;
String groupName = "BrownGroup " + AutomatedFunctionalTestUtils.createUniqueDtsPlusTwoRandomChars();
String nameSpace = "KR-IDM";
String today = getDateToday();
Calendar nextYearCal = Calendar.getInstance();
nextYearCal.add(Calendar.YEAR, 1);
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
String nextYear = sdf.format(nextYearCal.getTime());
//Enter details for BrownGroup.
waitAndTypeByName("document.documentHeader.documentDescription", "Adding Brown Group");
waitAndTypeByName("document.documentHeader.explanation", "I want to add Brown Group to test KIM");
waitAndTypeByName("document.documentHeader.organizationDocumentNumber", organizationDocumentNumber);
selectOptionByName("document.groupNamespace", nameSpace);
waitAndTypeByName("document.groupName", groupName);
waitAndTypeByName("document.groupDescription", groupDescription);
waitAndClickByXpath(SAVE_XPATH_2);
waitForTextPresent("Document was successfully saved.");
waitAndClickByXpath(SUBMIT_XPATH);
waitForTextPresent("Document was successfully submitted.");
}
protected void testAddingBrownGroupSubmit() throws Exception {
selectFrameIframePortlet();
waitAndCreateNew();
String docId = waitForDocId();
String random = RandomStringUtils.randomNumeric(4);
String organizationDocumentNumber = "ORD" + random;
String groupDescription = "GD" + random;
String groupName = "BrownGroup " + AutomatedFunctionalTestUtils.createUniqueDtsPlusTwoRandomChars();
String nameSpace = "KR-IDM";
String today = getDateToday();
acceptAlertIfPresent();
Calendar nextYearCal = Calendar.getInstance();
nextYearCal.add(Calendar.YEAR, 1);
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
String nextYear = sdf.format(nextYearCal.getTime());
//Enter details for BrownGroup.
waitAndTypeByName("document.documentHeader.documentDescription", "Adding Brown Group");
waitAndTypeByName("document.documentHeader.explanation", "I want to add Brown Group to test KIM");
waitAndTypeByName("document.documentHeader.organizationDocumentNumber", organizationDocumentNumber);
selectOptionByName("document.groupNamespace", nameSpace);
waitAndTypeByName("document.groupName", groupName);
waitAndTypeByName("document.groupDescription", groupDescription);
checkByName("document.active");
waitAndClickByXpath(SUBMIT_XPATH);
}
@Test
public void versionCheckShouldFailWithTooLongValue() {
final String version = RandomStringUtils.randomNumeric(Validation.MAX_VERSION_LENGTH + 1);
assertContainsIgnoreCase(
"Version can only be " + Validation.MAX_VERSION_LENGTH +
" characters in length, you entered " +
version.length(),
descriptor.doCheckVersion(version).toString());
assertValidationMessage(FormValidation.error(""), descriptor.doCheckVersion(version));
}
public static CrudOrder createRandomCrudOrder() {
CrudOrder co = new CrudOrder();
String id = RandomStringUtils.randomNumeric(10);
int userId = Randoms.randomInt(10000);
int price = 100;
co.setId(id);
co.setUserId(userId);
co.setPrice(price);
return co;
}
@Test
public void versionCheckShouldSucceedWithMaxNumber() {
final String version = RandomStringUtils.randomNumeric(Validation.MAX_VERSION_LENGTH);
assertEquals(FormValidation.ok(), descriptor.doCheckVersion(version));
}
@Override
public ValidateCode generate(ServletWebRequest request) {
String code = RandomStringUtils.randomNumeric(securityProperties.getCode().getSms().getLength());
return new ValidateCode(code, securityProperties.getCode().getSms().getExpireIn());
}
public static String getRandomTestUID() {
return RandomStringUtils.randomNumeric(10);
}
/**
* Generates a reset key.
*
* @return the generated reset key
*/
public static String generateResetKey() {
return RandomStringUtils.randomNumeric(DEF_COUNT);
}
/**
* Generates an activation key.
*
* @return the generated activation key
*/
public static String generateActivationKey() {
return RandomStringUtils.randomNumeric(DEF_COUNT);
}
/**
* Generate validate code.
*
* @param request the request
*
* @return the validate code
*/
@Override
public ValidateCode generate(ServletWebRequest request) {
String code = RandomStringUtils.randomNumeric(securityProperties.getCode().getSms().getLength());
return new ValidateCode(code, securityProperties.getCode().getSms().getExpireIn());
}
/**
* Generates an activation key.
*
* @return the generated activation key
*/
public static String generateActivationKey() {
return RandomStringUtils.randomNumeric(DEF_COUNT);
}
/**
* Generates a reset key.
*
* @return the generated reset key
*/
public static String generateResetKey() {
return RandomStringUtils.randomNumeric(DEF_COUNT);
}
/**
* Generates a reset key.
*
* @return the generated reset key
*/
public static String generateResetKey() {
return RandomStringUtils.randomNumeric(DEF_COUNT);
}
/**
* Generates (random) password for user to be provisioned
*
* @return
*/
protected String generatePassword() {
return RandomStringUtils.randomNumeric(12);
}
/**
* Generates a reset key.
*
* @return the generated reset key
*/
public static String generateResetKey() {
return RandomStringUtils.randomNumeric(DEF_COUNT);
}
/**
* Generates a reset key.
*
* @return the generated reset key
*/
public static String generateResetKey() {
return RandomStringUtils.randomNumeric(DEF_COUNT);
}