0

我正在开发一个系统,它将通过 coinbase php api 将 BTC 发送到某个接收者。该系统在我的本地主机中运行良好,但在将其移至现场后它不起作用并且没有错误消息。我尝试通过回显-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;

非常需要帮助.... :-(

4

1 回答 1

2

Tl;博士。Composer您必须在其余代码之前安装并运行并添加此行:

require __DIR__ . '/vendor/autoload.php';

Coinbase PHP API 用于Composer处理其依赖项,因此必须遵循 Github 上详述的安装过程以避免头痛。

Composer读取 Coinbase PHP API 的作者提供的配置文件,并自动创建一个目录结构,其中包含所需的所有依赖项,最重要的是,自动加载脚本。

PHP 曾经是 100% 独立的,已经内置了过多的函数和类,所以许多 PHP 编码器(例如我)在切换到更模块化的方法时遇到了一些问题,在某种程度上类似于 Python 风格的pip命令或到PEARPerl 星系等等,当然有一些重要的区别。

因此,请务必遵循以下顺序:

1) 假设您在 Linux 上,安装了本地 Web 服务器,并且您网站的文档根目录是/var/www/newsite.

2) 输入您的文档根目录,下载最新的 Coinbase PHP API 版本并解压缩/解压缩。我建议去发布,而不是克隆存储库。

$
$ cd /var/www/newsite

在您的文档根目录中下载 tarball

$
$ 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 日志文件中有许多错误,但此行为取决于服务器配置。

希望这可以帮助!

于 2017-05-21T20:23:41.353 回答