智慧工程
This commit is contained in:
parent
2a4a29826f
commit
1b76407711
|
|
@ -34,6 +34,28 @@
|
||||||
<artifactId>sgzb-common-redis</artifactId>
|
<artifactId>sgzb-common-redis</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.hutool</groupId>
|
||||||
|
<artifactId>hutool-all</artifactId>
|
||||||
|
<version>4.6.16</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.fastjson2</groupId>
|
||||||
|
<artifactId>fastjson2</artifactId>
|
||||||
|
<version>2.0.43</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- <dependency>-->
|
||||||
|
<!-- <groupId>org.springframework.boot</groupId>-->
|
||||||
|
<!-- <artifactId>spring-boot-configuration-processor</artifactId>-->
|
||||||
|
<!-- <version>3.1.0</version>-->
|
||||||
|
<!-- </dependency>-->
|
||||||
|
<!-- <dependency>-->
|
||||||
|
<!-- <groupId>com.alibaba</groupId>-->
|
||||||
|
<!-- <artifactId>fastjson</artifactId>-->
|
||||||
|
<!-- <version>2.0.25</version>-->
|
||||||
|
<!-- <scope>compile</scope>-->
|
||||||
|
<!-- </dependency>-->
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,49 @@
|
||||||
|
package com.bonus.sgzb.common.security.utils;
|
||||||
|
|
||||||
|
import cn.hutool.crypto.Mode;
|
||||||
|
import cn.hutool.crypto.Padding;
|
||||||
|
import cn.hutool.crypto.symmetric.AES;
|
||||||
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class GetTokenByAppKey {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
String token = getToken();
|
||||||
|
System.err.println(token);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取Token
|
||||||
|
* @return Token
|
||||||
|
* appKey、aesKey联系智慧工程系统提供
|
||||||
|
*/
|
||||||
|
private static String getToken() {
|
||||||
|
String appKey = "abc123";
|
||||||
|
String aesKey = "abcdefghijklmnop";
|
||||||
|
Map<String, Object> signatureMap = new HashMap<String, Object>();
|
||||||
|
signatureMap.put("appKey", appKey);
|
||||||
|
signatureMap.put("timestamp", String.valueOf(System.currentTimeMillis()));
|
||||||
|
Iterator<String> iterator = signatureMap.keySet().iterator();
|
||||||
|
//Map 转成 JSONObject 字符串
|
||||||
|
JSONObject jsonObj = new JSONObject(signatureMap);
|
||||||
|
String jsonStr = jsonObj.toJSONString();
|
||||||
|
|
||||||
|
AES aes = new AES(Mode.ECB, Padding.PKCS5Padding, aesKey.getBytes());
|
||||||
|
byte[] aesByte = aes.encrypt(jsonStr.getBytes(StandardCharsets.UTF_8));
|
||||||
|
String token = byteToHex(aesByte);
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String byteToHex(byte[] bytes) {
|
||||||
|
String strHex = "";
|
||||||
|
StringBuilder sb = new StringBuilder("");
|
||||||
|
for (int n = 0; n < bytes.length; n++) {
|
||||||
|
strHex = Integer.toHexString(bytes[n] & 0xFF);
|
||||||
|
sb.append((strHex.length() == 1) ? "0" + strHex : strHex); // 每个字节由两个字符表示,位数不够,高位补0
|
||||||
|
}
|
||||||
|
return sb.toString().trim();
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue