zhanghua
2025-08-22 89ad0fa748b1773d58822290e4822a4bbbb1d9f9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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();
 
    }
}