Пример #1
0
 public function public_accesstoken($platdata, $get_user_data = true, $url = '')
 {
     $code = $this->input[$platdata['response_type']];
     $openid = $this->input['openid'];
     if ($code) {
         $keys = array();
         $keys[$platdata['response_type']] = $code;
         $keys['redirect_uri'] = $platdata['callback'];
         $o = new Oauth($platdata['akey'], $platdata['skey'], $platdata['response_type']);
         $access_token = $o->getAccessToken($url ? $url : $this->settings['share_plat'][$platdata['type']]['accessurl'], $keys);
         //根据uid,name,access_token获取用户头像,名称
         $uid = empty($access_token['uid']) ? '' : $access_token['uid'];
         $name = empty($access_token['name']) ? '' : $access_token['name'];
         if ($get_user_data) {
             $data['userdata'] = $this->get_user->show_user($platdata, $access_token, $uid, $name, $openid, $url);
             if ($this->input['uid'] && $data['userdata']['id'] != $this->input['uid']) {
                 return false;
             }
             if ($data['userdata']['error']) {
                 return false;
             }
         }
         if (!empty($access_token['access_token'])) {
             //更新到数据库中
             if ($this->obj->updatetoken($platdata['token'], array('access_token' => json_encode($access_token), 'openid' => $openid, 'addTime' => TIMENOW))) {
                 $data['openid'] = $openid;
                 $data['access_token'] = $access_token;
                 $data['access_plat_token'] = $platdata['token'];
                 return $data;
             } else {
                 return 'GET_FAILD';
             }
         } else {
             return 'NO_ACCESS_TOKEN';
         }
     } else {
         return 'NO_RESPONSE_TYPE';
     }
 }
Пример #2
0
 public function oauth_callback()
 {
     $id = intval(ISession::get('oauth'));
     if (!$id) {
         $this->redirect('login');
         exit;
     }
     $oauthObj = new Oauth($id);
     $result = $oauthObj->checkStatus($_GET);
     if ($result === true) {
         $oauthObj->getAccessToken($_GET);
         $userInfo = $oauthObj->getUserInfo();
         if (isset($userInfo['id']) && isset($userInfo['name']) && $userInfo['id'] != '' && $userInfo['name'] != '') {
             $this->bindUser($userInfo, $id);
         } else {
             $this->redirect('login');
         }
     } else {
         $this->redirect('login');
     }
 }
        parse_str($urlArray['query']);
        $info['oauth_token'] = $oauth_token;
    }
    if (array_key_exists('oauth_token', $info) && array_key_exists('oauth_token_secret', $info) && array_key_exists('authentication_url', $info)) {
        echo "Request token        : " . $info['oauth_token'] . "\n";
        echo "Request token secret : " . $info['oauth_token_secret'] . "\n";
        echo "Next please authenticate yourself at " . $info['authentication_url'] . "?oauth_token=" . $info['oauth_token'] . " and collect the PIN for the next step.\n";
        $oauth_client->setToken($info['oauth_token'], $info['oauth_token_secret']);
    } else {
        Error("getRequestToken", null, $info, $oauth_client->getLastResponseInfo(), null);
    }
} catch (OAuthException $E) {
    Error("getRequestToken", $E->getMessage(), null, $oauth_client->getLastResponseInfo(), $E->debugInfo);
}
$pin = readline("Pin: ");
try {
    $info = $oauth_client->getAccessToken("{$api_url_base}/oauth1/access_token/v1", null, $pin);
    if (array_key_exists('oauth_token', $info) && array_key_exists('oauth_token_secret', $info)) {
        echo "Access token        : " . $info['oauth_token'] . "\n";
        echo "Access token secret : " . $info['oauth_token_secret'] . "\n";
        echo "\nYou can store these access token values in access_token.php for the other scripts to use.\n";
        $oauth_client->setToken($info['oauth_token'], $info['oauth_token_secret']);
    } else {
        Error("getAccessToken", null, $info, $oauth_client->getLastResponseInfo(), null);
    }
} catch (OAuthException $E) {
    Error("getAccessToken exception", $E->getMessage(), null, $oauth_client->getLastResponseInfo(), $E->debugInfo);
}
?>

<?php

if (isset($_REQUEST['oauth_token']) && isset($_REQUEST['oauth_verifier'])) {
    if (isset($_POST['oauth_token'])) {
        try {
            $oauth_client = new Oauth("key", "secret");
            $oauth_client->enableDebug();
            $oauth_client->setToken($_POST['oauth_token'], $_POST['oauth_token_secret']);
            $info = $oauth_client->getAccessToken("http://192.168.187.132/oauth/access_token", null, $_POST['oauth_verifier']);
            echo "<h1>Congrats !</h1>";
            echo "<strong>AccessToken</strong> " . $info['oauth_token'] . "<br />";
            echo "<strong>AccessToken Secret</strong> " . $info['oauth_token_secret'];
            echo "<a href=\"apicall.php?token=" . $info['oauth_token'] . "&token_secret=" . $info['oauth_token_secret'] . "\">get your user id with an api call</a>";
        } catch (OAuthException $E) {
            echo print_r($E->debugInfo);
        }
    } else {
        ?>
			<form method="post" action="callback.php">
				<label>token</label>
				<input type="text" name="oauth_token" value="<?php 
        echo $_REQUEST['oauth_token'];
        ?>
" /><br />
				<label>secret</label>
				<input type="text" name="oauth_token_secret" value="" />
				<span>This is not passed by url, a real client would have stored this somewhere, you can get it from the db</span>
				<br />
				<label>verifier</label>
				<input type="text" name="oauth_verifier" value="<?php 
        echo $_REQUEST['oauth_verifier'];