• Stars
    star
    109
  • Rank 317,871 (Top 7 %)
  • Language
    PHP
  • Created about 10 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

OAuthClient QQ Weibo Weixin Douban Renren Amazon

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());
}

More Repositories

1

yii2-uploadify-widget

JavaScript
19
star
2

yii2-lazyload-widget

http://www.appelsiini.net/projects/lazyload
PHP
17
star
3

yii2-qrcode-widget

http://sourceforge.net/projects/phpqrcode/
PHP
14
star
4

yii2-sitemap

yii2-sitemap
PHP
13
star
5

yii2-weui-widget

PHP
12
star
6

yii2-bootbox-widget

https://github.com/makeusabrew/bootbox
PHP
11
star
7

snoopy

fork http://sourceforge.net/projects/snoopy/
PHP
5
star
8

yii2-xunsearch

stoped dev. https://github.com/hightman/xs-sdk-php
PHP
5
star
9

yii2-jplayer-widget

http://www.jplayer.org/
PHP
4
star
10

yii2-rsa

Yii2-RSA-encrypt-decrypt
PHP
4
star
11

yii2-introjs-widget

http://usablica.github.io/intro.js/
PHP
3
star
12

yii2-user-agent

https://github.com/donatj/PhpUserAgent
PHP
3
star
13

yii2-lightbox2-widget

https://github.com/lokesh/lightbox2/
PHP
3
star
14

yii2-rbac-module

Yii2 RBAC Manger
PHP
3
star
15

yii2-imagesloaded-widget

http://imagesloaded.desandro.com/
PHP
2
star
16

yii2-mosaic-widget

https://github.com/buildinternet/mosaic
JavaScript
2
star
17

yii2-ratchet-widget

https://github.com/twbs/ratchet
PHP
2
star
18

yii2-dropzone-widget

http://www.dropzonejs.com/
PHP
2
star
19

yii2-weui.js

PHP
2
star
20

yii2-db-reconnect

yii\db\Connection - auto reconnect
PHP
2
star
21

yii2-timesheet-widget

https://github.com/sbstjn/timesheet.js
PHP
2
star
22

yii2-hoverzoom-widget

http://www.htmldrive.net/items/demo_show/1133
JavaScript
1
star
23

yii2-d3-widget

https://github.com/mbostock/d3
PHP
1
star
24

yii2-jquery-hash-widget

jquery-hash plugins Yii2 Assets
PHP
1
star
25

yii2-metroui

https://github.com/olton/Metro-UI-CSS
PHP
1
star
26

yii2-jquery-mobile-widget

https://github.com/jquery/jquery-mobile
JavaScript
1
star
27

yii2-angular-widget

https://github.com/angular/bower-angular
PHP
1
star
28

yii2-juxtapose-widget

https://github.com/NUKnightLab/juxtapose
PHP
1
star
29

php-rsa

php-rsa
PHP
1
star
30

yii2-ducky-widget

https://github.com/rse/ducky
PHP
1
star
31

yii2-jquery-zoom-widget

http://www.jacklmoore.com/zoom/
PHP
1
star
32

yii2-modernizr-widget

https://github.com/Modernizr/Modernizr
PHP
1
star
33

yii2-webuploader-widget

https://github.com/fex-team/webuploader
PHP
1
star
34

yii2-imgareaselect-widget

https://github.com/odyniec/imgareaselect
PHP
1
star
35

yii2-easing-widget

https://github.com/gdsmith/jquery.easing
PHP
1
star
36

yii2-tagit-widget

https://github.com/aehlke/tag-it
PHP
1
star
37

yii2-galleria-widget

https://github.com/aino/galleria
PHP
1
star