PHP code example of cblink / hyperf-socialite
1. Go to this page and download the library: Download cblink/hyperf-socialite 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/ */
cblink / hyperf-socialite example snippets
return [
// 需要加载的provider
'providers' => [
// \HyperfSocialiteProviders\Feishu\Provider::class,
],
'config' => [
'facebook' => [
'client_id' => '',
'client_secret' => '',
// 其他provider中需要使用的配置
// ...
],
// qq,weixin... ]()
],
];
use Cblink\Hyperf\Socialite\Contracts\SocialiteInterface;
class Controller
{
/**
* @param SocialiteInterface $socialite
* @return \Hyperf\HttpServer\Contract\ResponseInterface
*/
public function redirectToProvider(SocialiteInterface $socialite)
{
// 重定向跳转
$redirect = $socialite->driver('facebook')->redirect();
// 使用新的配置跳转
$socialite->driver('facebook')->setConfig([
'client_id' => 'xxx',
'client_secret' => 'xxxx',
])
return $redirect;
}
/**
* @param SocialiteInterface $socialite
*/
public function handleProviderCallback(SocialiteInterface $socialite)
{
// 获取用户信息
$user = $socialite->driver('facebook')->user();
//
// $user->token;
}
}
shell
# 安装
composer hp bin/hyperf.php vendor:publish cblink/hyperf-socialite