PHP code example of fangcloud / fangcloud-php-sdk

1. Go to this page and download the library: Download fangcloud/fangcloud-php-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/ */

    

fangcloud / fangcloud-php-sdk example snippets








YfyAppInfo::init($clientId, $clientSecret, $callbackUri);

// 初始化应用信息
YfyAppInfo::init($clientId, $clientSecret, $callbackUri);
// 可配置参数
$options = [
  YfyClientOptions::ACCESS_TOKEN => $accessToken,
  YfyClientOptions::REFRESH_TOKEN => $refreshToken
];
// 构造client
$client = new YfyClient($options);
// 调用api
$client->users()->getSelf();

# 获取授权url, 让用户跳转到这个url上以完成授权
$authorizationUrl =  $client->oauth()->getAuthorizationUrl();

# 在回调页面调用这个函数, sdk会帮助你校验state, 并且构造请求获取access token
$res = $client->oauth()->finishAuthorizationCodeFlow($code, $state);
$accessToken = $res['access_token'];
$refreshToken = $res['refresh_token'];

$res = $client->oauth()->getTokenByPasswordFlow($username, $password);
$accessToken = $res['access_token'];
$refreshToken = $res['refresh_token'];

$options = [
  YfyClientOptions::RANDOM_STRING_GENERATOR => RandomStringGeneratorFactory::create('random_bytes')
];
$client = new YfyClient(options);
bash
# 安装composer
curl -sS https://getcomposer.org/installer | php
bash
php composer.phar 

git clone [email protected]:yifangyun/fangcloud-php-sdk.git

php -S localhost:8000