|
@@ -37,7 +37,6 @@ import java.time.LocalDateTime;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
import java.util.Objects;
|
|
import java.util.Objects;
|
|
-import java.util.concurrent.ThreadLocalRandom;
|
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import static com.xy.utils.Beans.copy;
|
|
import static com.xy.utils.Beans.copy;
|
|
@@ -205,6 +204,8 @@ public class MercMiniDeviceController {
|
|
@ApiOperation("蓝牙开门-生成授权码")
|
|
@ApiOperation("蓝牙开门-生成授权码")
|
|
public R<Boolean> genCode(@RequestBody @Validated DeviceBluetoothAuthDto.GenCode dto) {
|
|
public R<Boolean> genCode(@RequestBody @Validated DeviceBluetoothAuthDto.GenCode dto) {
|
|
Long deviceId = dto.getDeviceId();
|
|
Long deviceId = dto.getDeviceId();
|
|
|
|
+ //用户输入的
|
|
|
|
+ String authCode = dto.getAuthCode();
|
|
List<Long> myDevices = getMyDevices();
|
|
List<Long> myDevices = getMyDevices();
|
|
if (!myDevices.contains(deviceId)) {
|
|
if (!myDevices.contains(deviceId)) {
|
|
return R.fail("抱歉!您无权对此设备进行授权!");
|
|
return R.fail("抱歉!您无权对此设备进行授权!");
|
|
@@ -226,8 +227,7 @@ public class MercMiniDeviceController {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- //授权码生成
|
|
|
|
- String authCode = getAuthCode();
|
|
|
|
|
|
+
|
|
//缓存
|
|
//缓存
|
|
setCacheAuthCode(deviceId, authCode);
|
|
setCacheAuthCode(deviceId, authCode);
|
|
DeviceBluetoothAuth saveInfo = new DeviceBluetoothAuth()
|
|
DeviceBluetoothAuth saveInfo = new DeviceBluetoothAuth()
|
|
@@ -266,25 +266,12 @@ public class MercMiniDeviceController {
|
|
return R.ok(deviceBluetoothAuthService.saveOrUpdate(deviceBluetoothAuth));
|
|
return R.ok(deviceBluetoothAuthService.saveOrUpdate(deviceBluetoothAuth));
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
- public static final String BASE_NUMBER = "0123456789";
|
|
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* auth-code有效期30分钟,单位:s ,
|
|
* auth-code有效期30分钟,单位:s ,
|
|
*/
|
|
*/
|
|
public static final Integer AUTH_CODE_TIMEOUT = 1800;
|
|
public static final Integer AUTH_CODE_TIMEOUT = 1800;
|
|
|
|
|
|
- /**
|
|
|
|
- * 随机6位数生成
|
|
|
|
- */
|
|
|
|
- public static String getAuthCode() {
|
|
|
|
- StringBuilder sb = new StringBuilder(6);
|
|
|
|
- for (int i = 0; i < 6; i++) {
|
|
|
|
- int num = ThreadLocalRandom.current().nextInt(BASE_NUMBER.length());
|
|
|
|
- sb.append(BASE_NUMBER.charAt(num));
|
|
|
|
- }
|
|
|
|
- return sb.toString();
|
|
|
|
- }
|
|
|
|
|
|
|
|
public static void setCacheAuthCode(Long deviceId, String code) {
|
|
public static void setCacheAuthCode(Long deviceId, String code) {
|
|
RedisService<String> redisService = SpringBeanUtils.getBean(RedisService.class);
|
|
RedisService<String> redisService = SpringBeanUtils.getBean(RedisService.class);
|