2016-11-06 166 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日誌文件中有很多錯誤,但這種行爲取決於服務器配置。

希望這會有所幫助!

相關問題