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;