PHP code example of tlikai / oauth2china

1. Go to this page and download the library: Download tlikai/oauth2china library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tlikai / oauth2china example snippets


public function actionAuth($provider)
{
    // 导入OAuth2China
    Yii::import('ext.yii-oauth2china.OAuth2China');

    // 配置各平台参数
    $providers = array(
        'weibo' => array(
            'id' => 'App key',
            'secret' => 'App secret',
        ),
        'qq' => array(
            'id' => 'APP ID',
            'secret' => 'APP KEY',
        ),
        'douban' => array(
            'id' => 'API Key',
            'secret' => 'Secret',
        ),
        'renren' => array(
            'id' => 'API key',
            'secret' => 'Secret key',
        ),
    );

    $OAuth2China = new OAuth2China($providers);

    $provider = $OAuth2China->getProvider('qq'); // getProvider方法的参数对应$providers配置中的key

    if(!isset($_GET['code']))
    {
        // 跳转到授权页面
        $provider->redirect();
    }
    else
    {
        // 获取access token
        $token = $provider->getAccessToken($_GET['code']);
        var_dump($token);
    }
}