添加大屏重定向

main
吴顺杰 1 month ago
parent 10d02198a5
commit 79447032d0

@ -16,6 +16,13 @@
</description>
<dependencies>
<!--jasypt加密-->
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>3.0.5</version>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-openapi2-spring-boot-starter</artifactId>
@ -27,7 +34,7 @@
<optional>true</optional> <!-- 表示依赖不会传递 -->
</dependency>
<!-- Mysql驱动包 -->
<!-- Mysql驱动包 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
@ -43,7 +50,7 @@
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.16</version>
<version>5.8.25</version>
</dependency>
<!-- 定时任务-->
@ -81,15 +88,15 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.1.0</version>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<warName>${project.artifactId}</warName>
</configuration>
</plugin>
</configuration>
</plugin>
</plugins>
<finalName>${project.artifactId}</finalName>
</build>

@ -0,0 +1,68 @@
package com.ruoyi.tcZz.controller;
import cn.hutool.http.HttpRequest;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.tcZz.utils.SecretUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.net.URLEncoder;
/**
*
*
* @author wu
* @since 2024/8/6 4:53
*/
@Api(tags = "对接大屏登录接口")
@RestController
@RequestMapping("/tcZz/networkEcology/singleLogin")
public class SingleLoginController extends BaseController {
/**
* token
*
* @param userName
* @param password
* @return token
* @throws Exception
*/
public static String getToken(String userName, String password) throws Exception {
return SecretUtil.jasyptSymmetry(userName + "#" + password + "#" + System.currentTimeMillis() / 1000, SecretUtil.HMAC_SHA1);
}
/**
* 1
*
* @return
*/
@ApiOperation(value = "对接大屏登录接口1")
@GetMapping("/login1")
public AjaxResult login1(String[] args) throws Exception {
String token = getToken("admin", "59a984baa2991e4adcc4d307aa967b2516494386");
String encodeToken = URLEncoder.encode(token, "UTF-8");
String s = "https://2.35.38.240/api/v2/singleLogin?" + "token=" + encodeToken + "&url=https://2.35.38.240/dasv/preview/4mj2a4fjqccg";
return AjaxResult.success((Object) s);
}
/**
* 1
*
* @return
*/
@ApiOperation(value = "对接大屏登录接口2")
@GetMapping("/login2")
public AjaxResult login2(String[] args) throws Exception {
String token = getToken("admin", "59a984baa2991e4adcc4d307aa967b2516494386");
String encodeToken = URLEncoder.encode(token, "UTF-8");
String s = "https://2.35.38.240/api/v2/singleLogin?" + "token=" + encodeToken + "&url=https://2.35.38.240/dasv/preview/4mj2bpr9ccn4";
return AjaxResult.success((Object) s);
}
}

@ -0,0 +1,277 @@
package com.ruoyi.tcZz.utils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.jasypt.util.text.BasicTextEncryptor;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
import javax.crypto.Cipher;
import javax.crypto.Mac;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.security.DigestInputStream;
import java.security.Key;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;
@Slf4j
public class SecretUtil {
public static final String TYPE_AES = "aes";
public static final String TYPE_DES = "des";
public static final String HMAC_MD5 = "HmacMD5";
public static final String HMAC_SHA1 = "HmacSha1";
private SecretUtil() {
}
/**
* sha1
*
* @param str
* @return
* @throws Exception
*/
public static String digestSha1(String str) {
try {
MessageDigest md = MessageDigest.getInstance("sha1");//md5
md.update(str.getBytes());
return toHexString(md.digest());
} catch (Exception e) {
log.warn("字符串加密失败 {}", e.getMessage(), e);
return "";
}
}
/**
* sha1
*
* @param str
* @return
* @throws Exception
*/
public static String digestSha256(String str) {
try {
MessageDigest md = MessageDigest.getInstance("sha256");//md5
md.update(str.getBytes());
return toHexString(md.digest());
} catch (Exception e) {
log.warn("字符串加密失败 {}", e.getMessage(), e);
return "";
}
}
/**
* md5
*
* @param str
* @return
* @throws Exception
*/
public static String digestMd5(String str) throws Exception {
MessageDigest md = MessageDigest.getInstance("md5");//md5
md.update(str.getBytes(StandardCharsets.UTF_8));
return toHexString(md.digest());
}
/**
* <EFBFBD>?sha1
*
* @param file
* @return
* @throws Exception
*/
public static String digestFile(File file) throws Exception {
InputStream is = null;
DigestInputStream dis = null;
MessageDigest md = MessageDigest.getInstance("sha1");//md5
try {
is = Files.newInputStream(file.toPath());
dis = new DigestInputStream(is, md);
byte[] buf = new byte[1024];
//即使不用<EFBC8C>?<3F><>将该流读<E6B581>?<3F><>
while (dis.read(buf) != -1) {
}
} finally {
IOUtils.closeQuietly(dis);
IOUtils.closeQuietly(is);
}
return toHexString(md.digest());
}
/**
*
*
* @param file
* @param algorithm
* @return
* @throws Exception
*/
public static String digestFile(File file,String algorithm) {
InputStream is = null;
try {
MessageDigest md = MessageDigest.getInstance(algorithm);//md5
is = Files.newInputStream(file.toPath());
byte[] buf = new byte[1024];
int numRead = 0;
while ((numRead = is.read(buf)) > 0) {
md.update(buf,0,numRead);
}
return toHexString(md.digest());
} catch (NoSuchAlgorithmException | IOException e) {
e.printStackTrace();
} finally {
IOUtils.closeQuietly(is);
}
return null;
}
/**
* 使jasypt
*
* @param content
* @param key
* @return
* @throws Exception
*/
public static String jasyptSymmetry(String content, String key) throws Exception {
BasicTextEncryptor enc = new BasicTextEncryptor();
enc.setPassword(key);
return enc.encrypt(content);
}
/**
* 使jasypt
*
* @param content
* @param key
* @return
* @throws Exception
*/
public static String jasyptDecrypt(String content, String key) {
log.info("content:{}, key:{}", content, key );
BasicTextEncryptor enc = new BasicTextEncryptor();
enc.setPassword(key);
return enc.decrypt(content);
}
/**
*
*
* @param type
* @param content
* @param keys
* @return
* @throws Exception
*/
public static byte[] symmetryEncrypt(String type, byte[] content, byte[] keys) throws Exception {
Cipher encryptCipher = Cipher.getInstance(type);
encryptCipher.init(Cipher.ENCRYPT_MODE, getKey(keys, type));
return encryptCipher.doFinal(content);
}
/**
*
*
* @param type <EFBFBD>?TYPE_...
* @param content
* @param keys
* @return
* @throws Exception
*/
public static byte[] decryptEncrypt(String type, byte[] content, byte[] keys) throws Exception {
Cipher decryptCipher = Cipher.getInstance(type);
decryptCipher.init(Cipher.DECRYPT_MODE, getKey(keys, type));
return decryptCipher.doFinal(content);
}
/**
* HMAC
*
* @param type <EFBFBD>?HMAC_....
* @param content
* @param keys
* @return
* @throws Exception
*/
public static String encryptHMAC(String type, byte[] content, byte[] keys) throws Exception {
SecretKey secretKey = new SecretKeySpec(keys, type);
Mac mac = Mac.getInstance(secretKey.getAlgorithm());
mac.init(secretKey);
return toHexString(mac.doFinal(content));
}
/*
* ()<EFBFBD>?es<EFBFBD>?aes<EFBFBD>?6<EFBFBD>?
* @param keyStr
* @return
*/
private static Key getKey(byte[] keyBytes, String type) {
int len = "des".equalsIgnoreCase(type) ? 8 : 16;
byte[] array = new byte[len];
System.arraycopy(keyBytes, 0, array, 0, Math.min(keyBytes.length, len));
return new SecretKeySpec(array, type);
}
/*
* byte[] 16
* @param pb
* @return
*/
private static String toHexString(byte[] pb) {
StringBuilder sb = new StringBuilder();
for (byte b : pb) {
int val = b & 0xff;
if (val < 0x10) {
sb.append('0');
}
sb.append(Integer.toHexString(val));
}
return sb.toString();
}
public static String bytesToBase64(byte[] bArray) {
if (bArray == null) {
return "";
}
return new BASE64Encoder().encode(bArray);
}
public static byte[] base64ToBytes(String str) throws IOException {
BASE64Decoder decoder = new BASE64Decoder();
return decoder.decodeBuffer(str);
}
public static byte[] decode(String str) throws Exception {
byte[] bytes = null;
BASE64Decoder decoder = new BASE64Decoder();
bytes = decoder.decodeBuffer(str);
return bytes;
}
public static String encode(byte[] bytes) {
BASE64Encoder encoder = new BASE64Encoder();
return encoder.encode(bytes);
}
public static String aes_128_cfb(String key,String content) throws Exception {
key = StringUtils.isBlank(key) ? "a94a8fe5ccb19ba6" : key;
SecretKey secretKey = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "AES");
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
return Base64.getEncoder().encodeToString(cipher.doFinal(content.getBytes(StandardCharsets.UTF_8)));
}
public static void main(String[] argc) {
System.out.println(SecretUtil.digestSha1("iS%4Rh37g3"));
}
}
Loading…
Cancel
Save