PHP code example of laravel-socialite-providers / socialite-wechat-web

1. Go to this page and download the library: Download laravel-socialite-providers/socialite-wechat-web 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/ */

    

laravel-socialite-providers / socialite-wechat-web example snippets


/**
 * The event handler mappings for the application.
 *
 * @var array
 */
protected $listen = [
    \SocialiteProviders\Manager\SocialiteWasCalled::class => [
        // add your listeners (aka providers) here
        'LaravelSocialiteProviders\\WeChatWeb\\WeChatWebExtendSocialite@handle',
    ],
];

'wechat_web' => [
    'client_id' => env('WECHAT_WEB_APP_ID'),
    'client_secret' => env('WECHAT_WEB_APP_SECRET'),
    'redirect' => env('WECHAT_WEB_CALLBACK_URL'),
    'scopes' => preg_split('/,/', env('WECHAT_WEB_SCOPES'), null, PREG_SPLIT_NO_EMPTY), // can not use explode, see vlucas/phpdotenv#175
    'union_id_with' => preg_split('/,/', env('WECHAT_WEB_UNION_ID_WITH'), null, PREG_SPLIT_NO_EMPTY),
],

return Socialite::with('wechat_web')->redirect();

// to turn off stateless
return Socialite::with('wechat_web')->stateless(false)->redirect();

// to use stateless
return Socialite::with('wechat_web')->stateless()->redirect();

$clientId = "secret";
$clientSecret = "secret";
$redirectUrl = "http://yourdomain.com/api/redirect";
$additionalProviderConfig = [
    // Add additional configuration values here.
];
$config = new \SocialiteProviders\Manager\Config(
    $clientId,
    $clientSecret,
    $redirectUrl,
    $additionalProviderConfig
);

return Socialite::with('wechat_web')->setConfig($config)->redirect();

// default use openid as $user->id
$user = Socialite::driver('wechat_web')->user();
$accessTokenResponseBody = $user->accessTokenResponseBody;

// use unionid as $user->id
$user = Socialite::driver('wechat_web')->scopes('unionid')->user();

$user = Socialite::driver('wechat_web')->setOpenId($openId)->userFromToken($token);
 php
'providers' => [
    // a whole bunch of providers
    // remove 'Laravel\Socialite\SocialiteServiceProvider',
    \SocialiteProviders\Manager\ServiceProvider::class, // add
];