QQ OAuth 2.0 support for the PHP League's OAuth 2.0 Client
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
.gitignore
LICENSE.txt
README.md
composer.json

README.md

oauth2-qq

QQ OAuth 2.0 support for the PHP League's OAuth 2.0 Client ##Install You can open a terminal and type in

composer require spoonwep/oauth2-qq

or require in a composer.json

"require": {
	"spoonwep/oauth2-qq": "~1.3"
}

then run:

composer update

##Useage

session_start();
$provider = new \spoonwep\OAuth2\Client\Provider\Qq([
	'clientId' => '{QQ APP ID}',
	'clientSecret' => '{QQ APP KEY}',
	'redirectUri' => 'http://example.com/callback-url',
]);
if (!isset($_GET['code'])) {
	$authUrl = $provider->getAuthorizationUrl();
	$_SESSION['oauth2state'] = $provider->getState();
	header('Location: '.$authUrl);
	exit;
} elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) {
	unset($_SESSION['oauth2state']);
	exit('Invalid state');
} else {
	$token = $provider->getAccessToken('authorization_code', [
		'code' => $_GET['code']
	]);

	//fetch userinfo returned by serverside
    $user = $provider->getResourceOwner($token);
    $user = $user->toArray();
    print_r($user);

    //get user's unique openid from serverside
    $openid = $provider->openid;
    printf('User\'s openid:%s', $openid);
}

###License The MIT License (MIT). Please see License File for more information.