PHP code example of yangxiaozhan / fc-ucenter-sdk

1. Go to this page and download the library: Download yangxiaozhan/fc-ucenter-sdk 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/ */

    

yangxiaozhan / fc-ucenter-sdk example snippets




use FC\UCenter\UCenterClient;

$ucenter = new UCenterClient(
    baseUrl: 'https://fcu.cdfcz.com',
    appKey: getenv('UCENTER_APP_KEY'),
    appSecret: getenv('UCENTER_APP_SECRET'),
);

// 从 Session 恢复 Token
$ucenter->setTokens($_SESSION['access_token'] ?? null, $_SESSION['refresh_token'] ?? null);

$ucenter->sendSms('13800138000');
$result = $ucenter->loginWithPhoneSms('13800138000', '123456');

$_SESSION['access_token'] = $ucenter->getAccessToken();
$_SESSION['refresh_token'] = $ucenter->getRefreshToken();

$profile = $ucenter->getProfile();

// 微信登录:PC 扫码 / 手机微信内直接授权
$oauth = $ucenter->getWechatLoginUrl('https://your-app.com/oauth/callback');
header('Location: ' . $oauth['url']);

// 手动指定模式
$oauth = $ucenter->getOAuthUrl('wechat', 'https://your-app.com/oauth/callback', ['mode' => 'qr']);