0

我是 CoinBase 的新手。

我正在使用 getAccounts() 方法来获取所有帐户。

$this->client->getAccounts();

这将返回一个对象类型的对象(Coinbase\Wallet\Resource\ResourceCollection)

object(Coinbase\Wallet\Resource\ResourceCollection)[37]
  private 'previousUri' => null
  private 'nextUri' => null
  private 'resources' => 
    array (size=1)
      0 => 
        object(Coinbase\Wallet\Resource\Account)[35]
          private 'name' => string 'BTC Wallet' (length=10)
          private 'primary' => boolean true
          private 'type' => string 'wallet' (length=6)
          private 'currency' => string 'BTC' (length=3)
          private 'balance' => 
            object(Coinbase\Wallet\Value\Money)[43]
              ...
          private 'nativeBalance' => 
            object(Coinbase\Wallet\Value\Money)[47]
              ...
          private 'createdAt' => 
            object(DateTime)[48]
              ...
          private 'updatedAt' => 
            object(DateTime)[49]
              ...
          private 'id' (Coinbase\Wallet\Resource\Resource) => string 'b12d3892-1228-5da1-a779-c5104bcbd749' (length=36)
          private 'resource' (Coinbase\Wallet\Resource\Resource) => string 'account' (length=7)
          private 'resourcePath' (Coinbase\Wallet\Resource\Resource) => string '/v2/accounts/b12d3892-1228-5da1-a779-c5104bcbd749' (length=49)
          private 'rawData' (Coinbase\Wallet\Resource\Resource) => 
            array (size=11)
              ...

使用 (array) 转换响应会在响应中提供无效字符。

   array (size=3)
  '�Coinbase\Wallet\Resource\ResourceCollection�previousUri' => null
  '�Coinbase\Wallet\Resource\ResourceCollection�nextUri' => null
  '�Coinbase\Wallet\Resource\ResourceCollection�resources' => 
    array (size=1)
      0 => 
        object(Coinbase\Wallet\Resource\Account)[35]
          private 'name' => string 'BTC Wallet' (length=10)
          private 'primary' => boolean true
          private 'type' => string 'wallet' (length=6)
          private 'currency' => string 'BTC' (length=3)
          private 'balance' => 
            object(Coinbase\Wallet\Value\Money)[43]
              ...
          private 'nativeBalance' => 
            object(Coinbase\Wallet\Value\Money)[47]
              ...
          private 'createdAt' => 
            object(DateTime)[48]
              ...
          private 'updatedAt' => 
            object(DateTime)[49]
              ...
          private 'id' (Coinbase\Wallet\Resource\Resource) => string 'b12d3892-1228-5da1-a779-c5104bcbd749' (length=36)
          private 'resource' (Coinbase\Wallet\Resource\Resource) => string 'account' (length=7)
          private 'resourcePath' (Coinbase\Wallet\Resource\Resource) => string '/v2/accounts/b12d3892-1228-5da1-a779-c5104bcbd749' (length=49)
          private 'rawData' (Coinbase\Wallet\Resource\Resource) => 
            array (size=11)
              ...

任何帮助将不胜感激。

阿努普

4

2 回答 2

0

能够通过以下代码进行纠正。

 $accountResponse = $this->client->getAccounts();
  foreach ($accountResponse->all() as &$account) {
  $responseData[] = $account->getRawData();
 }
于 2016-06-29T12:19:38.947 回答
-1

尝试像这样转换:

$accounts = json_decode(json_encode($this->client->getAccounts()), true);

更新

$accounts = $this->client->getAccounts();
$resources = $accounts->all();

foreach($resources as $index=>$details) {

  $accArr = [];

  foreach($details as $key=>$detail) {

    $method = 'get'.ucfirst($key).'()';
    $accArr[$key] = $detail->{$method};
    $accountsContainer[] = $accArr;

  }

}
var_dump($accountsContainer);
于 2016-06-28T13:27:52.290 回答