删除资源请求post-json方法
This commit is contained in:
parent
b5dada173a
commit
dbaf2cda60
@ -42,7 +42,7 @@ public class UserServiceImpl extends AbstractService implements IUserService {
|
||||
|
||||
@Override
|
||||
public JSONArray listUserByIds(Map<String, Object> 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("获取人员列表失败");
|
||||
}
|
||||
|
@ -70,6 +70,7 @@ public class RestTemplateUtil {
|
||||
httpHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
||||
|
||||
MultiValueMap<String, Object> queryParams = new LinkedMultiValueMap<>();
|
||||
queryParams.add("access_token", accessToken);
|
||||
for (Map.Entry<String, Object> 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<String, Object> params) {
|
||||
String accessToken = getAccessToken();
|
||||
if (StringUtils.isBlank(accessToken)) {
|
||||
return null;
|
||||
}
|
||||
Map<String, Object> queryParams = new HashMap<>(1);
|
||||
for (Map.Entry<String, Object> kv : params.entrySet()) {
|
||||
queryParams.put(kv.getKey(), kv.getValue());
|
||||
}
|
||||
|
||||
HttpHeaders httpHeaders = new HttpHeaders();
|
||||
httpHeaders.setContentType(MediaType.APPLICATION_JSON_UTF8);
|
||||
|
||||
HttpEntity<Map<String, Object>> 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;
|
||||
|
Loading…
Reference in New Issue
Block a user