https://developer.work.weixin.qq.com/document/path/91039
请求方式: GET(HTTPS)
请求地址: https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=ID&corpsecret=SECRET
注:此处标注大写的单词ID和SECRET,为需要替换的变量,根据实际获取值更新。其它接口也采用相同的标注,不再说明。
参数说明:
参数 | 必须 | 说明 |
---|---|---|
corpid | 是 | 企业ID,获取方式参考:术语说明-corpid |
corpsecret | 是 | 应用的凭证密钥,获取方式参考:术语说明-secret |
返回结果
{
"errcode": 0,
"errmsg": "ok",
"access_token": "accesstoken000001",
"expires_in": 7200
}
封装获取token的http请求
RestTemplate使用参考:
springboot集成RestTemplate
public String getAccessTokenBySecret(String secret) {
String url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={ID}&corpsecret={SECRET}";
HashMap<String, String> map = MapUtils.newHashMap();
map.put("ID", getCorpid());
map.put("SECRET", secret);
/**
第一个参数:请求地址
第二个参数:返回值类型
第三个参数:请求携带的参数,注意,map里的字段要和url里的占位符字符对应
*/
Map<String, Object> res = restTemplate.getForObject(url, Map.class, map);
return (String) res.get("access_token");
}