Example #1
0
 /**
  * 通过code授权
  *
  * @param string $code
  *
  * @return array
  */
 protected function authorize($code)
 {
     if ($this->authResult) {
         return $this->authResult;
     }
     // 关闭自动加access_token参数
     Wechat::autoRequestToken(false);
     $params = array('appid' => Wechat::getOption('appId'), 'secret' => Wechat::getOption('secret'), 'code' => $code, 'grant_type' => 'authorization_code');
     $authResult = Wechat::request('GET', self::API_TOKEN_GET, $params);
     // 开启自动加access_token参数
     Wechat::autoRequestToken(true);
     //TODO:refresh_token机制
     return $this->authResult = $authResult;
 }