r4kib / cloudbeds-api
PHP版本的cloudbeds.com API包装器
v0.0.1
2019-07-03 10:20 UTC
Requires
- league/oauth2-client: ^2.4
Requires (Dev)
- mockery/mockery: ^1.0
- phpunit/phpunit: ^7.5
This package is auto-updated.
Last update: 2024-09-29 05:21:44 UTC
README
Cloudbeds.com API包装器,PHP与Laravel集成
安装
composer require r4kib/cloudbeds-api
使用方法
初始化类
$cloudbeds = new \R4kib\Cloudbeds\Cloudbeds([ 'clientId' => 'yourId', // The client ID assigned to you by Amazon 'clientSecret' => 'yourSecret', // The client password assigned to you by Amazon 'redirectUri' => 'yourRedirectUri', // The return URL you specified for your app on Amazon 'version' => 'v1.1' // API Version, default v1.1 ]);
初始化类(Laravel版本)
- 发布配置
php artisan vendor:publish --config
- 在
.env
文件中设置API详细信息
CLOUDBEDS_API_CLIENT_ID=yourId
CLOUDBEDS_API_CLIENT_SECRET=yourSecret
CLOUDBEDS_API_REDIRECT_URI=yourRedirectUri
CLOUDBEDS_API_VERSION=v1.1
- 获取单例对象
$cloudbeds = resolve("R4kib\\Cloudbeds\\Cloudbeds");
OAuth助手
此实现中的OAuth部分遵循thephpleague/oauth2-client。有关详细信息,请参阅该链接。
$oauthHelper= $cloudbeds->getOauthHelper(); // Get authorization code if (!isset($_GET['code'])) { // Get authorization URL $authorizationUrl = $oauthHelper->getAuthorizationUrl(); // Redirect user to authorization URL header('Location: ' . $authorizationUrl); exit; } else { // Get access token $accessToken = $oauthHelper->getAccessToken( 'authorization_code', [ 'code' => $_GET['code'] ] ); // Get resource owner $resourceOwner = $oauthHelper->getResourceOwner($accessToken); // Now you can store the results to session etc. $_SESSION['accessToken'] = $accessToken; $_SESSION['resourceOwner'] = $resourceOwner; var_dump( $resourceOwner->getID(), $resourceOwner->getFirstName(), $resourceOwner->getLastName(), $resourceOwner->getEmail() ); }
发送API请求
// $params is [key=>value] array. See cloudbeds.com API documentation to view params. $cloudbeds->get('/path',$accessToken,$params); $cloudbeds->post('/path',$accessToken,$params); $cloudbeds->put('/path',$accessToken,$params); $cloudbeds->delete('/path',$accessToken,$params);
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。