SaeTOAuthV2::getAuthorizeURL PHP Method

getAuthorizeURL() public method

对应API:{@link http://open.weibo.com/wiki/Oauth2/authorize Oauth2/authorize}
public getAuthorizeURL ( string $url, string $response_type = 'code', string $state = NULL, string $display = NULL ) : array
$url string 授权后的回调地址,站外应用需与回调地址一致,站内应用需要填写canvas page的地址
$response_type string 支持的值包括 code 和token 默认值为code
$state string 用于保持请求和回调的状态。在回调时,会在Query Parameter中回传该参数
$display string 授权页面类型 可选范围: - default 默认授权页面 - mobile 支持html5的手机 - popup 弹窗授权页 - wap1.2 wap1.2页面 - wap2.0 wap2.0页面 - js js-sdk 专用 授权页面是弹窗,返回结果为js-sdk回掉函数 - apponweibo 站内应用专用,站内应用不传display参数,并且response_type为token时,默认使用改display.授权后不会返回access_token,只是输出js刷新站内应用父框架
return array
    function getAuthorizeURL($url, $response_type = 'code', $state = NULL, $display = NULL)
    {
        $params = array();
        $params['client_id'] = $this->client_id;
        $params['redirect_uri'] = $url;
        $params['response_type'] = $response_type;
        $params['state'] = $state;
        $params['display'] = $display;
        return $this->authorizeURL() . "?" . http_build_query($params);
    }

Usage Example

Example #1
0
 private function reflashToken()
 {
     if (empty($this->m_cfg['username']) || empty($this->m_cfg['password'])) {
         return;
     }
     $this->m_reflash_cookie = tmpDir('reflashsina.cookie');
     if (!file_exists($this->m_reflash_cookie)) {
         touch($this->m_reflash_cookie);
     }
     $loginResult = $this->curlLoginSina($this->m_cfg['username'], $this->m_cfg['password']);
     if (!$loginResult) {
         return $loginResult;
     }
     $callbackUrl = callbackUrl('sina');
     $o = new SaeTOAuthV2($this->m_cfg['key'], $this->m_cfg['secret']);
     $authorizeURL = $o->getAuthorizeURL($callbackUrl);
     $ch = curl_init($authorizeURL);
     $option = array();
     $option[CURLOPT_FOLLOWLOCATION] = 1;
     $option[CURLOPT_RETURNTRANSFER] = 1;
     $option[CURLOPT_COOKIEJAR] = $this->m_reflash_cookie;
     $option[CURLOPT_COOKIEFILE] = $this->m_reflash_cookie;
     $option[CURLOPT_HTTPHEADER] = array('Accept-Language: zh-cn', 'Connection: Keep-Alive', 'Cache-Control: no-cache');
     $option[CURLOPT_USERAGENT] = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)";
     curl_setopt_array($ch, $option);
     curl_exec($ch);
     curl_close($ch);
     unlink($this->m_reflash_cookie);
 }
All Usage Examples Of SaeTOAuthV2::getAuthorizeURL