Merge pull request #13 from gaoyiping/master

add: 用户可自己设置AccessToken
This commit is contained in:
邹景立 2018-07-14 16:04:35 +08:00 committed by GitHub
commit 3bab455cd6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -108,6 +108,28 @@ class BasicWeChat
return $this->access_token = $result['access_token']; return $this->access_token = $result['access_token'];
} }
/**
* 直接设置accessToken
* @param string $access_token
* @return void
* @throws \WeCaht\Exceptions\InvalidArgumentException
* @author 高一平 <iam@gaoyiping.com>
*
* 当用户使用自己的缓存驱动时直接实例化对象后可直接设置AccessToekn
* - 多用于分布式项目时保持AccessToekn统一
* - 使用此方法后就由用户来保证传入的AccessToekn为有效AccessToekn
*/
public function setAccessToken($access_token) {
if (!is_string($access_token)) {
throw new InvalidArgumentException("Invalid AccessToken type, need string.");
}
// 使用默认获取access_token的方法
if (is_null($access_token) || empty($access_token)) {
$this->access_token = '';
}
$this->access_token = $access_token;
}
/** /**
* 清理删除accessToken * 清理删除accessToken
* @return bool * @return bool