新增:重置短信验证码接口
This commit is contained in:
@@ -4,17 +4,24 @@ import cn.hutool.core.util.StrUtil;
|
|||||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||||
import com.gxwebsoft.common.core.utils.CacheClient;
|
import com.gxwebsoft.common.core.utils.CacheClient;
|
||||||
import com.gxwebsoft.common.core.utils.CommonUtil;
|
import com.gxwebsoft.common.core.utils.CommonUtil;
|
||||||
|
import com.gxwebsoft.common.core.utils.RedisUtil;
|
||||||
import com.gxwebsoft.common.core.web.*;
|
import com.gxwebsoft.common.core.web.*;
|
||||||
import com.gxwebsoft.common.system.entity.AccessKey;
|
import com.gxwebsoft.common.system.entity.AccessKey;
|
||||||
import com.gxwebsoft.common.system.param.AccessKeyParam;
|
import com.gxwebsoft.common.system.param.AccessKeyParam;
|
||||||
import com.gxwebsoft.common.system.service.AccessKeyService;
|
import com.gxwebsoft.common.system.service.AccessKeyService;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import static com.gxwebsoft.common.core.constants.WebsiteConstants.CACHE_KEY_VERIFICATION_CODE_BY_DEV_SMS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 访问凭证管理控制器
|
* 访问凭证管理控制器
|
||||||
@@ -26,125 +33,140 @@ import java.util.List;
|
|||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/system/access-key")
|
@RequestMapping("/api/system/access-key")
|
||||||
public class AccessKeyController extends BaseController {
|
public class AccessKeyController extends BaseController {
|
||||||
@Resource
|
@Resource
|
||||||
private AccessKeyService accessKeyService;
|
private AccessKeyService accessKeyService;
|
||||||
@Resource
|
@Resource
|
||||||
private CacheClient cacheClient;
|
private CacheClient cacheClient;
|
||||||
|
@Resource
|
||||||
|
private RedisUtil redisUtil;
|
||||||
|
|
||||||
@PreAuthorize("hasAuthority('sys:accessKey:list')")
|
@PreAuthorize("hasAuthority('sys:accessKey:list')")
|
||||||
@OperationLog
|
@OperationLog
|
||||||
@ApiOperation("分页查询访问凭证")
|
@ApiOperation("分页查询访问凭证")
|
||||||
@GetMapping("/page")
|
@GetMapping("/page")
|
||||||
public ApiResult<PageResult<AccessKey>> page(AccessKeyParam param) {
|
public ApiResult<PageResult<AccessKey>> page(AccessKeyParam param) {
|
||||||
// 使用关联查询
|
// 使用关联查询
|
||||||
final PageResult<AccessKey> accessKeyPageResult = accessKeyService.pageRel(param);
|
final PageResult<AccessKey> accessKeyPageResult = accessKeyService.pageRel(param);
|
||||||
if (param.getCode() != null) {
|
if (param.getCode() != null) {
|
||||||
// 短信验证码校验
|
// 短信验证码校验
|
||||||
String code = cacheClient.get(param.getPhone(), String.class);
|
String code = cacheClient.get(param.getPhone(), String.class);
|
||||||
if (StrUtil.equals(code,param.getCode()) || "128880".equals(param.getCode())) {
|
if (StrUtil.equals(code, param.getCode()) || "128880".equals(param.getCode())) {
|
||||||
return success(accessKeyPageResult);
|
return success(accessKeyPageResult);
|
||||||
}
|
|
||||||
return fail("短信验证码不正确",null);
|
|
||||||
}
|
}
|
||||||
// 默认不给查看AccessSecret
|
return fail("短信验证码不正确", null);
|
||||||
accessKeyPageResult.getList().forEach( d -> {
|
|
||||||
d.setAccessSecret(null);
|
|
||||||
});
|
|
||||||
return success(accessKeyPageResult);
|
|
||||||
}
|
}
|
||||||
|
// 默认不给查看AccessSecret
|
||||||
|
accessKeyPageResult.getList().forEach(d -> {
|
||||||
|
d.setAccessSecret(null);
|
||||||
|
});
|
||||||
|
return success(accessKeyPageResult);
|
||||||
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAuthority('sys:accessKey:list')")
|
@PreAuthorize("hasAuthority('sys:accessKey:list')")
|
||||||
@OperationLog
|
@OperationLog
|
||||||
@ApiOperation("查询全部访问凭证管理")
|
@ApiOperation("查询全部访问凭证管理")
|
||||||
@GetMapping()
|
@GetMapping()
|
||||||
public ApiResult<List<AccessKey>> list(AccessKeyParam param) {
|
public ApiResult<List<AccessKey>> list(AccessKeyParam param) {
|
||||||
PageParam<AccessKey, AccessKeyParam> page = new PageParam<>(param);
|
PageParam<AccessKey, AccessKeyParam> page = new PageParam<>(param);
|
||||||
page.setDefaultOrder("create_time desc");
|
page.setDefaultOrder("create_time desc");
|
||||||
return success(accessKeyService.list(page.getOrderWrapper()));
|
return success(accessKeyService.list(page.getOrderWrapper()));
|
||||||
// 使用关联查询
|
// 使用关联查询
|
||||||
//return success(accessKeyService.listRel(param));
|
//return success(accessKeyService.listRel(param));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAuthority('sys:accessKey:list')")
|
@PreAuthorize("hasAuthority('sys:accessKey:list')")
|
||||||
@OperationLog
|
@OperationLog
|
||||||
@ApiOperation("根据id查询访问凭证管理")
|
@ApiOperation("根据id查询访问凭证管理")
|
||||||
@GetMapping("/{id}")
|
@GetMapping("/{id}")
|
||||||
public ApiResult<AccessKey> get(@PathVariable("id") Integer id) {
|
public ApiResult<AccessKey> get(@PathVariable("id") Integer id) {
|
||||||
return success(accessKeyService.getById(id));
|
return success(accessKeyService.getById(id));
|
||||||
// 使用关联查询
|
// 使用关联查询
|
||||||
//return success(accessKeyService.getByIdRel(id));
|
//return success(accessKeyService.getByIdRel(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAuthority('sys:accessKey:list')")
|
@PreAuthorize("hasAuthority('sys:accessKey:list')")
|
||||||
@OperationLog
|
@OperationLog
|
||||||
@ApiOperation("添加访问凭证管理")
|
@ApiOperation("添加访问凭证管理")
|
||||||
@PostMapping()
|
@PostMapping()
|
||||||
public ApiResult<?> save(@RequestBody AccessKey accessKey) {
|
public ApiResult<?> save(@RequestBody AccessKey accessKey) {
|
||||||
final int count = accessKeyService.count();
|
final int count = accessKeyService.count();
|
||||||
if (count >= 5) {
|
if (count >= 5) {
|
||||||
return fail("当前账号只能绑定 5 个 AccessKey");
|
return fail("当前账号只能绑定 5 个 AccessKey");
|
||||||
}
|
|
||||||
accessKey.setAccessKey("AI" + CommonUtil.randomUUID16());
|
|
||||||
accessKey.setAccessSecret(CommonUtil.randomUUID16().concat(CommonUtil.randomUUID16()));
|
|
||||||
if (accessKeyService.save(accessKey)) {
|
|
||||||
return success("创建成功");
|
|
||||||
}
|
|
||||||
return fail("创建失败");
|
|
||||||
}
|
}
|
||||||
|
accessKey.setAccessKey("AI" + CommonUtil.randomUUID16());
|
||||||
|
accessKey.setAccessSecret(CommonUtil.randomUUID16().concat(CommonUtil.randomUUID16()));
|
||||||
|
if (accessKeyService.save(accessKey)) {
|
||||||
|
return success("创建成功");
|
||||||
|
}
|
||||||
|
return fail("创建失败");
|
||||||
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAuthority('sys:accessKey:update')")
|
@PreAuthorize("hasAuthority('sys:accessKey:update')")
|
||||||
@OperationLog
|
@OperationLog
|
||||||
@ApiOperation("修改访问凭证管理")
|
@ApiOperation("修改访问凭证管理")
|
||||||
@PutMapping()
|
@PutMapping()
|
||||||
public ApiResult<?> update(@RequestBody AccessKey accessKey) {
|
public ApiResult<?> update(@RequestBody AccessKey accessKey) {
|
||||||
if (accessKeyService.updateById(accessKey)) {
|
if (accessKeyService.updateById(accessKey)) {
|
||||||
return success("修改成功");
|
return success("修改成功");
|
||||||
}
|
|
||||||
return fail("修改失败");
|
|
||||||
}
|
}
|
||||||
|
return fail("修改失败");
|
||||||
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAuthority('sys:accessKey:remove')")
|
@PreAuthorize("hasAuthority('sys:accessKey:remove')")
|
||||||
@OperationLog
|
@OperationLog
|
||||||
@ApiOperation("删除访问凭证管理")
|
@ApiOperation("删除访问凭证管理")
|
||||||
@DeleteMapping("/{id}")
|
@DeleteMapping("/{id}")
|
||||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||||
if (accessKeyService.removeById(id)) {
|
if (accessKeyService.removeById(id)) {
|
||||||
return success("删除成功");
|
return success("删除成功");
|
||||||
}
|
|
||||||
return fail("删除失败");
|
|
||||||
}
|
}
|
||||||
|
return fail("删除失败");
|
||||||
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAuthority('sys:accessKey:save')")
|
@PreAuthorize("hasAuthority('sys:accessKey:save')")
|
||||||
@OperationLog
|
@OperationLog
|
||||||
@ApiOperation("批量添加访问凭证管理")
|
@ApiOperation("批量添加访问凭证管理")
|
||||||
@PostMapping("/batch")
|
@PostMapping("/batch")
|
||||||
public ApiResult<?> saveBatch(@RequestBody List<AccessKey> list) {
|
public ApiResult<?> saveBatch(@RequestBody List<AccessKey> list) {
|
||||||
if (accessKeyService.saveBatch(list)) {
|
if (accessKeyService.saveBatch(list)) {
|
||||||
return success("添加成功");
|
return success("添加成功");
|
||||||
}
|
|
||||||
return fail("添加失败");
|
|
||||||
}
|
}
|
||||||
|
return fail("添加失败");
|
||||||
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAuthority('sys:accessKey:update')")
|
@PreAuthorize("hasAuthority('sys:accessKey:update')")
|
||||||
@OperationLog
|
@OperationLog
|
||||||
@ApiOperation("批量修改访问凭证管理")
|
@ApiOperation("批量修改访问凭证管理")
|
||||||
@PutMapping("/batch")
|
@PutMapping("/batch")
|
||||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<AccessKey> batchParam) {
|
public ApiResult<?> removeBatch(@RequestBody BatchParam<AccessKey> batchParam) {
|
||||||
if (batchParam.update(accessKeyService, "id")) {
|
if (batchParam.update(accessKeyService, "id")) {
|
||||||
return success("修改成功");
|
return success("修改成功");
|
||||||
}
|
|
||||||
return fail("修改失败");
|
|
||||||
}
|
}
|
||||||
|
return fail("修改失败");
|
||||||
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAuthority('sys:accessKey:remove')")
|
@PreAuthorize("hasAuthority('sys:accessKey:remove')")
|
||||||
@OperationLog
|
@OperationLog
|
||||||
@ApiOperation("批量删除访问凭证管理")
|
@ApiOperation("批量删除访问凭证管理")
|
||||||
@DeleteMapping("/batch")
|
@DeleteMapping("/batch")
|
||||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||||
if (accessKeyService.removeByIds(ids)) {
|
if (accessKeyService.removeByIds(ids)) {
|
||||||
return success("删除成功");
|
return success("删除成功");
|
||||||
}
|
|
||||||
return fail("删除失败");
|
|
||||||
}
|
}
|
||||||
|
return fail("删除失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
@PreAuthorize("hasAuthority('sys:accessKey:resetSMSCode')")
|
||||||
|
@OperationLog
|
||||||
|
@ApiOperation("重置短信验证码")
|
||||||
|
@PostMapping("/resetSMSCode")
|
||||||
|
public ApiResult<?> resetSMSCode() {
|
||||||
|
// 生成短信验证码
|
||||||
|
Random randObj = new Random();
|
||||||
|
String code = Integer.toString(100000 + randObj.nextInt(900000));
|
||||||
|
redisUtil.set(CACHE_KEY_VERIFICATION_CODE_BY_DEV_SMS, code, 5L, TimeUnit.MINUTES);
|
||||||
|
return success("新验证码:".concat(code));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user