From b07f4b9924497d96f845e69d5eb4e30a5b46d6b5 Mon Sep 17 00:00:00 2001 From: gaoyiping Date: Sat, 14 Jul 2018 15:58:31 +0800 Subject: [PATCH] =?UTF-8?q?add:=20=E7=94=A8=E6=88=B7=E5=8F=AF=E8=87=AA?= =?UTF-8?q?=E5=B7=B1=E8=AE=BE=E7=BD=AEAccessToken?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WeChat/Contracts/BasicWeChat.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/WeChat/Contracts/BasicWeChat.php b/WeChat/Contracts/BasicWeChat.php index 83c9a3d..df01cb4 100644 --- a/WeChat/Contracts/BasicWeChat.php +++ b/WeChat/Contracts/BasicWeChat.php @@ -108,6 +108,28 @@ class BasicWeChat return $this->access_token = $result['access_token']; } + /** + * 直接设置accessToken + * @param string $access_token + * @return void + * @throws \WeCaht\Exceptions\InvalidArgumentException + * @author 高一平 + * + * 当用户使用自己的缓存驱动时,直接实例化对象后可直接设置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 * @return bool