62 lines
1.7 KiB
Java
62 lines
1.7 KiB
Java
package com.zhgd.xmgl.util;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.slf4j.Logger;
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
import java.net.URLEncoder;
|
|
import java.security.MessageDigest;
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
|
/**
|
|
* @author 邱平毅
|
|
* @ClassName JinqianmaoUtil
|
|
* @date 2022/8/17 13:43
|
|
* @Version 1.0
|
|
*/
|
|
@Slf4j
|
|
public class JinqianmaoUtil {
|
|
|
|
private JinqianmaoUtil() {
|
|
}
|
|
|
|
// public static final String AK = "GX00003";
|
|
//
|
|
// public static final String SECRET = "4ee100d0-f153-11ec-b06b-0242ac140005";
|
|
//
|
|
// public static final String URL = "https://fjvsaps.jqmkj.com:20020";
|
|
//
|
|
// public static final String token = "APP0000115184376461117ced48f-08b5-11e8-a224-000c292671b9";
|
|
|
|
/**
|
|
* 生成token
|
|
*
|
|
* @return
|
|
* @throws NoSuchAlgorithmException
|
|
*/
|
|
public static String getTokenUrl(Long currentTimeMillis , String AK,String SECRET) {
|
|
byte[] sha1_1 = new byte[0];
|
|
try {
|
|
sha1_1 = encryptsHA1((AK + currentTimeMillis + SECRET).getBytes());
|
|
byte[] sha1_2 = encryptsHA1(sha1_1);
|
|
String token = base64_encode(sha1_2);
|
|
return URLEncoder.encode(token, "utf-8");
|
|
} catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
|
|
e.printStackTrace();
|
|
log.error(e.getMessage());
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public static byte[] encryptsHA1(byte[] data) throws NoSuchAlgorithmException {
|
|
MessageDigest sha = MessageDigest.getInstance("SHA1");
|
|
sha.update(data);
|
|
return sha.digest();
|
|
}
|
|
|
|
public static String base64_encode(byte[] data) {
|
|
return new sun.misc.BASE64Encoder().encode(data);
|
|
}
|
|
|
|
}
|