我正在开发一个系统,它将通过coinbase php api将BTC发送给某个接收者。系统在我的localhost中工作正常但在将其移动到生存后它不起作用并且没有错误消息。我尝试通过回显-3并运行脚本逐步跟踪错误,我发现当我把回声放在
之后$account = $client->getPrimaryAccount();
echo -3;
......我有一个白页,没有-3作为测试结果。
以下是此过程的完整构建:
$apiKey = "dfdsfsd";
$apiSecret = "fdsfdsfsfdff";
$configuration = Configuration::apiKey($apiKey, $apiSecret);
$client = Client::create($configuration);
$_btc_wallet = @$_GET['_btcwallet'];
$_btc_amount = @$_GET['_btc_amount'];
$transaction = Transaction::send([
'toBitcoinAddress' => $_btc_wallet,
'bitcoinAmount' => $_btc_amount,
'description' => 'Group Fund Transfer',
]);
$account = $client->getPrimaryAccount();
echo -3;
$client->createAccountTransaction($account, $transaction);
echo 1;
exit;
急需帮助......: - (
答案 0 :(得分:2)
铊;博士。您必须先安装并运行
Composer
并添加此行 你的其余代码:require __DIR__ . '/vendor/autoload.php';
Coinbase PHP API使用Composer
来处理它的依赖关系,因此遵循Github上详细介绍的安装过程是必须的,以避免头痛。
Composer
读取Coinbase PHP API作者提供的配置文件,并自动创建一个包含所需所有依赖项的目录结构,最重要的是自动加载脚本。
PHP过去是100%自包含的,已经内置了大量的函数和类,所以许多PHP编码器(例如我)在切换到更模块化的方法时遇到了一些问题,类似于Python风格它的pip
命令或Perl galaxy中的PEAR
等等,当然还有一些重要的区别。
所以,请务必遵循以下顺序:
1)假设您使用的是Linux,安装了本地Web服务器,并且您的网站的文档根目录为/var/www/newsite
。
2)输入您的文档根目录,下载最新的Coinbase PHP API版本并解压缩/解压缩。我建议去发布,而不是克隆存储库。
$
$ cd /var/www/newsite
$
$ tar xzvf coinbase-php-2.5.0.ta.gz
3)现在您需要下载Composer
。转到https://getcomposer.org/的主页,然后点击下载。按照命令行安装部分中的说明进行操作。
为方便起见,我在这里报告,但它们可能会发生变化,因此请务必查看Composer
的主页。从您的文档根目录:
$ php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
$ php -r "if (hash_file('SHA384', 'composer-setup.php') === '669656bab3166a7aff8a7506b8cb2d1c292f042046c5a994c43155c0be6190fa0355160742ab2e1c88d40d5be660b410') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
$ php composer-setup.php
$ php -r "unlink('composer-setup.php');"
4)最后一步,运行Composer
并等待他完成工作:
$ php composer.phar install
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 26 installs, 0 updates, 0 removals
- Installing guzzlehttp/promises (v1.3.1): Downloading (100%)
- Installing psr/http-message (1.0.1): Downloading (100%)
- Installing guzzlehttp/psr7 (1.4.2): Downloading (100%)
- Installing guzzlehttp/guzzle (6.2.3): Downloading (100%)
- Installing psr/log (1.0.2): Downloading (100%)
- Installing symfony/yaml (v3.2.8): Downloading (100%)
- Installing sebastian/version (1.0.6): Downloading (100%)
- Installing sebastian/global-state (1.1.1): Downloading (100%)
- Installing sebastian/recursion-context (1.0.5): Downloading (100%)
- Installing sebastian/exporter (1.2.2): Downloading (100%)
- Installing sebastian/environment (1.3.8): Downloading (100%)
- Installing sebastian/diff (1.4.2): Downloading (100%)
- Installing sebastian/comparator (1.2.4): Downloading (100%)
- Installing doctrine/instantiator (1.0.5): Downloading (100%)
- Installing phpunit/php-text-template (1.2.1): Downloading (100%)
- Installing phpunit/phpunit-mock-objects (2.3.8): Downloading (100%)
- Installing phpunit/php-timer (1.0.9): Downloading (100%)
- Installing phpunit/php-file-iterator (1.4.2): Downloading (100%)
- Installing phpunit/php-token-stream (1.4.11): Downloading (100%)
- Installing phpunit/php-code-coverage (2.2.4): Downloading (100%)
- Installing webmozart/assert (1.2.0): Downloading (100%)
- Installing phpdocumentor/reflection-common (1.0): Downloading (100%)
- Installing phpdocumentor/type-resolver (0.2.1): Downloading (100%)
- Installing phpdocumentor/reflection-docblock (3.1.1): Downloading (100%)
- Installing phpspec/prophecy (v1.7.0): Downloading (100%)
- Installing phpunit/phpunit (4.8.35): Downloading (100%)
symfony/yaml suggests installing symfony/console (For validating YAML files using the lint command)
sebastian/global-state suggests installing ext-uopz (*)
phpunit/phpunit-mock-objects suggests installing ext-soap (*)
phpunit/php-code-coverage suggests installing ext-xdebug (>=2.2.1)
phpunit/phpunit suggests installing phpunit/php-invoker (~1.1)
Writing lock file
Generating autoload files
$
5)记住上面的最后一行。 Github的Coinbase PHP API自述文件中的示例有点误导,因为Composer
很好并且创建了一个名为autoload.php
的文件,必须使用它来以正确的方式加载新库。
因此,这里修改了您的代码以使用它,从而加载所有必需的依赖项:
<?php
require __DIR__ . '/vendor/autoload.php';
$apiKey = 'topsecret';
$apiSecret = 'topkey';
$configuration = Configuration::apiKey($apiKey, $apiSecret);
$client = Client::create($configuration);
$account = $client->getPrimaryAccount();
该行:
require __DIR__ . '/vendor/autoload.php';
应该有所作为。没有它,脚本退出时屏幕上没有错误,但php日志文件中有很多错误,但这种行为取决于服务器配置。
希望这有帮助!