1000nettles/factom-api-php

Factom API 的简单 PHP 封装

0.1.1 2017-10-26 23:13 UTC

This package is not auto-updated.

Last update: 2024-09-29 03:10:18 UTC


README

为任何 Factom API v2 调用(包括对 factomdfactom-walletd 的调用)提供一个简单的 PHP 封装

在这里找到 Factom API 参考文档: https://docs.factom.com/api

安装

使用 Composer

composer require 1000nettles/factom-api-php

常规要求

require_once('FactomAPIAdapter.php');

如何使用

启动任何 Factom 命令行应用程序

PHP Factom API 集成连接到本地运行的 factomdfactom-walletd 实例。当您在本地或服务器上运行这些应用程序时,它们作为服务运行,允许您通过 https://:8088(factomd)或 https://:8089(factom-walletd)进行连接。您可以在这里了解更多关于运行这些服务的信息 - https://docs.factom.com/cli

对于 factomd,您可能可以连接到“礼遇节点”,例如 http://courtesy-node.factom.com,但这些并不保证。我没有测试是否有 API 限制。更多信息请参阅: https://docs.factom.com/#run-enterprise-wallet-online

实例化 Factom API 适配器

注意,我们在下面的 API 版本 2 中提供了完整的 URL。

$url = 'https://:8088/v2';
$adapter = new FactomAPIAdapter($url);

如果您想安全地与 API 交互,请确保您以 TLS 模式运行 factomd - ./factomd -tls true。您还应该在实例化适配器时传递您的证书位置,并将 URL 更改为 HTTPS

$url = 'https://:8088/v2';
$certLocation = '~/.factom/m2/factomdAPIpub.cert';
$adapter = new FactomAPIAdapter($url, $certLocation);

如果您想使用用户名和密码与 API 交互,请确保您以用户名和密码定义运行 factomd - ./factomd -rpcuser <username> -rpcpass <password>。如果您愿意,也可以用证书运行此操作。

$url = 'https://:8088/v2';
$username = 'user';
$password = 'password';
$adapter = new FactomAPIAdapter($url, null, $username, $password);

使用您的参数运行 API 方法!

API 方法概述在这里: https://docs.factom.com/api

$method = 'POST';
$result = $adapter->call('transaction', $method, array('hash' => '64251aa63e011f803c883acf2342d784b405afa59e24d9c5506c84f6c91bf18b'));

发送 GET 请求

某些 API 方法使用 GET 方法而不是 POST。例如,factom-walletd 中的 'address' 方法: https://docs.factom.com/api#address。您可以轻松运行此操作

$method = 'GET';
$result = $adapter->call('address', $method, array('address' => 'FA2jK2HcLnRdS94dEcU27rF3meoJfpUcZPSinpb7AwQvPRY6RL1Q'));

就是这样。如果您遇到 cURL 问题,可能是因为您没有安装 PHP cURL 库。

测试

抱歉!目前没有。

已知问题

  • 目前,如果您使用安全连接(TLS)并提供证书路径,我们将通过将 CURLOPT_SSL_VERIFYPEER 设置为 false 来忽略 cURL 自签名证书警告。
  • 调试 API 端点无法通过此包装器访问