15832144755
2021-07-23 741d66c00c593d4f14cd6731d3e4af6ee5c191ac
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
package com.hxzkoa.util;
 
import java.io.IOException;
 
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
 
import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicHeader;
import org.apache.http.util.EntityUtils;
 
public class HttpUtil {
    static String pathName = "G:\\publicKey.txt";
 
    public static String getSerchPersion(String url, String param) {
        HttpClient httpClient = new HttpClient();
 
        httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
 
        GetMethod getMethod = new GetMethod(url);
 
        getMethod.getParams().setParameter("http.socket.timeout", Integer.valueOf(5000));
 
        getMethod.getParams().setParameter("http.method.retry-handler", new DefaultHttpMethodRetryHandler());
        String response = "";
        try {
            int statusCode = httpClient.executeMethod(getMethod);
 
            if (statusCode != 200) {
                System.err.println("请求出错: " + getMethod.getStatusLine());
            }
 
            Header[] headers = getMethod.getResponseHeaders();
            for (Header h : headers) {
                System.out.println(h.getName() + "------------ " + h.getValue());
            }
            byte[] responseBody = getMethod.getResponseBody();
            response = new String(responseBody, param);
            System.out.println("----------response:" + response);
        } catch (HttpException e) {
            System.out.println("请检查输入的URL!");
            e.printStackTrace();
        } catch (IOException e) {
            System.out.println("发生网络异常!");
            e.printStackTrace();
        } finally {
            getMethod.releaseConnection();
        }
        return response;
    }
 
    public static JSONObject doPost(String url, JSONObject json, String charset) {
        CloseableHttpClient client = HttpClients.createDefault();
        HttpPost post = new HttpPost(url);
        post.addHeader("Content-Type", "application/json;charset=" + charset);
        JSONObject response = null;
        try {
            StringEntity s = new StringEntity(json.toString(), charset);
            s.setContentEncoding(new BasicHeader("Content-Type", "application/json"));
            post.setEntity(s);
            HttpResponse res = client.execute(post);
            if (res.getStatusLine().getStatusCode() == 200) {
                String result = EntityUtils.toString(res.getEntity());
                response = JSONObject.fromObject(result);
                System.out.println("----------response:" + response.toString());
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return response;
    }
 
    public static JSONObject doPost(String url, JSONArray json, String charset) {
        CloseableHttpClient client = HttpClients.createDefault();
        HttpPost post = new HttpPost(url);
        JSONObject response = null;
        try {
            StringEntity s = new StringEntity(json.toString());
            s.setContentEncoding(charset);
            s.setContentType("application/json");
            post.setEntity(s);
            HttpResponse res = client.execute(post);
            if (res.getStatusLine().getStatusCode() == 200) {
                String result = EntityUtils.toString(res.getEntity());
                response = JSONObject.fromObject(result);
                System.out.println("----------response:" + response.toString());
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return response;
    }
 
    public static JSONObject doPost(String url, String encryptByPublicKey, String charset) {
        CloseableHttpClient client = HttpClients.createDefault();
        HttpPost post = new HttpPost(url);
        JSONObject response = null;
        try {
            StringEntity s = new StringEntity(encryptByPublicKey);
            System.out.print(encryptByPublicKey);
            s.setContentEncoding(charset);
            s.setContentType("application/json");
            post.setEntity(s);
            HttpResponse res = client.execute(post);
            System.out.print(res);
            if (res.getStatusLine().getStatusCode() == 200) {
                String result = EntityUtils.toString(res.getEntity());
                result = result.replace("\\", "");
                result = result.substring(1, result.length()-1);
                System.out.println("----------result:" + result);
                response = JSONObject.fromObject(result);
//              System.out.println("----------response:" + response.toString());
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return response;
    }
 
    public static String doPostByXML(String url, String encryptByPublicKey, String charset) {
        CloseableHttpClient client = HttpClients.createDefault();
        HttpPost post = new HttpPost(url);
        String result = "";
        try {
            StringEntity s = new StringEntity(encryptByPublicKey);
            s.setContentEncoding(charset);
            s.setContentType("text/xml");
            post.setEntity(s);
            HttpResponse res = client.execute(post);
            if (res.getStatusLine().getStatusCode() == 200) {
                result = new String(EntityUtils.toString(res.getEntity()).getBytes("ISO-8859-1"), "UTF8");
                System.out.println("----------response:" + result);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return result;
    }
 
    public static void main(String[] arg) throws Exception {
 
        // 分中心数据获取接口
        // String url = "https://dianzikouan.cn/hxzkoa/SubSale.do";
        // String url = "http://127.0.0.1:8080/hxzkoa/SubSale.do";
        // UserNPO user = new UserNPO();
        // user.setOpenid("oQrTM4pwlR0ID4i1cCA5me7Av8qA");
        // user.setOpenid("oQrTM4i89gp0MLXdkBhNiwL5K111");
        //
        // user.setOpenid("oQrTM4pwlR0ID4i1cCA5me7Av8qA");
        // JSONObject reObject = JSONObject.fromObject(user);
        // doPost(url, reObject.toString(), "UTF-8");
 
        // 坐标获取接口
        // String url = "https://dianzikouan.cn/hxzkoa/Location.do";
        // SubSaleLL ll = new SubSaleLL();
        // ll.setRa_longitude("117.022218");
        // ll.setRa_latitude("36.706498");
        // JSONObject llObject = JSONObject.fromObject(ll);
        // doPost(url, llObject.toString(), "UTF-8");
 
        // 获取城市列表
        // String url = "https://dianzikouan.cn/hxzkoa/CityList.do";
        // doPost(url, "", "UTF-8");
 
        // 坐标定位信息(城市)
        // String url = "https://dianzikouan.cn/hxzkoa/LocationByCity.do";
        // SubSaleLL ll = new SubSaleLL();
        // ll.setRa_longitude("117.022218");
        // ll.setRa_latitude("36.706498");
        // ll.setRa_city_code("BJ");
        // JSONObject llObject = JSONObject.fromObject(ll);
        // doPost(url, llObject.toString(), "UTF-8");
 
        // 搜索取卡点(模糊搜索)
        // String url = "http://127.0.0.1:8080/hxzkoa/SearchSubsale.do";
        // SubSale subsale = new SubSale();
        // subsale.setRa_name("昆明分中心");
        // //subsale.setRa_name("大连分中心营");
        // JSONObject reObject = JSONObject.fromObject(subsale);
        // doPost(url, reObject.toString(),
        // "UTF-8");
 
        // 搜索发票(精确搜索)
        // String url = "http://127.0.0.1:8080/hxzkoa/SearchInvoice.do";
        // InvoiceOIS invoice = new InvoiceOIS();
        // // invoice.setInvoice_id("TF20200813232958298");
        // invoice.setInvoice_id("dfd");
        // JSONObject reObject = JSONObject.fromObject(invoice);
        // doPost(url, reObject.toString(), "UTF-8");
 
        // 获取商品列表接口
        // String url = "https://dianzikouan.cn/hxzkoa/EquipmentList.do";
        // EquipmentORL equi = new EquipmentORL();
        // equi.setRa_code("1");
        // JSONObject reObject = JSONObject.fromObject(equi);
        // doPost(url, reObject.toString(), "UTF-8");
 
        // 用户登录校验接口
        // String url =
        // "https://dianzikouan.cn/hxzkoa/UserLoginVerification.do";
        // UserNPO user = new UserNPO();
        // user.setOpenid("oQrTM4k7-Vti-uBJHCUmQjn8CKGY");
        // // user.setOpenid("AAAA");
        // JSONObject reObject = JSONObject.fromObject(user);
        // doPost(url, reObject.toString(), "UTF-8");
 
        // 获取商品详细接口
        // String url = "http://127.0.0.1:8080/hxzkoa/EquipmentDetail.do";
        // EquiDetailRE re = new EquiDetailRE();
        // re.setEquipment_id("2027003");
        // re.setRa_code("4");
        // JSONObject reObject = JSONObject.fromObject(re);
        // doPost(url, reObject.toString(), "UTF-8");
 
        // 生成订单接口
        // String url = "http://127.0.0.1:8080/hxzkoa/GenerateInvoice.do";
        // Invoice invoice = new Invoice();
        // invoice.setOpenid("oQrTM4pwlR0ID4i1cCA5me7Av8qA");
        // invoice.setRa_code("1");
        // invoice.setSpbill_create_ip("192.168.88.65");
        // List<String> equipIdList = new ArrayList<String>();
        // equipIdList.add("2027002");
        // equipIdList.add("2027003");
        // equipIdList.add("2027004");
        // List<String> equipAmountList = new ArrayList<String>();
        // equipAmountList.add("1");
        // equipAmountList.add("2");
        // equipAmountList.add("3");
        // invoice.setEquiIdList(equipIdList);
        // invoice.setEquiAmountList(equipAmountList);
        // invoice.setRandom32uuid("6C0B20C4FAB44BF1A5FAD3DF174994F3");
        // JSONObject reObject = JSONObject.fromObject(invoice);
        // doPost(url, reObject.toString(), "UTF-8");
 
        // 订单结算接口(微信接口)
        // String url = "http://127.0.0.1:8080/hxzkoa/hxzkoaWeixin.do";
        // Invoice invoice = new Invoice();
        // invoice.setInvoice_id("TF20171122110419458");
        // invoice.setSpbill_create_ip("39.106.31.124");
        // invoice.setOpenid("oQrTM4k7-Vti-uBJHCUmQjn8CKGY");
        // JSONObject reObject = JSONObject.fromObject(invoice);
        // doPost(url, reObject.toString(), "UTF-8");
 
        // 订单结算接口(支付接口)
        // String url = "https://dianzikouan.cn/hxzkoa/PayOrder.do";
        // String url = "http://39.106.31.124/hxzkoa/PayOrder.do";
        // String url = "http://127.0.0.1:8080/hxzkoa/PayOrder.do";
        // Invoice invoice = new Invoice();
        // invoice.setInvoice_id("TF20201116124830564");
        // invoice.setInvoice_status("1");
        // invoice.setPost_ra_code("1");
        // JSONObject reObject2 = JSONObject.fromObject(invoice);
        // doPost(url, reObject2.toString(), "UTF-8");
 
        // 登录接口
        // String url = "https://dianzikouan.cn/hxzkoa/Login.do";
        // String url = "http://127.0.0.1:8080/hxzkoa/Login.do";
        // UserNPO user = new UserNPO();
        // user.setCode("033zeY112Ftwd64Pb9n12uwG7y0zeY1T");
        // JSONObject reObject = JSONObject.fromObject(user);
        // doPost(url, reObject.toString(), "UTF-8");
 
        // 微信绑定接口
        // String url = "http://127.0.0.1:8080/hxzkoa/WeixinBinding.do";
        // UserNPO user1 = new UserNPO();
        // user1.setOpenid("");
        // user1.setUser_name("leeway@tsinghua.edu.cn");
        // user1.setUserpwd("12356");
        // JSONObject reObject1 = JSONObject.fromObject(user1);
        // doPost(url, reObject1.toString(), "UTF-8");
        // UserNPO user2 = new UserNPO();
        // user2.setOpenid("AAAA");
        // user2.setUser_name("108771799@qq.com");
        // user2.setUserpwd("d683b3c54bcb3a37eaa368053549685d");
        // JSONObject reObject2 = JSONObject.fromObject(user2);
        // doPost(url, reObject2.toString(), "UTF-8");
 
        // 重置密码接口
        // String url = "https://dianzikouan.cn/hxzkoa/ResetPassword.do";
        // UserNPO user = new UserNPO();
        // user.setOpenid("oQrTM4pwlR0ID4i1cCA5me7Av8qA");
        // user.setUserpwd("12356");
        // JSONObject reObject = JSONObject.fromObject(user);
        // doPost(url, reObject.toString(), "UTF-8");
 
        // 新用户注册接口
        // String url = "https://dianzikouan.cn/hxzkoa/Registration.do";
        // UserNPO user = new UserNPO();
        // user.setUser_name("456@tsinghua.edu.cn");
        // user.setUserpwd("12356");
        // JSONObject reObject = JSONObject.fromObject(user);
        // doPost(url, reObject.toString(), "UTF-8");
 
        // 获取用户信息接口
        // String url = "https://dianzikouan.cn/hxzkoa/QueryUser.do";
        // String url = "http://127.0.0.1:8080/hxzkoa/QueryUser.do";
        // UserNPO userNPO = new UserNPO();
        // userNPO.setOpenid("oQrTM4i89gp0MLXdkBhNiwL5Kyns");
        // JSONObject reObject = JSONObject.fromObject(userNPO);
        // doPost(url, reObject.toString(), "UTF-8");
 
        // 获取下单信息接口
        // String url = "https://dianzikouan.cn/hxzkoa/QueryOrder.do";
        // String url = "http://127.0.0.1:8080/hxzkoa/QueryOrder.do";
        // EquipmentORL userNPO = new EquipmentORL();
        // userNPO.setOpenid("oQrTM4i89gp0MLXdkBhNiwL5Kyns");
        // userNPO.setRa_code("1");
        // JSONObject reObject = JSONObject.fromObject(userNPO);
        // doPost(url, reObject.toString(), "UTF-8");
 
        // 用户信息维护接口
        // String url = "http://127.0.0.1:8080/hxzkoa/UserUpdate.do";
        // UserOrg userorg = new UserOrg();
        // userorg.setOpenid("AAAA");
        // userorg.setOrg_name("新加坡測試");
        // userorg.setTpay_id("9137028355396927ZP");
        // userorg.setInvoice_account("青岛银行平度支行802590200121658");
        // userorg.setInvoice_address_tel("青岛平度市经济开发区长江路98号 0532-86633877");
        // userorg.setInvoice_receiver("刘丽");
        // userorg.setPhone_number("13573283129");
        // userorg.setInvoice_address("山东省青岛市黄岛区滨海街道办事处白石坎村");
        // userorg.setPost_code("266409");
        // JSONObject reObject = JSONObject.fromObject(userorg);
        // doPost(url, URLEncoder.encode(reObject.toString(), "UTF-8"),
        // "UTF-8");
        // String url = "http://39.106.31.124/hxzkoa/UserUpdate.do";
        // UserOrg userorg = new UserOrg();
        // userorg.setOpenid("CCC");
        // userorg.setOrg_name("新加坡測試Z");
        // userorg.setTpay_id("9137028355396927ZP");
        // userorg.setInvoice_account("青岛银行平度支行80259020012165Z");
        // userorg.setInvoice_address_tel("青岛平度市经济开发区长江路98号 0532-8663387Z");
        // userorg.setInvoice_receiver("刘美丽");
        // userorg.setPhone_number("13573283129");
        // userorg.setInvoice_address("山东省青岛市黄岛区滨海街道办事处灰石坎村");
        // userorg.setPost_code("266409");
        // JSONObject reObject = JSONObject.fromObject(userorg);
        // doPost(url,URLEncoder.encode(reObject.toString(), "UTF-8"), "UTF-8");
 
        // 获取订单列表接口
        // String url = "http://127.0.0.1:8080/hxzkoa/InvoiceList1.do";
        // InvoiceOIS invoiceOIS = new InvoiceOIS();
        // invoiceOIS.setOpenid("oQrTM4i89gp0MLXdkBhNiwL5Kyns");
        // invoiceOIS.setPage("0");
        // invoiceOIS.setInvoice_status("");
        // JSONObject reObject = JSONObject.fromObject(invoiceOIS);
        // doPost(url, reObject.toString(), "UTF-8");
 
        // 获取订单详情接口
        // String url = "https://dianzikouan.cn/hxzkoa/InvoiceDetail.do";
        // String url = "http://127.0.0.1:8080/hxzkoa/InvoiceDetail.do";
        // InvoiceOIS invoiceOIS = new InvoiceOIS();
        // invoiceOIS.setInvoice_id("TF20201231013659952");
        // JSONObject reObject = JSONObject.fromObject(invoiceOIS);
        // doPost(url, reObject.toString(), "UTF-8");
 
        // 修改订单状态接口
        // String url = "https://dianzikouan.cn/hxzkoa/UpdateInvoiceState.do";
        // String url = "http://127.0.0.1:8080/hxzkoa/UpdateInvoiceState.do";
        // InvoiceOIS invoiceOIS = new InvoiceOIS();
        // invoiceOIS.setInvoice_id("TF20201116124028352");
        // invoiceOIS.setInvoice_status("8");
        // invoiceOIS.setRandom32uuid("D34570E809F740EABF76861CF07B048A");
        // invoiceOIS.setRa_code("1");
        // JSONObject reObject = JSONObject.fromObject(invoiceOIS);
        // doPost(url, reObject.toString(), "UTF-8");
 
        // 获取发票列表接口
        // String url = "https://dianzikouan.cn/hxzkoa/InvoiceList2.do";
        // InvoiceOIS invoiceOIS = new InvoiceOIS();
        // invoiceOIS.setInvoiceId("TF20200813232958298");
        // JSONObject reObject = JSONObject.fromObject(invoiceOIS);
        // doPost(url, reObject.toString(), "UTF-8");
 
        // 发票信息维护接口1
        // String url = "http://39.106.31.124/hxzkoa/InvoiceUpdate1.do";
        // Invoice invoice = new Invoice();
        // invoice.setIs_einvoice("0");
        // invoice.setInvoice_payable("北京市海淀区清华大学");
        // invoice.setTpay_id("913702126143725974");
        // invoice.setInvoice_account("1662");
        // invoice.setInvoice_address_tel("afsadfsadf");
        // invoice.setEmail("fa@da");
        // JSONObject reObject = JSONObject.fromObject(invoice);
        // doPost(url, URLEncoder.encode(reObject.toString(), "UTF-8"),
        // "UTF-8");
 
        // 发票信息维护接口2
        // String url = "http://127.0.0.1:8080/hxzkoa/InvoiceUpdate2.do";
        // Invoice invoice = new Invoice();
        // invoice.setIs_einvoice("0");
        // invoice.setInvoice_payable("北京市海淀区清华大学");
        // invoice.setTpay_id("913702126143725974");
        // invoice.setInvoice_account("1662");
        // invoice.setInvoice_receiver("aaa");
        // invoice.setPhone_number("123124412");
        // JSONObject reObject = JSONObject.fromObject(invoice);
        // byte[] publicKey = Base64.decode(RSAUtil.keyOper(pathName, "read",
        // ""));
        // byte[] code = RSAUtil.encryptByPublicKey(
        // reObject.toString().getBytes(), publicKey);
        // String encode = Base64.encode(code);
        //
        // doPost(url, URLEncoder.encode(encode, "UTF-8"), "UTF-8");
 
        String user_id = UUIDGenerator.random12UUID();
        System.out.println("user_id:" + user_id);
 
    }
}