2016-11-06 167 views
0

我正在开发一个系统,通过coinbase php api将BTC发送到某个接收器。系统在我的本地主机上正常工作,但移动到现场后无法正常工作,也没有错误信息。我试图呼应-3跟踪一步一个错误的步骤并运行该脚本,我发现,当我把回声PHP Coinbase API不工作,但在本地主机上工作

$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; 

需要帮助的厉害.... :-(

回答

2

铊;博士,您必须安装并运行Composer之前加入这一行。你的代码的 休息:

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

Coinbase PHP API使用Composer来处理它的依赖关系,以便遵循Github上详细介绍的安装过程,以避免头痛。

Composer读取由Coinbase PHP API作者提供的配置文件,并自动创建一个目录结构,该结构包含所需的所有依赖关系,最重要的是自动载入脚本。 PHP过去是100%自包含的,有很多功能和类已经内置,所以很多PHP编码器(例如我)有一些问题需要切换到更模块化的方法,有些类似于Python风格在Perl星系中有pip命令或PEAR,等等,当然还有一些重要的区别。

所以,一定要遵循以下步骤:

1)假设你是在Linux上,您必须安装本地Web服务器,和你的网站的文档根目录是/var/www/newsite。 2)输入您的文档根目录,下载最新的Coinbase PHP API版本并解压缩/解压缩。我建议去发布版本,而不是克隆版本库。

$ 
$ cd /var/www/newsite 

Download the tarball in your document root

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

希望这会有所帮助!

相关问题