beakerboy / cashid-library
PHP 的 CashID 库
v0.1.0
2019-06-26 23:33 UTC
Requires
- php: >=7.0.0
- bitcoin-php/bitcoin-ecdsa: >=1.3
- submtd/cashaddr-converter: >=1.0.1
Requires (Dev)
This package is auto-updated.
Last update: 2024-09-29 05:20:54 UTC
README
依赖关系
- 任何 PSR-16 兼容的缓存(如 paillechat/apcu-simple-cache)
- BitcoinPHP ECDSA 库
- CashaddrConverter
规范
- CashID API (https://gitlab.com/cashid/protocol-specification)
设置
将此库和所选的缓存实现添加到您的项目中的 composer.json 文件中
{ "require": { "beakerboy/cashid-library": "0.*", "paillechat/apcu-simple-cache": "*" } }
使用 composer 安装库
$ php composer.phar install
Composer 会将 CashID 安装在您的 vendor 文件夹中。然后您可以在 .php 文件中添加以下内容以使用库的自动加载。
require_once(__DIR__ . '/vendor/autoload.php');
或者,在命令行中使用 composer 来引入并安装 CashID
$ php composer.phar require beakerboy/cashid-library:0.* paillechat/apcu-simple-cache:*
最低要求
- PHP 7.1
示例
创建 CashID 请求
<?php use CashID\Services\RequestGenerator; use Paillechat\ApcuSimpleCache\ApcuCache; // Specify your server details $domain = 'mydomain.com'; $listener_script = '/api/parse.php'; // Create your cache $cache = new ApcuCache(); // Create a request generator $generator = new RequestGenerator($domain, $listener_script, $cache); // Create a minimal request $requestURI = $generator->createRequest(); // Validate that the request was created if($requestURI !== false) { // Show a QR code / share with NFC the $requestURI }
验证 CashID 响应
<?php use CashID\Services\ResponseHandler; use Paillechat\ApcuSimpleCache\ApcuCache; // Specify your server details $domain = 'mydomain.com'; $listener_script = '/api/parse.php'; // Create your cache $cache = new ApcuCache(); // Create a response handler $handler = new ResponseHandler($domain, $listener_script, $cache); // Capture the response $response = file_get_contents('php://input'); // Parse the request. $request = $handler->validateRequest($response); // Validate the request. if($request !== false) { // Perform the $request['action'] using $request['data'] and $request['metadata']. } // Send the request confirmation. $handler->confirmRequest();