<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
laravel-socialite-providers / socialite-wechat-service-account example snippets
/**
* The event handler mappings for the application.
*
* @var array
*/
protected $listen = [
\SocialiteProviders\Manager\SocialiteWasCalled::class => [
// add your listeners (aka providers) here
'LaravelSocialiteProviders\\WeChatServiceAccount\\WeChatServiceAccountExtendSocialite@handle',
],
];
'wechat_service_account' => [
'client_id' => env('WECHAT_SERVICE_ACCOUNT_APP_ID'),
'client_secret' => env('WECHAT_SERVICE_ACCOUNT_APP_SECRET'),
'redirect' => env('WECHAT_SERVICE_ACCOUNT_CALLBACK_URL'),
'scopes' => preg_split('/,/', env('WECHAT_SERVICE_ACCOUNT_SCOPES'), null, PREG_SPLIT_NO_EMPTY), // can not use explode, see vlucas/phpdotenv#175
'union_id_with' => preg_split('/,/', env('WECHAT_SERVICE_ACCOUNT_UNION_ID_WITH'), null, PREG_SPLIT_NO_EMPTY),
],
// default need user grant, and then you can get user info(nickname, unionid, openid...)
return Socialite::with('wechat_service_account')->redirect();
// not need user grant, and then you can only get openid
return Socialite::with('wechat_service_account')->scopes('snsapi_base')->redirect();
// to turn off stateless
return Socialite::with('wechat_service_account')->stateless(false)->redirect();
// to use stateless
return Socialite::with('wechat_service_account')->stateless()->redirect();
// default use openid as $user->id
$user = Socialite::driver('wechat_service_account')->user();
$accessTokenResponseBody = $user->accessTokenResponseBody;
// use unionid as $user->id
$user = Socialite::driver('wechat_service_account')->scopes('unionid')->user();
// not need user grant, you can only get openid
$user = Socialite::driver('wechat_service_account')->scopes('snsapi_base')->user();