1.使用spring原生restTemplate请求接口
// GET 获取部门列表
GET_DEPARTMENT_URL("https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token=ACCESS_TOKEN&id=ID")
String urlValue = QyaApiEnum.GET_DEPARTMENT_URL.getUrlValue();
String accessToken = tokenUtil.getAccessToken();
String url = urlValue.replace("ACCESS_TOKEN", accessToken).replace("ID", id);
ResponseEntity<String> forEntity = restTemplate.getForEntity(url, String.class);
log.info("获取部门列表:" + forEntity.getBody());
2.由于企业微信根据企业ID和凭证密钥获取的access_token长度过长,在测试过程中,发现获取的token与替换之后请求的token由于使用replace替换出现字符串丢失
// 根据https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=ID&corpsecret=SECRET获取的的token为
// ******************NukGFk6AIDnmLC9KRSngNkPr38IzAaE8feZKlgviBrSM67ayjpR9T0zWQOO7QlujPA
String url = urlValue.replace("ACCESS_TOKEN", accessTo