密钥对接口完善

This commit is contained in:
墨大叔 2024-07-18 18:17:35 +08:00
parent d8b9992b23
commit 49baa39cd1
4 changed files with 37 additions and 25 deletions

View File

@ -88,5 +88,8 @@ public interface AccessService
*/
boolean deleteCache(String accessKey);
AccessApplyVO reset(Long accessId);
/**
* 重置秘钥
*/
String reset(Long accessId);
}

View File

@ -208,7 +208,17 @@ public class AccessServiceImpl implements AccessService
}
@Override
public AccessApplyVO reset(Long accessId) {
return null;
public String reset(Long accessId) {
ServiceUtil.assertion(accessId == null, "秘钥ID不允许为空");
String secret = SecurityUtils.genSecret(64);
Access access = new Access();
access.setAccessId(accessId);
access.setAccessSecret(secret);
int update = accessMapper.updateAccess(access);
ServiceUtil.assertion(update != 1, "重置秘钥失败");
return secret;
}
}

View File

@ -1,17 +0,0 @@
package com.ruoyi.web.controller.api;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 第三方API 设备Controller
* @author wjh
* 2024/7/17
*/
@RestController
@RequestMapping("/openapi/v1/device")
public class ApiDeviceController {
}

View File

@ -1,22 +1,26 @@
package com.ruoyi.web.controller.api;
package com.ruoyi.web.controller.app;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.framework.web.service.SysLoginService;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.ss.access.domain.AccessQuery;
import com.ruoyi.ss.access.domain.AccessVO;
import com.ruoyi.ss.access.service.AccessService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Objects;
/**
* 第三方认证接口
* @author wjh
* 2024/7/17
*/
@RestController
@RequestMapping("/openapi/v1/access")
public class ApiAccessController extends BaseController {
@RequestMapping("/app/access")
public class AppAccessController extends BaseController {
@Autowired
private AccessService accessService;
@ -31,7 +35,19 @@ public class ApiAccessController extends BaseController {
@PutMapping("/{accessId}/reset")
public AjaxResult reset(@PathVariable Long accessId) {
AccessVO access = accessService.selectAccessByAccessId(accessId);
return success(accessService.reset(accessId));
if (access == null || !Objects.equals(access.getUserId(), getUserId())) {
return error("您无权操作");
}
return AjaxResult.success("操作成功", accessService.reset(accessId));
}
@ApiOperation("查询本人秘钥列表")
@GetMapping("/list")
public TableDataInfo list(AccessQuery query) {
query.setUserId(getUserId());
startPage();
List<AccessVO> list = accessService.selectAccessList(query);
return getDataTable(list);
}
}