From d877cccbc11123e1c41ca939160ffe7d8e6cb9e9 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Wed, 20 Jan 2021 10:04:14 +0800 Subject: [PATCH] =?UTF-8?q?mongodb=E8=AE=BF=E9=97=AE=E6=96=B9=E5=BC=8F?= =?UTF-8?q?=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DipperAstPosAsyncTaskServiceImpl.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java index febe80a..5def78f 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperAstPosAsyncTaskServiceImpl.java @@ -1,5 +1,6 @@ package com.telpo.dipperposition.service.impl; +import cn.hutool.core.bean.BeanUtil; import com.alibaba.fastjson.JSONObject; import com.telpo.dipperposition.common.*; import com.telpo.dipperposition.config.NettyServerConfig; @@ -20,7 +21,9 @@ import org.springframework.util.ResourceUtils; import java.io.File; import java.io.FileNotFoundException; import java.io.UnsupportedEncodingException; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * @program: DipperAstPosAsyncTaskServiceImpl @@ -58,14 +61,16 @@ public class DipperAstPosAsyncTaskServiceImpl implements IDipperAstPosAsyncTaskS IpProvinceEntity ipProvinceEntity = ipProvinceService.getIpProvince(ipAddress); if (ipProvinceEntity == null) { // 匹配不到,再请求高德IP定位服务。 - JSONObject userObj = new JSONObject(); - userObj.put("ip", ipAddress); - userObj.put("key", ipPositionRequestKey); - JSONObject json = okHttpUtil.postRequestWithJson(ipPositionRequestPath, null, userObj); - if (ObjectUtils.isNotEmpty(json)) { - String province = (String) json.get("province"); + //JSONObject userObj = new JSONObject(); + Map dataMap = new HashMap(); + dataMap.put("ip", ipAddress); + dataMap.put("key", ipPositionRequestKey); + StringBuffer buffer = okHttpUtil.getQueryString(ipPositionRequestPath, dataMap); + if (ObjectUtils.isNotEmpty(buffer)) { + JSONObject provinceJson = JSONObject.parseObject(buffer.toString()); + String province = (String)provinceJson.get("province"); if (ObjectUtils.isEmpty(province)) { - log.debug("json is :" + json.toString()); + log.debug("json is :" + buffer.toString()); return null; } return province;