regalii / regaliator
本包最新版本(1.0.1)没有提供许可证信息。
用于连接 Regalii API 的 PHP 客户端库
1.0.1
2017-02-01 22:47 UTC
Requires
- php: >=5.2
- rmccue/requests: ^1.7
This package is not auto-updated.
Last update: 2024-09-23 13:27:46 UTC
README
连接 Regalii API 的 PHP 客户端。
使用方法
在您的 composer.json
文件中引入 regalii/regaliator
之后,您可以使用该类如下所示
$configuration = new Regaliator\Configuration([ 'version' => '3.1', 'api_host' => 'api.casiregalii.com', 'api_key' => getenv('REGALII_API_KEY'), 'secret_key' => getenv('REGALII_SECRET') ]); $regaliator = new Regaliator\Regaliator($configuration); $response = $regaliator->account(); if ($response->success) { $data = json_decode($response->body, true); } else { echo "Failed with status code {$response->status_code}"; }
$response
将是来自 Requests 库的 Response
对象。
示例
一些常见用例的示例
创建凭证账单
$response = $regaliator->create_credentials_bill(12376, 'login', 'challengeme'); $bill = json_decode($response->body, true); echo "Created bill {$bill['id']}\n";
账单获取时的轮询
function poll_while_updating($regaliator, $id) { for($i = 0; $i < 60; $i++) { echo "Checking status for bill {$id} after sleeping 1 second\n"; sleep(1); $response = $regaliator->show_bill($id); $bill = json_decode($response->body, true); if ($bill['status'] !== 'fetching') { return $bill; } } // raise exception because bill is still fetching } $bill = poll_while_updating($regaliator, $bill['id']);
回答 MFA 挑战
$response = $regaliator->update_bill_mfas($bill['id'], ['mfa_challenges' => [ [ 'id' => $bill['mfa_challenges'][0]['id'], 'type' => $bill['mfa_challenges'][0]['type'], 'response' => '8' ] ]]);