官方开发文档:文档 - 企业微信开发者中心
获取access_token
请求方式 |
GET | |
请求地址 | https://qyapi.weixin.qq.com/cgi-bin/gettoken | |
请求参数 | 是否必填 | 说明 |
corpid | 是 | 企业ID,参考:术语说明-corpid |
corpsecret | 是 | 应用密钥,参考:术语说明-secret |
获取到的access_token用户后续的操作,作为鉴权调用者的身份。获取到的access_token在有效期内无需重复获取(注意:不能频繁调用gettoken接口,否则会受到频率拦截),待到失效或过有效期,需要重新获取(access_token的有效期通过返回的expires_in来传达)。
/**
* 通过cache缓存暂存access_token
*/
public function __construct(){
if (Cache::has('access_token')) {
$this->access_token = Cache::get('access_token');
} else {
$url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=%s&corpsecret=%s";
$response = $this->curlAll(sprintf($url,$this->corpid,$this->secret));
$response = json_decode($response,true);
if($response['errcode'] != 0){
return false;
}else{
Cache::put('access_token', $response['access_token'], $response['expires_in']);