yunwuxin/think-social

ThinkPHP6 Social SDK

Installs: 382

Dependents: 0

Suggesters: 0

Security: 0

Stars: 63

Watchers: 7

Forks: 16

Open Issues: 2

Type:think-extend

v3.1.2 2023-10-10 06:02 UTC

This package is auto-updated.

Last update: 2024-04-10 06:57:53 UTC


README

安装

composer require yunwuxin/think-social

配置

目前支持4个平台的:qq,weibo,github,wechat

配置示例

...
  'weibo' => [
    'client_id'     => 'your-app-id',
    'client_secret' => 'your-app-secret',
  ],
...

使用

路由

Route::get('auth/:channel/callback', 'Auth/handleSocialCallback');
Route::get('auth/:channel', 'Auth/redirectToSocial');

控制器

<?php

namespace app\controller;

use yunwuxin\Social;

class AuthController extends Controller
{

    public function redirectToSocial(Social $social, $channel)
    {
        return $social->channel($channel)->redirect();
        // return $social->channel($channel)->scopes(['scope1','scope2'])->redirect();
    }

    public function handleSocialCallback(Social $social,$channel)
    {
        $user = $social->channel($channel)->user();

        // $user->getToken();
        // $user->getId();
        // $user->getName();
        // $user->getNickname();
        // $user->getAvatar();
        // $user->getEmail();
    }
}