ghostzero / bitinflow-accounts
3.2.4
2023-09-01 22:20 UTC
Requires
- php: ^7.4|^8.0
- ext-json: *
- firebase/php-jwt: ^6.0
- guzzlehttp/guzzle: ^6.3|^7.0
- illuminate/console: ~5.4|~5.7.0|~5.8.0|^6.0|^7.0|^8.0|^9.0|^10.0
- illuminate/support: ~5.4|~5.7.0|~5.8.0|^6.0|^7.0|^8.0|^9.0|^10.0
- socialiteproviders/manager: ^3.4|^4.0.1
Requires (Dev)
- codedungeon/phpunit-result-printer: ^0.31
- orchestra/testbench: ^6.0
- phpunit/phpunit: ^8.0|^9.0
README
Laravel 5+ 的 PHP bitinflow Accounts API 客户端
目录
安装
composer require ghostzero/bitinflow-accounts
如果您使用 Laravel 5.5+,则已完成,否则继续。
将服务提供者添加到您的 app.php
配置文件中
Bitinflow\Accounts\Providers\BitinflowAccountsServiceProvider::class,
事件监听器
- 将
SocialiteProviders\Manager\SocialiteWasCalled
事件添加到您的app/Providers/EventServiceProvider
中的listen[]
数组。 - 将您的监听器(即来自提供者的监听器)添加到您刚刚创建的
SocialiteProviders\Manager\SocialiteWasCalled[]
。 - 为该提供者添加的监听器是
'GhostZero\\BitinflowAccounts\\Socialite\\BitinflowExtendSocialite@handle',
。 - 注意:除非您使用自己的提供者覆盖它们,否则您不需要为内置的社交提供者添加任何内容。
/**
* The event handler mappings for the application.
*
* @var array
*/
protected $listen = [
\SocialiteProviders\Manager\SocialiteWasCalled::class => [
// add your listeners (aka providers) here
'Bitinflow\\Accounts\\Socialite\\BitinflowExtendSocialite@handle',
],
];
配置
将配置复制到配置文件夹
$ php artisan vendor:publish --provider="Bitinflow\Accounts\Providers\BitinflowAccountsServiceProvider"
将环境变量添加到您的 .env
BITINFLOW_ACCOUNTS_KEY=
BITINFLOW_ACCOUNTS_SECRET=
BITINFLOW_ACCOUNTS_REDIRECT_URI=https://
您需要在服务配置文件中添加一个条目,以便在配置文件缓存用于生产环境(Laravel 命令 artisan config:cache
)之后,所有配置仍然可用。
添加到 config/services.php
'bitinflow-accounts' => [ 'client_id' => env('BITINFLOW_ACCOUNTS_KEY'), 'client_secret' => env('BITINFLOW_ACCOUNTS_SECRET'), 'redirect' => env('BITINFLOW_ACCOUNTS_REDIRECT_URI') ],
示例
基本
$bitinflowAccounts = new Bitinflow\Accounts\BitinflowAccounts(); $bitinflowAccounts->setClientId('abc123'); // Get SSH Key by User ID $result = $bitinflowAccounts->getSshKeysByUserId(38); // Check, if the query was successfull if ( ! $result->success()) { die('Ooops: ' . $result->error()); } // Shift result to get single key data $sshKey = $result->shift(); echo $sshKey->name;
设置器
$bitinflowAccounts = new Bitinflow\Accounts\BitinflowAccounts(); $bitinflowAccounts->setClientId('abc123'); $bitinflowAccounts->setClientSecret('abc456'); $bitinflowAccounts->setToken('abcdef123456'); $bitinflowAccounts = $bitinflowAccounts->withClientId('abc123'); $bitinflowAccounts = $bitinflowAccounts->withClientSecret('abc123'); $bitinflowAccounts = $bitinflowAccounts->withToken('abcdef123456');
OAuth 令牌
$bitinflowAccounts = new Bitinflow\Accounts\BitinflowAccounts(); $bitinflowAccounts->setClientId('abc123'); $bitinflowAccounts->setToken('abcdef123456'); $result = $bitinflowAccounts->getAuthedUser(); $user = $userResult->shift();
$bitinflowAccounts->setToken('uvwxyz456789'); $result = $bitinflowAccounts->getAuthedUser();
$result = $bitinflowAccounts->withToken('uvwxyz456789')->getAuthedUser();
外观
use Bitinflow\Accounts\Facades\BitinflowAccounts; BitinflowAccounts::withClientId('abc123')->withToken('abcdef123456')->getAuthedUser();
文档
Oauth
public function retrievingToken(string $grantType, array $attributes)
支付意向
public function getPaymentIntent(string $id) public function createPaymentIntent(array $parameters)
SSH 密钥
public function getSshKeysByUserId(int $id) public function createSshKey(string $publicKey, string $name = NULL) public function deleteSshKey(int $id)
用户
public function getAuthedUser() public function createUser(array $parameters)
开发
运行测试
composer test
BASE_URL=xxxx CLIENT_ID=xxxx CLIENT_KEY=yyyy CLIENT_ACCESS_TOKEN=zzzz composer test
生成文档
composer docs
加入 bitinflow Discord!