xuhy
2024-08-27 b79c0fa3aa4f7dffe18ab419b6cf4ed47ebd22f9
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
package com.ruoyi.account.util.carBrand;
 
import com.cloud.apigateway.sdk.utils.Client;
import com.cloud.apigateway.sdk.utils.Request;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
 
public class CarBrandUtil {
    private static final Logger LOGGER = LoggerFactory.getLogger(CarBrandUtil.class);
    public static   String getBrand() throws Exception {
        // Create a new request.
        Request httpClientRequest = new Request();
        try {
            // Set the request parameters.
            // AppKey, AppSecrect, Method and Url are required parameters.
            // Directly writing AK/SK in code is risky. For security, encrypt your AK/SK and store them in the configuration file or environment variables.
            // In this example, the AK/SK are stored in environment variables for identity authentication. 
            // Before running this example, set environment variables HUAWEICLOUD_SDK_AK and HUAWEICLOUD_SDK_SK.
            httpClientRequest.setKey("9a4a2b69afe141718f6843c5d39961ec");
            httpClientRequest.setSecret("541845f206324bbc933065b44fc98c47");
            httpClientRequest.setMethod("POST");
            // Set a request URL in the format of https://{Endpoint}/{URI}.
            httpClientRequest.setUrl("https://vehiclequery.apistore.huaweicloud.com/vehicle/query/brand");
            httpClientRequest.addHeader("Content-Type", "text/plain");
            // Set a body for http request.
//            httpClientRequest.setBody("put your request body here");
        } catch (Exception e) {
//            LOGGER.error(e.getMessage());
            return "";
        }
        CloseableHttpClient client = null;
        try {
            // Sign the request.
            HttpRequestBase signedRequest = Client.sign(httpClientRequest, Constant.SIGNATURE_ALGORITHM_SDK_HMAC_SHA256);
            if (Constant.DO_VERIFY) {
                // creat httpClient and verify ssl certificate
                HostName.setUrlHostName(httpClientRequest.getHost());
                client = (CloseableHttpClient) SSLCipherSuiteUtil.createHttpClientWithVerify(Constant.INTERNATIONAL_PROTOCOL);
            } else {
                // creat httpClient and do not verify ssl certificate
                client = (CloseableHttpClient) SSLCipherSuiteUtil.createHttpClient(Constant.INTERNATIONAL_PROTOCOL);
            }
            HttpResponse response = client.execute(signedRequest);
            // Print the body of the response.
            HttpEntity resEntity = response.getEntity();
            if (resEntity != null) {
//                LOGGER.info("Processing Body with name: {} and value: {}", System.getProperty("line.separator"),
//                        EntityUtils.toString(resEntity, "UTF-8"));
                String string = EntityUtils.toString(resEntity, "UTF-8");
                return string;
            }
        } catch (Exception e) {
            LOGGER.error(e.getMessage());
        } finally {
            if (client != null) {
                client.close();
            }
        }
        return "";
    }
 
 
    public static   String getModelById(String brandId) throws Exception {
        // Create a new request.
        Request httpClientRequest = new Request();
        try {
            // Set the request parameters.
            // AppKey, AppSecrect, Method and Url are required parameters.
            // Directly writing AK/SK in code is risky. For security, encrypt your AK/SK and store them in the configuration file or environment variables.
            // In this example, the AK/SK are stored in environment variables for identity authentication.
            // Before running this example, set environment variables HUAWEICLOUD_SDK_AK and HUAWEICLOUD_SDK_SK.
            httpClientRequest.setKey("9a4a2b69afe141718f6843c5d39961ec");
            httpClientRequest.setSecret("541845f206324bbc933065b44fc98c47");
            httpClientRequest.setMethod("POST");
            // Set a request URL in the format of https://{Endpoint}/{URI}.
            httpClientRequest.setUrl("https://vehiclequery.apistore.huaweicloud.com/vehicle/query/series");
            httpClientRequest.addHeader("Content-Type", "text/plain");
            httpClientRequest.addQueryStringParam("brandId",brandId);
            // Set a body for http request.
//            httpClientRequest.setBody("put your request body here");
        } catch (Exception e) {
//            LOGGER.error(e.getMessage());
            return "";
        }
        CloseableHttpClient client = null;
        try {
            // Sign the request.
            HttpRequestBase signedRequest = Client.sign(httpClientRequest, Constant.SIGNATURE_ALGORITHM_SDK_HMAC_SHA256);
            if (Constant.DO_VERIFY) {
                // creat httpClient and verify ssl certificate
                HostName.setUrlHostName(httpClientRequest.getHost());
                client = (CloseableHttpClient) SSLCipherSuiteUtil.createHttpClientWithVerify(Constant.INTERNATIONAL_PROTOCOL);
            } else {
                // creat httpClient and do not verify ssl certificate
                client = (CloseableHttpClient) SSLCipherSuiteUtil.createHttpClient(Constant.INTERNATIONAL_PROTOCOL);
            }
            HttpResponse response = client.execute(signedRequest);
            // Print the body of the response.
            HttpEntity resEntity = response.getEntity();
            if (resEntity != null) {
//                LOGGER.info("Processing Body with name: {} and value: {}", System.getProperty("line.separator"),
//                        EntityUtils.toString(resEntity, "UTF-8"));
                String string = EntityUtils.toString(resEntity, "UTF-8");
                return string;
            }
        } catch (Exception e) {
            LOGGER.error(e.getMessage());
        } finally {
            if (client != null) {
                client.close();
            }
        }
        return "";
    }
 
 
 
    public static   String getSeriesById(String brandId) throws Exception {
        // Create a new request.
        Request httpClientRequest = new Request();
        try {
            // Set the request parameters.
            // AppKey, AppSecrect, Method and Url are required parameters.
            // Directly writing AK/SK in code is risky. For security, encrypt your AK/SK and store them in the configuration file or environment variables.
            // In this example, the AK/SK are stored in environment variables for identity authentication.
            // Before running this example, set environment variables HUAWEICLOUD_SDK_AK and HUAWEICLOUD_SDK_SK.
            httpClientRequest.setKey("9a4a2b69afe141718f6843c5d39961ec");
            httpClientRequest.setSecret("541845f206324bbc933065b44fc98c47");
            httpClientRequest.setMethod("POST");
            // Set a request URL in the format of https://{Endpoint}/{URI}.
            httpClientRequest.setUrl("https://vehiclequery.apistore.huaweicloud.com/vehicle/query/model");
            httpClientRequest.addHeader("Content-Type", "text/plain");
            httpClientRequest.addQueryStringParam("seriesId",brandId);
            // Set a body for http request.
//            httpClientRequest.setBody("put your request body here");
        } catch (Exception e) {
//            LOGGER.error(e.getMessage());
            return "";
        }
        CloseableHttpClient client = null;
        try {
            // Sign the request.
            HttpRequestBase signedRequest = Client.sign(httpClientRequest, Constant.SIGNATURE_ALGORITHM_SDK_HMAC_SHA256);
            if (Constant.DO_VERIFY) {
                // creat httpClient and verify ssl certificate
                HostName.setUrlHostName(httpClientRequest.getHost());
                client = (CloseableHttpClient) SSLCipherSuiteUtil.createHttpClientWithVerify(Constant.INTERNATIONAL_PROTOCOL);
            } else {
                // creat httpClient and do not verify ssl certificate
                client = (CloseableHttpClient) SSLCipherSuiteUtil.createHttpClient(Constant.INTERNATIONAL_PROTOCOL);
            }
            HttpResponse response = client.execute(signedRequest);
            // Print the body of the response.
            HttpEntity resEntity = response.getEntity();
            if (resEntity != null) {
//                LOGGER.info("Processing Body with name: {} and value: {}", System.getProperty("line.separator"),
//                        EntityUtils.toString(resEntity, "UTF-8"));
                String string = EntityUtils.toString(resEntity, "UTF-8");
                return string;
            }
        } catch (Exception e) {
            LOGGER.error(e.getMessage());
        } finally {
            if (client != null) {
                client.close();
            }
        }
        return "";
    }
 
 
    public static   String getDetailById(String brandId) throws Exception {
        // Create a new request.
        Request httpClientRequest = new Request();
        try {
            // Set the request parameters.
            // AppKey, AppSecrect, Method and Url are required parameters.
            // Directly writing AK/SK in code is risky. For security, encrypt your AK/SK and store them in the configuration file or environment variables.
            // In this example, the AK/SK are stored in environment variables for identity authentication.
            // Before running this example, set environment variables HUAWEICLOUD_SDK_AK and HUAWEICLOUD_SDK_SK.
            httpClientRequest.setKey("9a4a2b69afe141718f6843c5d39961ec");
            httpClientRequest.setSecret("541845f206324bbc933065b44fc98c47");
            httpClientRequest.setMethod("POST");
            // Set a request URL in the format of https://{Endpoint}/{URI}.
            httpClientRequest.setUrl("https://vehiclequery.apistore.huaweicloud.com/vehicle/query/detail");
            httpClientRequest.addHeader("Content-Type", "text/plain");
            httpClientRequest.addQueryStringParam("modelId",brandId);
            // Set a body for http request.
//            httpClientRequest.setBody("put your request body here");
        } catch (Exception e) {
//            LOGGER.error(e.getMessage());
            return "";
        }
        CloseableHttpClient client = null;
        try {
            // Sign the request.
            HttpRequestBase signedRequest = Client.sign(httpClientRequest, Constant.SIGNATURE_ALGORITHM_SDK_HMAC_SHA256);
            if (Constant.DO_VERIFY) {
                // creat httpClient and verify ssl certificate
                HostName.setUrlHostName(httpClientRequest.getHost());
                client = (CloseableHttpClient) SSLCipherSuiteUtil.createHttpClientWithVerify(Constant.INTERNATIONAL_PROTOCOL);
            } else {
                // creat httpClient and do not verify ssl certificate
                client = (CloseableHttpClient) SSLCipherSuiteUtil.createHttpClient(Constant.INTERNATIONAL_PROTOCOL);
            }
            HttpResponse response = client.execute(signedRequest);
            // Print the body of the response.
            HttpEntity resEntity = response.getEntity();
            if (resEntity != null) {
//                LOGGER.info("Processing Body with name: {} and value: {}", System.getProperty("line.separator"),
//                        EntityUtils.toString(resEntity, "UTF-8"));
                String string = EntityUtils.toString(resEntity, "UTF-8");
                return string;
            }
        } catch (Exception e) {
            LOGGER.error(e.getMessage());
        } finally {
            if (client != null) {
                client.close();
            }
        }
        return "";
    }
}