|
@@ -9,13 +9,16 @@ import com.skyversation.poiaddr.service.AreaService;
|
|
|
import com.skyversation.poiaddr.util.net.AddressNetTools;
|
|
|
import com.skyversation.poiaddr.util.status.AddressLevel;
|
|
|
import com.skyversation.poiaddr.util.status.AddressResultEnum;
|
|
|
+import org.springframework.http.HttpMethod;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
+import org.springframework.util.LinkedMultiValueMap;
|
|
|
+import org.springframework.util.MultiValueMap;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
+import org.apache.commons.codec.binary.Base64;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashSet;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Set;
|
|
|
+import javax.crypto.Mac;
|
|
|
+import javax.crypto.spec.SecretKeySpec;
|
|
|
+import java.util.*;
|
|
|
|
|
|
public class AddressQueryEngine {
|
|
|
|
|
@@ -67,7 +70,7 @@ public class AddressQueryEngine {
|
|
|
}*/
|
|
|
if (addressResult.getData() == null || addressResult.getData().size() == 0) {
|
|
|
for (String addr : addrs) {
|
|
|
- AddressResult.ContentBean contentBean = verificaData(szxSearchByName(addr), level, addr);
|
|
|
+ AddressResult.ContentBean contentBean = verificaData(sj_szxSearchByName(addr), level, addr);
|
|
|
if (contentBean != null) {
|
|
|
contentBean.setSearchAddress(addr);
|
|
|
contentBeans.add(contentBean);
|
|
@@ -149,7 +152,7 @@ public class AddressQueryEngine {
|
|
|
* @return
|
|
|
*/
|
|
|
public AddressResult szxSearchByName(String address) {
|
|
|
- ResponseEntity response = AddressNetTools.getInstance().requestGet(Constant.SZX_URL + "®ion=" + Constant.getAMAP_CITY_CODE() + "&query=" + address, null, null, 10);
|
|
|
+ ResponseEntity response = AddressNetTools.getInstance().requestGetOrPost(HttpMethod.GET, Constant.SZX_URL + "®ion=" + Constant.getAMAP_CITY_CODE() + "&query=" + address, null, null, 10);
|
|
|
if (response != null) {
|
|
|
String body = response.getBody() + "";
|
|
|
if (!StringUtils.hasText(body))
|
|
@@ -166,6 +169,98 @@ public class AddressQueryEngine {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public String getSigns(String timestamp, String appCode, String UUid, String appSecret) {
|
|
|
+// 先拼接
|
|
|
+ String signData = timestamp + appCode + UUid;
|
|
|
+// 生成sign
|
|
|
+ String sign = "";
|
|
|
+ try {
|
|
|
+ Mac sha256 = Mac.getInstance("HmacSHA256");
|
|
|
+ sha256.init(new SecretKeySpec(appSecret.getBytes(), "HmacSHA256"));
|
|
|
+ byte[] result = sha256.doFinal(signData.getBytes());
|
|
|
+ sign = Base64.encodeBase64String(result);
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.err.println("sign 生成异常:" + e);
|
|
|
+ }
|
|
|
+ return sign;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Object x_sjRHSearchByAddr(String address) {
|
|
|
+// 鉴权
|
|
|
+ Map<String, String> headerMap = new HashMap<>();
|
|
|
+ String timestamp = System.currentTimeMillis() + "";
|
|
|
+ String appCode = "7unv4vbwqxnq4a7m9h";
|
|
|
+ String UUid = UUID.randomUUID().toString();
|
|
|
+ String appSecret = "w6tawvf4k3ck4ikij9";
|
|
|
+ headerMap.put("x-timestamp", timestamp);
|
|
|
+ headerMap.put("x-appcode", appCode);
|
|
|
+ headerMap.put("x-uuid", UUid);
|
|
|
+// 签名
|
|
|
+ headerMap.put("x-sign", getSigns(timestamp, appCode, UUid, appSecret));
|
|
|
+ JSONObject params = new JSONObject();
|
|
|
+ JSONArray requestJson = new JSONArray();
|
|
|
+ JSONObject paramObject = new JSONObject();
|
|
|
+ paramObject.put("name", "query");
|
|
|
+ paramObject.put("position", "QUERY");
|
|
|
+ paramObject.put("value", address);
|
|
|
+ requestJson.add(paramObject);
|
|
|
+ params.put("requestJson", requestJson);
|
|
|
+ ResponseEntity response = AddressNetTools.getInstance().requestGetOrPost(HttpMethod.POST, Constant.SJ_SZX_SEARCH_BY_NAME, params, headerMap, 10);
|
|
|
+ if (response != null) {
|
|
|
+ String body = response.getBody() + "";
|
|
|
+ if (!StringUtils.hasText(body))
|
|
|
+ return AddressTools.getInstance().faildQuery(AddressResultEnum.RESULT_NULL, "搜索无结果");
|
|
|
+ try {
|
|
|
+ JSONArray json = JSONArray.parseArray(body);
|
|
|
+ return TransfromDataTool.szxResultToResult2(json);
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.err.println(e);
|
|
|
+ return AddressTools.getInstance().faildQuery(AddressResultEnum.DATA_FROMAT_FAILD, "格式化失败");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return "地址[" + address + "]未查询到数据!";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public AddressResult sj_szxSearchByName(String address) {
|
|
|
+// 鉴权
|
|
|
+ Map<String, String> headerMap = new HashMap<>();
|
|
|
+ String timestamp = System.currentTimeMillis() + "";
|
|
|
+ String appCode = "7unv4vbwqxnq4a7m9h";
|
|
|
+ String UUid = UUID.randomUUID().toString();
|
|
|
+ String appSecret = "w6tawvf4k3ck4ikij9";
|
|
|
+ headerMap.put("x-timestamp", timestamp);
|
|
|
+ headerMap.put("x-appcode", appCode);
|
|
|
+ headerMap.put("x-uuid", UUid);
|
|
|
+// 签名
|
|
|
+ headerMap.put("x-sign", getSigns(timestamp, appCode, UUid, appSecret));
|
|
|
+
|
|
|
+ JSONObject params = new JSONObject();
|
|
|
+ JSONArray requestJson = new JSONArray();
|
|
|
+ JSONObject paramObject = new JSONObject();
|
|
|
+ paramObject.put("name", "query");
|
|
|
+ paramObject.put("position", "QUERY");
|
|
|
+ paramObject.put("value", address);
|
|
|
+ requestJson.add(paramObject);
|
|
|
+ params.put("requestJson", requestJson);
|
|
|
+ ResponseEntity response = AddressNetTools.getInstance().requestGetOrPost(HttpMethod.POST, Constant.SJ_SZX_SEARCH_BY_NAME, params, headerMap, 10);
|
|
|
+ if (response != null) {
|
|
|
+ String body = response.getBody() + "";
|
|
|
+ if (!StringUtils.hasText(body))
|
|
|
+ return AddressTools.getInstance().faildQuery(AddressResultEnum.RESULT_NULL, "搜索无结果");
|
|
|
+ try {
|
|
|
+ System.out.println("请求地址:" + address + ";返回结果:" + body);
|
|
|
+ return TransfromDataTool.szxResultToResult(JSONObject.parseObject(body));
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.err.println(e);
|
|
|
+ return AddressTools.getInstance().faildQuery(AddressResultEnum.DATA_FROMAT_FAILD, "格式化失败");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ System.out.println("地址[" + address + "]未查询到数据!");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/***
|
|
|
* 高德普通地名搜索
|
|
|
* @param address
|
|
@@ -173,7 +268,7 @@ public class AddressQueryEngine {
|
|
|
*/
|
|
|
public AddressResult gdSearchByName(String address) {
|
|
|
String geoUrl = Constant.AMAP_GEO_URL + "?key=" + Constant.AMAP_KEY + "&address=" + address + "&city=" + Constant.getAMAP_CITY_CODE() + "&output=JSON";
|
|
|
- ResponseEntity response = AddressNetTools.getInstance().requestGet(geoUrl, null, null, 0);
|
|
|
+ ResponseEntity response = AddressNetTools.getInstance().requestGetOrPost(HttpMethod.GET, geoUrl, null, null, 0);
|
|
|
if (response != null && response.getBody() != null) {
|
|
|
String body = response.getBody() + "";
|
|
|
if (!StringUtils.hasText(body))
|
|
@@ -199,7 +294,7 @@ public class AddressQueryEngine {
|
|
|
String geoUrl =
|
|
|
Constant.AMAP_SEARCH_NAME_V3 + "?key=" + Constant.AMAP_KEY + "&types=" + Constant.AMAP_SEARCH_TYPES +
|
|
|
"&keywords=" + address + "&city=" + Constant.getAMAP_CITY_CODE() + "&offset=20";
|
|
|
- ResponseEntity responseEntity = AddressNetTools.getInstance().requestGet(geoUrl, null, null, 0);
|
|
|
+ ResponseEntity responseEntity = AddressNetTools.getInstance().requestGetOrPost(HttpMethod.GET, geoUrl, null, null, 0);
|
|
|
if (responseEntity.hasBody()) {
|
|
|
String body = responseEntity.getBody() + "";
|
|
|
if (!StringUtils.hasText(body)) {
|
|
@@ -217,7 +312,7 @@ public class AddressQueryEngine {
|
|
|
geoUrl =
|
|
|
Constant.AMAP_SEARCH_NAME_V3 + "?key=" + Constant.AMAP_KEY + "&types=" + Constant.AMAP_SEARCH_TYPES +
|
|
|
"&keywords=" + address + "&city=" + Constant.getAMAP_CITY_CODE() + "&offset=20&page=" + i;
|
|
|
- ResponseEntity responseEntity2 = AddressNetTools.getInstance().requestGet(geoUrl, null, null, 0);
|
|
|
+ ResponseEntity responseEntity2 = AddressNetTools.getInstance().requestGetOrPost(HttpMethod.GET, geoUrl, null, null, 0);
|
|
|
if (responseEntity2.hasBody()) {
|
|
|
body = responseEntity2.getBody() + "";
|
|
|
}
|