@Autowired
private StringRedisTemplate stringRedisTemplate;
@Autowired
public UserController userController;
@SneakyThrows
@Test
public void test2(){
//输入流,读文件里的电话号
BufferedReader br = new BufferedReader(new FileReader("C:\\Users\\lmz\\Desktop\\1.txt"));
//输出流,将登录的电话号返回的token写到指定文件中
PrintWriter pw = new PrintWriter("C:\\Users\\lmz\\Desktop\\2.txt");
String phone;
while ((phone = br.readLine()) != null) {
//进行发短信
userController.sendCode(phone, null);
//得到redis中存的短信验证码
String code = stringRedisTemplate.opsForValue().get(RedisConstants.LOGIN_CODE_KEY + phone);
//进行登录
Object data = userController.login(new LoginFormDTO(phone, code, "123"), null).getData();
//将登录返回的token写到文件中
pw.println(data);
pw.flush();
}
br.close();
pw.close();
}
//循环生成电话号
@SneakyThrows
@Test
public void test3(){
//创建打印流指定打印到某个文件
PrintWriter pw = new PrintWriter("C:\\Users\\lmz\\Desktop\\1.txt");
for (int i = 0; i < 1000; i++) {
//打印
pw.println(phone());
//刷新打印流
pw.flush();
}
//关闭打印流
pw.close();
}
//生成随机电话号
private static String phone(){
String[] phoneProfix = new String[]{"130", "131", "132", "133", "134", "135", "136", "137", "138", "139",
"147", "150", "151", "152", "153", "155", "156", "157", "158", "159",
"186", "187", "188", "189"};
int index = RandomUtil.randomInt(0, phoneProfix.length);
String first = phoneProfix[index];
//需要引入hutool工具类依赖
return first + RandomUtil.randomNumbers(8);
}
随机生成1000个电话号并进行登录接口测试
最新推荐文章于 2023-04-23 16:15:29 发布