PHP code example of kuainiu / yii2-kuainiu

1. Go to this page and download the library: Download kuainiu/yii2-kuainiu 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/ */

    

kuainiu / yii2-kuainiu example snippets


//按需配置
'modules' => [
    'kuainiu' => [
        'class' => 'kuainiu\Module',
    ],
    ...
],

//全局配置
$config = [
    'components' => [
        'authClientCollection' => [
            'class' => 'yii\authclient\Collection',
            'clients' => [
                'kuainiu' => [
                    'class' => 'kuainiu\components\authclient\Kuainiu',
                    'clientId' => 'kuainiu_client_id',
                    'clientSecret' => 'kuainiu_client_secret',
                    'authUrl' => 'https://*domain*/auth',
                    'tokenUrl' => 'https://*domain*/auth/token',
                    'apiBaseUrl' => 'https://*domain*/api'
                ],
            ],
        ],
    ]
];
 

'modules' => [
    'kuainiu' => [
        'class' => 'kuainiu\Module',
        'tableMap' => [ // Optional, but if defined, all must be declared
            'user_table'            =>  '{{%user}}',
            'username_field'        =>  'name',
            'email_field'           =>  'email',
            'password_hash_field'   =>  'password_hash',
            'fullname_field'        =>  'chinese_name',
            'avatar_field'          =>  'avatar',
            'position_field'        =>  'position',
        ],
        'profileMap' => [ // Optional, but if defined, all must be declared
            'username_field'        =>  'name',
            'email_field'           =>  'email',
            'fullname_field'        =>  'chinese_name',
            'avatar_field'          =>  'avatar',
            'position_field'        =>  'position',
        ],
    ],
    ...
],

public function actionLogin()
{
	if (!Yii::$app->user->isGuest) {
    	return $this->goHome();
	}
    $this->redirect(['kuainiu/user/auth','authclient'=>'kuainiu']);
}

use kuainiu\components\KuainiuClient;
...
$client = new KuainiuClient();
$response = $client->DepartmentList(82);

use kuainiu\components\KuainiuClient;
...
$client = new FondClient();
$response = $client->DepartmentUser(82);

use kuainiu\components\KuainiuClient;
...
$client = new FondClient();
$response = $client->Notification('Allen', 'Hello World');
html
//头像
<?=Yii::$app->user->identity->avatar