2017 © Pedro Peláez
 

library yii2-oauth

yii2-oauth

image

xj/yii2-oauth

yii2-oauth

  • Tuesday, July 10, 2018
  • by xjflyttp
  • Repository
  • 16 Watchers
  • 102 Stars
  • 3,492 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 42 Forks
  • 2 Open issues
  • 10 Versions
  • 8 % Grown

The README.md

# yii2-oauth

### composer.json

"require": {
        "xj/yii2-oauth": "~2.0.0"
},

### config

'components' => [
    'authClientCollection' => [
        'class' => 'yii\authclient\Collection',
        'clients' => [
            'qq' => [
                'class' => 'xj\oauth\QqAuth',
                'clientId' => '111',
                'clientSecret' => '111',

            ],
            'weibo' => [
                'class' => 'xj\oauth\WeiboAuth',
                'clientId' => '111',
                'clientSecret' => '111',
            ],
            'weixin' => [
                'class' => 'xj\oauth\WeixinAuth',
                'clientId' => '111',
                'clientSecret' => '111',
            ],
            'renren' => [
                'class' => 'xj\oauth\RenrenAuth',
                'clientId' => '111',
                'clientSecret' => '111',
            ],
            'douban' => [
                'class' => 'xj\oauth\DoubanAuth',
                'clientId' => '111',
                'clientSecret' => '111',
            ],
            'weixin-mp' => [
                'class' => 'xj\oauth\WeixinMpAuth',
                'clientId' => '111',
                'clientSecret' => '111',
            ],
            'amazon' => [
                'class' => 'xj\oauth\AmazonAuth',
                'clientId' => '',
                'clientSecret' => '',
            ],
        ]
    ]
    ...
]

### Controller

class SiteController extends Controller
{
    public function actions()
    {
        return [
            'auth' => [
                'class' => 'yii\authclient\AuthAction',
                'successCallback' => [$this, 'successCallback'],
            ],
        ];
    }

    /**
     * Success Callback
     * @param QqAuth|WeiboAuth $client
     * @see http://wiki.connect.qq.com/get_user_info
     * @see http://stuff.cebe.cc/yii2docs/yii-authclient-authaction.html
     */
    public function successCallback($client) {
        $id = $client->getId(); // qq | sina | weixin
        $attributes = $client->getUserAttributes(); // basic info
        $openid = $client->getOpenid(); //user openid
        $userInfo = $client->getUserInfo(); // user extend info
        var_dump($id, $attributes, $openid, $userInfo);
    }
}

### View

<?=
yii\authclient\widgets\AuthChoice::widget([
    'baseAuthUrl' => ['site/auth'],
    'popupMode' => false,
])
?>

WeixinMp

$weixinMp = Yii::$app->authClientCollection->getClient('weixin-mp');

// http://mp.weixin.qq.com/wiki/11/0e4b294685f817b95cbed85ba5e82b8f.html
// getAccessToken
$accessTokenResult = $weixinMp->getMpAccessToken();
if ($accessTokenResult->validate()) {
    $accessTokenResult->access_token;
    $accessTokenResult->expires_in;
    $accessTokenResult->getAccessToken(); // WeixinMpToken
} else {
    var_dump($accessTokenResult->getErrCodeText());
    var_dump($accessTokenResult->getErrors());
}

// http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html#.E8.8E.B7.E5.8F.96api_ticket
// getTicket
$accessTokenResult = $weixinMp->getMpAccessToken();
$ticketType = 'jsapi'; // wx_card
$ticketResult = $weixinMp->getTicket($accessTokenResult->access_token, $ticketType);
if ($ticketResult->validate()) {
    $accessTokenResult->ticket; // TicketString
} else {
    var_dump($ticketResult->getErrCodeText());
    var_dump($ticketResult->getErrors());
}

The Versions

10/07 2018

dev-master

9999999-dev

yii2-oauth

  Sources   Download

BSD-3-Clause

The Requires

 

by Avatar xjflyttp

10/07 2018

2.0.3

2.0.3.0

yii2-oauth

  Sources   Download

BSD-3-Clause

The Requires

 

by Avatar xjflyttp

11/04 2018

2.0.2

2.0.2.0

yii2-oauth

  Sources   Download

BSD-3-Clause

The Requires

 

by Avatar xjflyttp

07/09 2016

2.0.1

2.0.1.0

yii2-oauth

  Sources   Download

BSD-3-Clause

The Requires

 

by Avatar xjflyttp

11/08 2016

2.0.0

2.0.0.0

yii2-oauth

  Sources   Download

BSD-3-Clause

The Requires

 

by Avatar xjflyttp

15/03 2016

1.0.4

1.0.4.0

yii2-oauth

  Sources   Download

BSD-3-Clause

The Requires

 

by Avatar xjflyttp

16/07 2015

1.0.3

1.0.3.0

yii2-oauth

  Sources   Download

BSD-3-Clause

The Requires

 

by Avatar xjflyttp

19/01 2015

1.0.2

1.0.2.0

yii2-oauth

  Sources   Download

BSD-3-Clause

The Requires

 

by Avatar xjflyttp

02/12 2014

1.0.1

1.0.1.0

yii2-oauth

  Sources   Download

BSD-3-Clause

The Requires

 

by Avatar xjflyttp

08/08 2014

1.0.0

1.0.0.0

yii2-oauth

  Sources   Download

BSD-3-Clause

The Requires

 

by Avatar xjflyttp