From dbaf2cda608100264077eaecda5632d0a906c5ae Mon Sep 17 00:00:00 2001 From: wenc000 <450292408@qq.com> Date: Fri, 2 Aug 2019 10:52:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E8=B5=84=E6=BA=90=E8=AF=B7?= =?UTF-8?q?=E6=B1=82post-json=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/user/impl/UserServiceImpl.java | 2 +- .../common/plugin/utils/RestTemplateUtil.java | 34 ++----------------- 2 files changed, 3 insertions(+), 33 deletions(-) diff --git a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/user/impl/UserServiceImpl.java b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/user/impl/UserServiceImpl.java index 4e3b1ea..c71cb27 100644 --- a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/user/impl/UserServiceImpl.java +++ b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/user/impl/UserServiceImpl.java @@ -42,7 +42,7 @@ public class UserServiceImpl extends AbstractService implements IUserService { @Override public JSONArray listUserByIds(Map params) throws SearchException { - String result = restTemplateUtil.doPostJson(String.format(IApiConsts.LIST_USER_BY_ID, apiPathProperties.getUserCenter()), params); + String result = restTemplateUtil.doPostForm(String.format(IApiConsts.LIST_USER_BY_ID, apiPathProperties.getUserCenter()), params); if (StringUtils.isBlank(result)) { throw new SearchException("获取人员列表失败"); } diff --git a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/utils/RestTemplateUtil.java b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/utils/RestTemplateUtil.java index b08845b..a85d89c 100644 --- a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/utils/RestTemplateUtil.java +++ b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/utils/RestTemplateUtil.java @@ -70,6 +70,7 @@ public class RestTemplateUtil { httpHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED); MultiValueMap queryParams = new LinkedMultiValueMap<>(); + queryParams.add("access_token", accessToken); for (Map.Entry kv : params.entrySet()) { queryParams.add(kv.getKey(), kv.getValue()); } @@ -78,38 +79,7 @@ public class RestTemplateUtil { RestTemplate restTemplate = getRestTemplate(); try { - return getResponse(restTemplate.postForEntity(String.format("%s?access_token=%s", url, accessToken), httpEntity, String.class)); - } catch (Exception e) { - LOG.error(e.getMessage(), e); - return null; - } - } - - /** - * post提交 json 数据 - * - * @param url - * @param params - * @return - */ - public String doPostJson(String url, Map params) { - String accessToken = getAccessToken(); - if (StringUtils.isBlank(accessToken)) { - return null; - } - Map queryParams = new HashMap<>(1); - for (Map.Entry kv : params.entrySet()) { - queryParams.put(kv.getKey(), kv.getValue()); - } - - HttpHeaders httpHeaders = new HttpHeaders(); - httpHeaders.setContentType(MediaType.APPLICATION_JSON_UTF8); - - HttpEntity> httpEntity = new HttpEntity<>(queryParams, httpHeaders); - - RestTemplate restTemplate = getRestTemplate(); - try { - return getResponse(restTemplate.postForEntity(String.format("%s?access_token=%s", url, accessToken), httpEntity, String.class)); + return getResponse(restTemplate.postForEntity(url, httpEntity, String.class)); } catch (Exception e) { LOG.error(e.getMessage(), e); return null;