getAuthorizeUrl() public method

Get baidu oauth2's authorization granting url.
public getAuthorizeUrl ( string $responseType = 'code', string $scope = '', string $state = '', string $display = 'popup' ) : string
$responseType string Response type, 'code' or 'token'
$scope string blank space separated list of requested extended perms
$state string state parameter
$display string Authorization page style, 'page', 'popup', 'touch' or 'mobile'
return string Page url for authorization granting
Example #1
0
 public function authorize()
 {
     global $_G, $_GET;
     if (empty($_G['uid'])) {
         dsetcookie('_refer', rawurlencode(BASESCRIPT . '?mod=connect&op=oauth&bz=baiduPCS'));
         showmessage('to_login', '', array(), array('showmsg' => true, 'login' => 1));
     }
     require_once DZZ_ROOT . './core/api/BaiduPCS/BaiduOAuth2.php';
     $cloud = DB::fetch_first("select `key` , `secret` from " . DB::table('connect') . " where bz='baiduPCS'");
     $auth = new BaiduOAuth2($cloud['key'], $cloud['secret']);
     $auth->setRedirectUri($_G['siteurl'] . 'index.php?mod=connect&op=oauth&bz=baiduPCS');
     if ($_GET['code'] && (($state = authcode($_GET['state'], 'DECODE')) == $cloud['key'] || $state == 'in_admin_' . $cloud['key']) && ($token = $auth->getAccessTokenByAuthorizationCode($_GET['code']))) {
         $token['refreshtime'] = TIMESTAMP;
         $token['uid'] = strpos($state, 'in_admin_') === 0 ? 0 : $_G['uid'];
         if ($token['access_token'] && ($userinfo = $auth->getLoggedInUser($token['access_token']))) {
             $token['cuid'] = $userinfo['uid'];
             $token['cusername'] = $userinfo['uname'];
             $token['portrait'] = $userinfo['portrait'];
         }
         if ($token['cuid']) {
             if ($id = DB::result_first("select id from " . DB::table(self::T) . " where uid='{$token[uid]}' and cuid='{$token[cuid]}' and bz='baiduPCS'")) {
                 DB::update(self::T, $token, "id ='{$id}'");
             } else {
                 $token['bz'] = 'baiduPCS';
                 $token['dateline'] = TIMESTAMP;
                 $id = DB::insert(self::T, $token, 1);
             }
             if (strpos($state, 'in_admin_') === 0) {
                 //插入企业盘空间库(local_storage);
                 $setarr = array('name' => '百度网盘:' . $token['cusername'], 'bz' => 'baiduPCS', 'isdefault' => 0, 'dname' => self::T, 'did' => $id, 'dateline' => TIMESTAMP);
                 if (!DB::result_first("select COUNT(*) from %t where did=%d and dname=%s", array('local_storage', $id, self::T))) {
                     C::t('local_storage')->insert($setarr);
                 }
             }
         }
         if (strpos($state, 'in_admin_') === 0) {
             $returnurl = 'admin.php?mod=cloud&op=space';
         } else {
             $returnurl = 'index.php?mod=connect';
         }
         header('Location: ' . $returnurl);
         //include template('oauth');
         exit;
     }
     $clientid = $cloud['key'];
     $state = authcode(defined('IN_ADMIN') ? 'in_admin_' . $clientid : $clientid, 'ENCODE');
     $authorizeurl = $auth->getAuthorizeUrl('code', 'basic netdisk', $state);
     //exit($authorizeurl);
     header('Location: ' . $authorizeurl);
 }