123
This commit is contained in:
1 parent
7530acde5b
commit
f91140ea33
4 files changed
+116
-4
No files matched your search
@@ -0,0 +1,82 @@
|
|||||||
|
package com.ruoyi.common.utils;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
import java.util.Base64;
|
||||||
|
|
||||||
|
public class TokenUtil {
|
||||||
|
|
||||||
|
private static final String SECRET = "lu7213";
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
String token = TokenUtil.generateToken("admin", "123456");
|
||||||
|
System.out.println(token);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 生成24小时token
|
||||||
|
*/
|
||||||
|
public static String generateToken(String username, String password) {
|
||||||
|
long expireAt = System.currentTimeMillis() + 24 * 60 * 60 * 1000L;
|
||||||
|
|
||||||
|
String rawCredential = Base64.getEncoder().encodeToString(
|
||||||
|
(username + ":" + password).getBytes(StandardCharsets.UTF_8)
|
||||||
|
);
|
||||||
|
|
||||||
|
String sign = md5(rawCredential + ":" + expireAt + ":" + SECRET);
|
||||||
|
|
||||||
|
String payload = rawCredential + ":" + expireAt + ":" + sign;
|
||||||
|
|
||||||
|
return Base64.getUrlEncoder()
|
||||||
|
.withoutPadding()
|
||||||
|
.encodeToString(payload.getBytes(StandardCharsets.UTF_8));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验token
|
||||||
|
*/
|
||||||
|
public static boolean validateToken(String username, String password,String token) {
|
||||||
|
try {
|
||||||
|
String rawCredential = Base64.getEncoder().encodeToString(
|
||||||
|
(username + ":" + password).getBytes(StandardCharsets.UTF_8)
|
||||||
|
);
|
||||||
|
String decoded = new String(
|
||||||
|
Base64.getUrlDecoder().decode(token),
|
||||||
|
StandardCharsets.UTF_8
|
||||||
|
);
|
||||||
|
String[] parts = decoded.split(":");
|
||||||
|
if (parts.length != 3) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(!parts[0].equals(rawCredential)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
String expireStr = parts[1];
|
||||||
|
String sign = parts[2] ;
|
||||||
|
long expireAt = Long.parseLong(expireStr);
|
||||||
|
if (System.currentTimeMillis() > expireAt) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
String expectedSign = md5(rawCredential + ":" + expireAt + ":" + SECRET);
|
||||||
|
|
||||||
|
return expectedSign.equals(sign);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String md5(String str) {
|
||||||
|
try {
|
||||||
|
byte[] digest = MessageDigest.getInstance("MD5")
|
||||||
|
.digest(str.getBytes(StandardCharsets.UTF_8));
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (byte b : digest) {
|
||||||
|
sb.append(String.format("%02x", b));
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,8 @@ import org.apache.commons.lang3.builder.ToStringBuilder;
|
|||||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||||
import com.ruoyi.common.annotation.Excel;
|
import com.ruoyi.common.annotation.Excel;
|
||||||
import com.ruoyi.common.core.domain.BaseEntity;
|
import com.ruoyi.common.core.domain.BaseEntity;
|
||||||
|
import org.springframework.data.annotation.Transient;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
/**
|
/**
|
||||||
* 大漠代理对象 dm_playerent
|
* 大漠代理对象 dm_playerent
|
||||||
@@ -69,12 +71,33 @@ public class DmPlayerent extends BaseEntity
|
|||||||
/** 当前任务 */
|
/** 当前任务 */
|
||||||
@Excel(name = "当前任务")
|
@Excel(name = "当前任务")
|
||||||
private String winOneCurTask;
|
private String winOneCurTask;
|
||||||
|
/** 当前任务 */
|
||||||
|
@Excel(name = "secret")
|
||||||
|
private String secret;
|
||||||
/** 当前任务 */
|
/** 当前任务 */
|
||||||
@Excel(name = "当前任务")
|
@Excel(name = "当前任务")
|
||||||
private String winTwoCurTask;
|
private String winTwoCurTask;
|
||||||
|
@Excel(name = "mjpeg播放地址")
|
||||||
|
@Transient
|
||||||
|
private transient String mjpegUrl;
|
||||||
|
|
||||||
public void setId(Long id)
|
public String getSecret() {
|
||||||
|
return secret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSecret(String secret) {
|
||||||
|
this.secret = secret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMjpegUrl() {
|
||||||
|
return mjpegUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMjpegUrl(String mjpegUrl) {
|
||||||
|
this.mjpegUrl = mjpegUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id)
|
||||||
{
|
{
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-1
@@ -9,6 +9,7 @@ import com.luqj.util.HttpHelper;
|
|||||||
import com.ruoyi.common.select.SelectItem;
|
import com.ruoyi.common.select.SelectItem;
|
||||||
import com.ruoyi.common.utils.DateUtils;
|
import com.ruoyi.common.utils.DateUtils;
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
|
import com.ruoyi.common.utils.TokenUtil;
|
||||||
import com.ruoyi.system.domain.DmOperateVo;
|
import com.ruoyi.system.domain.DmOperateVo;
|
||||||
import com.ruoyi.system.domain.DmPlayerConfigPlus;
|
import com.ruoyi.system.domain.DmPlayerConfigPlus;
|
||||||
import com.ruoyi.system.domain.DmPlayerent;
|
import com.ruoyi.system.domain.DmPlayerent;
|
||||||
@@ -154,7 +155,11 @@ public class DmPlayerentServiceImpl extends ServiceImpl<DmPlayerentMapper, DmPla
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public DmPlayerent selectDmPlayerentById(Long id) {
|
public DmPlayerent selectDmPlayerentById(Long id) {
|
||||||
return dmPlayerentMapper.selectDmPlayerentById(id);
|
DmPlayerent dmPlayerent = dmPlayerentMapper.selectDmPlayerentById(id);
|
||||||
|
dmPlayerent.setMjpegUrl("http://" + dmPlayerent.getIp()+":8888/stream?token="
|
||||||
|
+ TokenUtil.generateToken(dmPlayerent.getId()+"",dmPlayerent.getSecret()));
|
||||||
|
dmPlayerent.setSecret(null);
|
||||||
|
return dmPlayerent;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -168,6 +173,7 @@ public class DmPlayerentServiceImpl extends ServiceImpl<DmPlayerentMapper, DmPla
|
|||||||
List<DmPlayerent> list = dmPlayerentMapper.selectDmPlayerentList(dmPlayerent);
|
List<DmPlayerent> list = dmPlayerentMapper.selectDmPlayerentList(dmPlayerent);
|
||||||
List<Long> ids = new ArrayList<>();
|
List<Long> ids = new ArrayList<>();
|
||||||
for (DmPlayerent playerent : list) {
|
for (DmPlayerent playerent : list) {
|
||||||
|
playerent.setSecret(null);
|
||||||
ids.add(playerent.getId());
|
ids.add(playerent.getId());
|
||||||
}
|
}
|
||||||
if (!ids.isEmpty()) {
|
if (!ids.isEmpty()) {
|
||||||
|
|||||||
@@ -22,10 +22,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<result property="winOneImgPath" column="win_one_img_path" />
|
<result property="winOneImgPath" column="win_one_img_path" />
|
||||||
<result property="winOneCurTask" column="win_one_cur_task" />
|
<result property="winOneCurTask" column="win_one_cur_task" />
|
||||||
<result property="winTwoCurTask" column="win_two_cur_task" />
|
<result property="winTwoCurTask" column="win_two_cur_task" />
|
||||||
|
<result property="secret" column="secret" />
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<sql id="selectDmPlayerentVo">
|
<sql id="selectDmPlayerentVo">
|
||||||
select id, accountId, name, create_time, update_time, online_status, player_status, ip, http_port, win_one_hwnd, win_one_info, win_two_hwnd, win_two_info, win_two_img_path, win_one_img_path, win_one_cur_task, win_two_cur_task from dm_playerent
|
select id, accountId, name, secret,create_time, update_time, online_status, player_status, ip, http_port, win_one_hwnd, win_one_info, win_two_hwnd, win_two_info, win_two_img_path, win_one_img_path, win_one_cur_task, win_two_cur_task from dm_playerent
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
<select id="selectDmPlayerentList" parameterType="DmPlayerent" resultMap="DmPlayerentResult">
|
<select id="selectDmPlayerentList" parameterType="DmPlayerent" resultMap="DmPlayerentResult">
|
||||||
|
|||||||
Reference in new issue
Block a user