/** * 获取授权公众号的令牌 * * @return string */ public function getToken() { $cacheKey = sprintf($this->cacheKey, $this->authorizerAppId); $this->token = $this->getCache()->fetch($cacheKey); if (!$this->token) { $params = array('component_appid' => $this->componentAppId, 'authorizer_appid' => $this->authorizerAppId, 'authorizer_refresh_token' => $this->authorizerRefreshToken); $http = new ComponentHttp(new ComponentAccessToken($this->componentAppId, $this->componentAppSecret, $this->cache)); $response = $http->json(self::API_AUTHORIZER_TOKEN, $params); Log::debug(is_array($response) ? json_encode($response) : $response); // 设置token $token = $response['authorizer_access_token']; // 把token缓存起来 $this->setToken($response['authorizer_access_token'], $response['authorizer_refresh_token']); return $token; } return $this->token; }
/** * 设置授权方的选项信息 * * @param $authorizerAppId * @param $optionName * @param $optionValue * @return mixed */ public function setAuthorizerOption($authorizerAppId, $optionName, $optionValue) { $params = array('component_appid' => $this->componentAppId, 'authorizer_appid' => $authorizerAppId, 'option_name' => $optionName, 'option_value' => $optionValue); return $this->http->json(self::API_SET_AUTHORIZER_OPTION, $params); }