|
- package com.hisen.test1;
- import java.util.Map;
- import org.apache.http.HttpEntity;
- import org.apache.http.client.methods.CloseableHttpResponse;
- import org.apache.http.client.methods.HttpGet;
- import org.apache.http.impl.client.CloseableHttpClient;
- import org.apache.http.impl.client.HttpClientBuilder;
- import org.apache.http.util.EntityUtils;
- import com.alibaba.fastjson.JSON;
- public static void queryBLM(String id) {
- String appSecret = "jhrrhghgfkv33dtG7mRZKLJiv2bO1zKJ";
- String appKey = "606955288693";
- String url = "https://www.baidu.com/info?";
- // 签文
- Map<String, Object> map = BLMSignUtil.createSign(id, appSecret, appKey);
- String params = "orderId=" + map.get("orderId") + "&sign="
- + map.get("sign") + "&appKey=" + map.get("appKey")
- + "×tamp=" + map.get("timestamp");
- StringBuilder stringBuilder = new StringBuilder();
- System.out.println(">>>>> 链接 <<<<< \n" + url + params);
-
- CloseableHttpClient client = HttpClientBuilder.create().build();
- HttpGet request = new HttpGet(url + params);
- request.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
- request.setHeader("Accept-Encoding", "gzip, deflate, sdch");
- request.setHeader("Accept-Language", "zh-CN,zh;q=0.8");
- request.setHeader("Connection", "keep-alive");
- request.setHeader("Upgrade-Insecure-Requests", "1");
- request.setHeader("Host", "www.baidu.com");
- request.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36");
- try {
- CloseableHttpResponse response = client.execute(request);
- HttpEntity entity = response.getEntity();
- String responseStr = EntityUtils.toString(entity, "utf-8");
- stringBuilder.append(responseStr);
- System.out.println(stringBuilder.toString());
- } catch (Exception e) {
- System.out.println("查询出错:" + e.getMessage() + e);
- e.printStackTrace();
- }
- // 反序列化
- BLMOrderInfoListDto blmOrderInfoListDto = JSON.parseObject(stringBuilder.toString(), BLMOrderInfoListDto.class);
- System.out.println(blmOrderInfoListDto);
- }
- }
复制代码
|
|