fei.wang
2024-04-15 61747a14819075bf6da2c1597b6c22e22e026686
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
58
59
60
61
62
63
64
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//
 
package com.flow.controller;
 
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
@RestController
@RequestMapping({"/hxzk"})
public class ProxyHandler {
    public ProxyHandler() {
    }
 
    @GetMapping({"wlk"})
    public void wlk(HttpServletResponse response, String Timestamp, String Nonce, String targetUrl, String targetUrl1) throws IOException, NoSuchAlgorithmException, InvalidKeyException {
        String accessKey = "448c2cedcdce41428a290d144e81ab6e";
        String stringSignTemp = accessKey + Nonce + Timestamp;
        String accessSecret = "RgoIWycMYGmQfrLwLuT2VWawAhwMO8w7P9zh2dZp";
        Mac sha256Hmac = Mac.getInstance("HmacSHA256");
        SecretKeySpec secretKeySpec = new SecretKeySpec(accessSecret.getBytes(StandardCharsets.UTF_8), "HmacSHA256");
        sha256Hmac.init(secretKeySpec);
        byte[] hmacBytes = sha256Hmac.doFinal(stringSignTemp.getBytes(StandardCharsets.UTF_8));
        String sign = Base64.getEncoder().encodeToString(hmacBytes);
        targetUrl = targetUrl + targetUrl1;
        URL url = new URL(targetUrl);
        HttpURLConnection connection = (HttpURLConnection)url.openConnection();
        connection.setRequestProperty("Accept-Charset", "UTF-8");
        connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
        connection.setRequestProperty("Access-Control-Allow-Origin", "http://localhost:8080");
        connection.setRequestProperty("AccessKey", accessKey);
        connection.setRequestProperty("Nonce", Nonce);
        connection.setRequestProperty("Timestamp", Timestamp);
        connection.setRequestProperty("Sign", sign);
        connection.connect();
        BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
        StringBuilder response1 = new StringBuilder();
 
        String line;
        while((line = reader.readLine()) != null) {
            response1.append(line);
        }
 
        reader.close();
        connection.disconnect();
        response.setContentType("application/json; charset=UTF-8");
        response.getWriter().write(response1.toString());
    }
}