package org.dromara.web.utils;
|
|
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.http.HttpRequest;
|
import lombok.extern.slf4j.Slf4j;
|
import me.zhyd.oauth.utils.RandomUtil;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.stereotype.Component;
|
|
import java.security.MessageDigest;
|
import java.util.Map;
|
|
@Component
|
@Slf4j
|
public class RZTHttpUtils {
|
|
@Value("${rzt.url}")
|
private String url;
|
|
@Value("${rzt.paasid}")
|
private String paasid;
|
|
@Value("${rzt.paastoken}")
|
private String paastoken;
|
|
|
public String sendGetRequest(String urlPath, Map<String, String> params) throws Exception {
|
|
//获取时间戳:
|
String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
|
|
String nonce = RandomUtil.randomString(20);
|
//获取签名:
|
MessageDigest digest = MessageDigest.getInstance("SHA-256");
|
byte[] hash = digest.digest((timestamp + paastoken + nonce + timestamp).getBytes());
|
StringBuffer hexString = new StringBuffer();
|
for (int i = 0; i < hash.length; i++) {
|
String hex = Integer.toHexString(0xff & hash[i]);
|
if (hex.length() == 1) {
|
hexString.append('0');
|
}
|
hexString.append(hex);
|
}
|
String signature = hexString.toString().toUpperCase();
|
HttpRequest request = HttpRequest.get(url + urlPath)
|
.header("x-rio-paasid", paasid)
|
.header("x-rio-timestamp", timestamp)
|
.header("x-rio-nonce", nonce)
|
.header("x-rio-signature", signature);
|
if (params != null) {
|
request.formStr(params);
|
}
|
log.info(request.toString());
|
return request.execute().body();
|
|
}
|
}
|