重置密码接口
This commit is contained in:
parent
1696c0b8e6
commit
e06785032b
@ -14,7 +14,9 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ -228,4 +230,45 @@ public class SystemUserController {
|
||||
return Result.success(systemUserService.getTenantListBySn(map));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "星纵验证账号", notes = "星纵验证账号", httpMethod = "POST")
|
||||
@PostMapping(value = "/xz/checkAccount")
|
||||
public Result checkAccount(@RequestBody SystemUser systemUser) {
|
||||
systemUserService.checkAccount(systemUser);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "根据账号获取邮箱验证码", notes = "根据账号获取邮箱验证码", httpMethod = "POST")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "type", required = true, value = "1修改密码", paramType = "body"),
|
||||
@ApiImplicitParam(name = "account", required = true, value = "账号", paramType = "body"),
|
||||
})
|
||||
@PostMapping(value = "/getEmailCodeByAccount")
|
||||
public Result getEmailCodeByAccount(@ApiIgnore @RequestBody HashMap<String, Object> paramMap) {
|
||||
systemUserService.getEmailCodeByAccount(paramMap);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "重置密码验证邮箱", notes = "重置密码验证邮箱", httpMethod = "POST")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "account", required = true, value = "账号", paramType = "body"),
|
||||
@ApiImplicitParam(name = "code", required = true, value = "邮箱验证码", paramType = "body"),
|
||||
})
|
||||
@PostMapping(value = "/resetPwValidCode")
|
||||
public Result<HashMap<String, Object>> resetPwValidCode(@ApiIgnore @RequestBody HashMap<String, Object> paramMap) {
|
||||
return Result.success(systemUserService.resetPwValidCode(paramMap));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "重置密码通过邮箱方式", notes = "重置密码通过邮箱方式", httpMethod = "POST")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "account", required = true, value = "账号", paramType = "body"),
|
||||
@ApiImplicitParam(name = "password", required = true, value = "新密码", paramType = "body"),
|
||||
@ApiImplicitParam(name = "uuid", required = true, value = "随机id", paramType = "body"),
|
||||
})
|
||||
@PostMapping(value = "/resetPwByEmail")
|
||||
public Result resetPwByEmail(@ApiIgnore @RequestBody HashMap<String, Object> paramMap) {
|
||||
systemUserService.resetPwByEmail(paramMap);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@ import com.zhgd.xmgl.modules.basicdata.entity.dto.LoginInfoByTokenDto;
|
||||
import com.zhgd.xmgl.modules.basicdata.entity.SystemUser;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ -76,4 +77,12 @@ public interface ISystemUserService extends IService<SystemUser> {
|
||||
void xzUpdatePw(SystemUser systemUser);
|
||||
|
||||
List<SystemUser> getTenantListBySn(Map<String, Object> map);
|
||||
|
||||
void checkAccount(SystemUser systemUser);
|
||||
|
||||
void getEmailCodeByAccount(HashMap<String, Object> hashMap);
|
||||
|
||||
HashMap<String, Object> resetPwValidCode(HashMap<String, Object> paramMap);
|
||||
|
||||
void resetPwByEmail(HashMap<String, Object> paramMap);
|
||||
}
|
||||
|
||||
@ -33,13 +33,11 @@ import com.zhgd.xmgl.modules.worker.mapper.WorkerInfoMapper;
|
||||
import com.zhgd.xmgl.modules.worker.service.IUserEnterpriseService;
|
||||
import com.zhgd.xmgl.modules.xz.entity.XzRegistry;
|
||||
import com.zhgd.xmgl.modules.xz.mapper.XzRegistryMapper;
|
||||
import com.zhgd.xmgl.modules.xz.service.impl.XzRegistryServiceImpl;
|
||||
import com.zhgd.xmgl.security.JwtTokenProvider;
|
||||
import com.zhgd.xmgl.security.entity.UserInfo;
|
||||
import com.zhgd.xmgl.security.util.SecurityUtils;
|
||||
import com.zhgd.xmgl.util.EnvironmentUtil;
|
||||
import com.zhgd.xmgl.util.GovDanzhouSafeHatUtil;
|
||||
import com.zhgd.xmgl.util.MessageUtil;
|
||||
import com.zhgd.xmgl.util.PwUtil;
|
||||
import com.zhgd.xmgl.util.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -76,6 +74,8 @@ public class SystemUserServiceImpl extends ServiceImpl<SystemUserMapper, SystemU
|
||||
@Autowired
|
||||
private XzRegistryMapper xzRegistryMapper;
|
||||
@Autowired
|
||||
private XzRegistryServiceImpl xzRegistryService;
|
||||
@Autowired
|
||||
private QualityRegionMapper qualityRegionMapper;
|
||||
@Autowired
|
||||
private ICompanyService companyService;
|
||||
@ -111,7 +111,16 @@ public class SystemUserServiceImpl extends ServiceImpl<SystemUserMapper, SystemU
|
||||
private ProjectMapper projectMapper;
|
||||
@Autowired
|
||||
private ProjectExternalSystemServiceMapper projectExternalSystemServiceMapper;
|
||||
|
||||
@Autowired
|
||||
private EmailUtils emailUtils;
|
||||
/**
|
||||
* 重置密码的邮箱验证码
|
||||
*/
|
||||
public static final String UPDATE_PW_EMAIL_CODE = "UPDATE_PW_EMAIL_CODE:";
|
||||
/**
|
||||
* 修改密码的有效期
|
||||
*/
|
||||
public static final String UPDATE_PW_UUID = "UPDATE_PW_UUID:";
|
||||
@Value("${mqtt-scope}")
|
||||
private String scope;
|
||||
/**
|
||||
@ -1130,22 +1139,12 @@ public class SystemUserServiceImpl extends ServiceImpl<SystemUserMapper, SystemU
|
||||
|
||||
@Override
|
||||
public void xzUpdatePw(SystemUser systemUser) {
|
||||
checkCode(systemUser);
|
||||
SystemUser su = systemUserMapper.selectById(systemUser.getUserId());
|
||||
if (su == null) {
|
||||
throw new OpenAlertException("userId不存在");
|
||||
}
|
||||
if (StringUtils.isBlank(systemUser.getGraphValidateCodeUuid())) {
|
||||
throw new OpenAlertException("graphValidateCodeUuid不能为空");
|
||||
}
|
||||
Object o = redisRepository.get(systemUser.getGraphValidateCodeUuid());
|
||||
if (o == null) {
|
||||
throw new OpenAlertException("验证码已过期");
|
||||
}
|
||||
String code = String.valueOf(o);
|
||||
if (!Objects.equals(code, systemUser.getGraphValidateCode())) {
|
||||
throw new OpenAlertException("验证码不正确");
|
||||
}
|
||||
if (!Objects.equals(su.getOldPassword(), systemUser.getShowPassword())) {
|
||||
if (!Objects.equals(su.getShowPassword(), systemUser.getOldPassword())) {
|
||||
throw new OpenAlertException("原密码不正确");
|
||||
}
|
||||
systemUser.setPassword(null);
|
||||
@ -1158,11 +1157,103 @@ public class SystemUserServiceImpl extends ServiceImpl<SystemUserMapper, SystemU
|
||||
systemUserMapper.updateById(systemUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查验证码是否正确
|
||||
*
|
||||
* @param systemUser
|
||||
*/
|
||||
private void checkCode(SystemUser systemUser) {
|
||||
if (StringUtils.isBlank(systemUser.getGraphValidateCodeUuid())) {
|
||||
throw new OpenAlertException("graphValidateCodeUuid不能为空");
|
||||
}
|
||||
Object o = redisRepository.get(systemUser.getGraphValidateCodeUuid());
|
||||
redisRepository.del(systemUser.getGraphValidateCodeUuid());
|
||||
if (o == null) {
|
||||
throw new OpenAlertException("验证码已失效");
|
||||
}
|
||||
String code = String.valueOf(o);
|
||||
if (!Objects.equals(code, systemUser.getGraphValidateCode())) {
|
||||
throw new OpenAlertException("验证码不正确");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SystemUser> getTenantListBySn(Map<String, Object> map) {
|
||||
return baseMapper.getTenantListBySn(map);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkAccount(SystemUser systemUser) {
|
||||
checkCode(systemUser);
|
||||
Integer count = systemUserMapper.selectCount(new LambdaQueryWrapper<SystemUser>()
|
||||
.eq(SystemUser::getAccount, systemUser.getAccount()));
|
||||
if (count == 0) {
|
||||
throw new OpenAlertException("账号不存在");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getEmailCodeByAccount(HashMap<String, Object> hashMap) {
|
||||
Integer type = MapUtils.getInteger(hashMap, "type");
|
||||
if (Objects.equals(type, 1)) {
|
||||
String account = MapUtils.getString(hashMap, "account");
|
||||
SystemUser systemUser = new SystemUser();
|
||||
systemUser.setAccount(account);
|
||||
SystemUser su = systemUserMapper.selectOne(new LambdaQueryWrapper<SystemUser>()
|
||||
.eq(SystemUser::getAccount, systemUser.getAccount()));
|
||||
if (su == null) {
|
||||
throw new OpenAlertException("账号不存在");
|
||||
}
|
||||
String code = NumberUtils.randomNum(6);
|
||||
redisRepository.set(UPDATE_PW_EMAIL_CODE + su.getAccount(), code, 1200L);
|
||||
HashMap<String, Object> registryEmailMap = xzRegistryService.getRegistryEmail(systemUser);
|
||||
String subject = "重置密码";
|
||||
String content = "您收到这封邮件是因为我们收到了一个重设密码的请求,您的账号是" + systemUser.getAccount() + ",验证码是," + code +
|
||||
"请注意,为了您的账户安全,请勿与他人分享您的验证码。";
|
||||
emailUtils.sendSimpleMail(MapUtils.getString(registryEmailMap, "email"), subject, content);
|
||||
} else {
|
||||
throw new OpenAlertException("type不能为空");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<String, Object> resetPwValidCode(HashMap<String, Object> paramMap) {
|
||||
String account = MapUtils.getString(paramMap, "account");
|
||||
String code = MapUtils.getString(paramMap, "code");
|
||||
String key = UPDATE_PW_EMAIL_CODE + account;
|
||||
Object o = redisRepository.get(key);
|
||||
redisRepository.del(key);
|
||||
if (!Objects.equals(code, o)) {
|
||||
throw new OpenAlertException("验证码不正确或者失效");
|
||||
}
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
String uuid = IdUtil.randomUUID();
|
||||
map.put("uuid", uuid);
|
||||
String uuidKey = UPDATE_PW_UUID + account;
|
||||
redisRepository.set(uuidKey, uuid, 300L);
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetPwByEmail(HashMap<String, Object> paramMap) {
|
||||
String account = MapUtils.getString(paramMap, "account");
|
||||
String uuid = MapUtils.getString(paramMap, "uuid");
|
||||
String password = MapUtils.getString(paramMap, "password");
|
||||
String uuidKey = UPDATE_PW_UUID + account;
|
||||
Object o = redisRepository.get(uuidKey);
|
||||
if (!Objects.equals(uuid, o)) {
|
||||
throw new OpenAlertException("uuid不正确或者失效");
|
||||
}
|
||||
SystemUser systemUser = systemUserMapper.selectOne(new LambdaQueryWrapper<SystemUser>()
|
||||
.eq(SystemUser::getAccount, account));
|
||||
String showPassword = systemUser.getShowPassword();
|
||||
systemUser.setPwUpdateTime(new Date());
|
||||
systemUser.setPassword(passwordEncoder.encode(showPassword));
|
||||
systemUser.setShowPassword(password);
|
||||
systemUserMapper.updateById(systemUser);
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String timestamp = "1711613997695";
|
||||
String pw = "123";
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
package com.zhgd.xmgl.modules.worker.controller;
|
||||
|
||||
import com.zhgd.jeecg.common.api.vo.Result;
|
||||
import com.zhgd.xmgl.modules.worker.entity.WorkerAttendance;
|
||||
import com.zhgd.xmgl.modules.worker.entity.dto.GetWorkerInfoByDevDto;
|
||||
import com.zhgd.xmgl.modules.worker.entity.vo.GetWorkerInfoByDevVo;
|
||||
import com.zhgd.xmgl.modules.worker.entity.vo.UploadAttendanceByDevDto;
|
||||
@ -12,6 +10,10 @@ import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import java.util.HashMap;
|
||||
|
||||
@RestController
|
||||
@RequestMapping
|
||||
@ -24,16 +26,35 @@ public class UfaceDevApiController {
|
||||
IWorkerAttendanceService workerAttendanceService;
|
||||
|
||||
@ApiOperation(value = "下载白名单(拉取允许通行人员信息)", notes = "下载白名单(拉取允许通行人员信息)", httpMethod = "GET")
|
||||
@GetMapping(value = "/service-address/workers")
|
||||
@GetMapping(value = "/workers")
|
||||
public GetWorkerInfoByDevVo getWorkerInfoByDev(GetWorkerInfoByDevDto dto) {
|
||||
return workerInfoService.getWorkerInfoByDev(dto);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "考勤照片上传", notes = "考勤照片上传", httpMethod = "POST")
|
||||
@PostMapping(value = "/service-address/photo")
|
||||
@PostMapping(value = "/photo")
|
||||
public GetWorkerInfoByDevVo uploadAttendanceByDev(@RequestBody UploadAttendanceByDevDto dto) {
|
||||
return workerAttendanceService.uploadAttendanceByDev(dto);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "时间同步", notes = "时间同步", httpMethod = "POST")
|
||||
@GetMapping(value = "/init")
|
||||
public String init(@ApiIgnore @RequestParam HashMap<String, Object> paramMap) {
|
||||
long time = System.currentTimeMillis() / 1000;
|
||||
return "{\n" +
|
||||
"\"success\": true,\n" +
|
||||
"\"code\": 0,\n" +
|
||||
"\"message\": \"success\",\n" +
|
||||
"\"time\": " + time + ",\n" +
|
||||
"\"data\": {\n" +
|
||||
" \"dgBaseInfo\": {\n" +
|
||||
" },\n" +
|
||||
" \"setting\": {\n" +
|
||||
" }\n" +
|
||||
"},\n" +
|
||||
"\"event\":\"init\"\n" +
|
||||
"}";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.wf.captcha.base.Captcha;
|
||||
import com.zhgd.jeecg.common.api.vo.Result;
|
||||
import com.zhgd.redis.lock.RedisRepository;
|
||||
import com.zhgd.xmgl.modules.basicdata.entity.SystemUser;
|
||||
import com.zhgd.xmgl.modules.xz.captcha.LoginCode;
|
||||
import com.zhgd.xmgl.modules.xz.captcha.LoginCodeEnum;
|
||||
import com.zhgd.xmgl.modules.xz.captcha.LoginProperties;
|
||||
@ -22,7 +23,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -145,7 +145,7 @@ public class XzRegistryController {
|
||||
captchaValue = captchaValue.split("\\.")[0];
|
||||
}
|
||||
// 保存
|
||||
redisRepository.set(uuid, captchaValue, loginProperties.getLoginCode().getExpiration());
|
||||
redisRepository.set(uuid, captchaValue, loginProperties.getLoginCode().getExpiration() * 60);
|
||||
// 验证码信息
|
||||
Map<String, Object> imgResult = new HashMap<String, Object>(2) {{
|
||||
put("img", captcha.toBase64());
|
||||
@ -169,4 +169,10 @@ public class XzRegistryController {
|
||||
public static void main(String[] args) {
|
||||
System.out.println(DateUtil.parse("2024-03-30").getTime() / 1000);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "根据账号查询注册邮箱", notes = "根据账号查询注册邮箱", httpMethod = "POST")
|
||||
@PostMapping(value = "/getRegistryEmail")
|
||||
public Result<HashMap<String, Object>> getRegistryEmail(@RequestBody SystemUser systemUser) {
|
||||
return Result.success(xzRegistryService.getRegistryEmail(systemUser));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.zhgd.xmgl.modules.xz.service;
|
||||
|
||||
import com.zhgd.xmgl.modules.basicdata.entity.SystemUser;
|
||||
import com.zhgd.xmgl.modules.xz.entity.XzRegistry;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
@ -26,4 +27,6 @@ public interface IXzRegistryService extends IService<XzRegistry> {
|
||||
void delete(String id);
|
||||
|
||||
void approval(XzRegistry xzRegistry);
|
||||
|
||||
HashMap<String, Object> getRegistryEmail(SystemUser systemUser);
|
||||
}
|
||||
|
||||
@ -6,7 +6,6 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.sun.mail.smtp.SMTPSendFailedException;
|
||||
import com.zhgd.jeecg.common.execption.OpenAlertException;
|
||||
import com.zhgd.jeecg.common.system.query.QueryGenerator;
|
||||
import com.zhgd.xmgl.modules.basicdata.entity.SystemLogoConfig;
|
||||
@ -104,6 +103,7 @@ public class XzRegistryServiceImpl extends ServiceImpl<XzRegistryMapper, XzRegis
|
||||
su.setAccountType(11);
|
||||
su.setHeadquartersSn(xz.getHeadquartersSn());
|
||||
systemUserService.saveSystemUser(su);
|
||||
xz.setApprovalProcess(2);
|
||||
baseMapper.insert(xz);
|
||||
} else if (Objects.equals(xz.getAccountType(), 1)) {
|
||||
xz.setId(null);
|
||||
@ -167,5 +167,19 @@ public class XzRegistryServiceImpl extends ServiceImpl<XzRegistryMapper, XzRegis
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<String, Object> getRegistryEmail(SystemUser systemUser) {
|
||||
XzRegistry xzRegistry = xzRegistryMapper.selectOne(new LambdaQueryWrapper<XzRegistry>()
|
||||
.eq(XzRegistry::getAccount, systemUser.getAccount())
|
||||
.eq(XzRegistry::getApprovalProcess, 2)
|
||||
.last("order by create_time desc limit 1")
|
||||
);
|
||||
if (xzRegistry == null) {
|
||||
throw new OpenAlertException("账号未注册成功");
|
||||
}
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("email", xzRegistry.getEmail());
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -269,8 +269,9 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
.antMatchers("/xmgl/smartBeamFieldMaintainData/**").permitAll()
|
||||
.antMatchers("/xmgl/smartBeamFieldMakeBeamPedestal/list").permitAll()
|
||||
.antMatchers("/xmgl/smartBeamFieldBeam/countSmartBeamFieldBeam").permitAll()
|
||||
.antMatchers("/service-address/workers").permitAll()
|
||||
.antMatchers("/service-address/photo").permitAll()
|
||||
.antMatchers("/workers").permitAll()
|
||||
.antMatchers("/photo").permitAll()
|
||||
.antMatchers("/init").permitAll()
|
||||
.antMatchers("/xmgl/sewageData/add").permitAll()
|
||||
.antMatchers("/xmgl/rtTool/updateRtToolStatus").permitAll()
|
||||
.antMatchers("/xmgl/rtWorkTicket/countRtWorkTicket").permitAll()
|
||||
@ -347,6 +348,11 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
.antMatchers("/xmgl/exteriorScaffoldingMonitorType/page").permitAll()
|
||||
.antMatchers("/xmgl/exteriorScaffoldingMonitorType/selectMonitorTypeCount").permitAll()
|
||||
.antMatchers("/xmgl/hikvision/eventCallback").permitAll()
|
||||
.antMatchers("/xmgl/systemUser/xz/checkAccount").permitAll()
|
||||
.antMatchers("/xmgl/xzRegistry/getRegistryEmail").permitAll()
|
||||
.antMatchers("/xmgl/systemUser/getEmailCodeByAccount").permitAll()
|
||||
.antMatchers("/xmgl/systemUser/resetPwValidCode").permitAll()
|
||||
.antMatchers("/xmgl/systemUser/resetPwByEmail").permitAll()
|
||||
.antMatchers(HttpMethod.OPTIONS, "/**").anonymous()
|
||||
.anyRequest().authenticated() // 剩下所有的验证都需要验证.
|
||||
.and()
|
||||
|
||||
@ -4,6 +4,8 @@ import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class NumberUtils {
|
||||
/**
|
||||
* 除以
|
||||
@ -124,4 +126,24 @@ public class NumberUtils {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成数字随机数
|
||||
*
|
||||
* @param place 定义随机数的位数
|
||||
*/
|
||||
public static String randomNum(int place) {
|
||||
String base = "0123456789";
|
||||
StringBuffer sb = new StringBuffer();
|
||||
Random rd = new Random();
|
||||
for (int i = 0; i < place; i++) {
|
||||
sb.append(base.charAt(rd.nextInt(base.length())));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(randomNum(6));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user