2016-11-13 52 views
-1

我得到一個數組從外部公司在我laravel應用Laravel獲得刀片陣列,其中包含「bns:OrderId」名稱?

處理傳入的JSON有名稱類似:在它的BNS的OrderId'?

片給出一個錯誤,當我試圖訪問{{$命令 - > BNS:的OrderId}}

我該怎麼處理這個?

控制器:

public function getBolOrders() 
{ 
    // or live API: https://plazaapi.bol.com 
    $url = 'https://test-plazaapi.bol.com'; 
    $uri = '/services/rest/orders/v1/open'; 

    // your public key 
    $public_key = '<public key>'; 

    //your private key 
    $private_key = '<private key>'; 

    $port = 443; 
    $contenttype = 'application/xml'; 
    $date = gmdate('D, d M Y H:i:s T'); 
    $httpmethod = 'GET'; 

    $signature_string = $httpmethod . "\n\n"; 
    $signature_string .= $contenttype . "\n"; 
    $signature_string .= $date."\n"; 
    $signature_string .= "x-bol-date:" . $date . "\n"; 
    $signature_string .= $uri; 
    $signature = $public_key.':'.base64_encode(hash_hmac('SHA256', $signature_string, $private_key, true)); 

    // Setup CURL (One can also opt to use sockets or http libraries, but CURL is a versatile, widespread solution) 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: ".$contenttype, "X-BOL-Date:".$date, "X-BOL-Authorization: ".$signature)); 
    curl_setopt($ch, CURLOPT_URL, $url.$uri); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($ch, CURLOPT_PORT, $port); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 

    $result = curl_exec($ch); 
    $orders = fopen("orders.xml", "w"); 
    fwrite($orders, $result); 
    fclose($orders); 
    if(curl_errno($ch)) { 
     print_r(curl_errno($ch), true); 
    } 
// Clean up after ourselves 
    curl_close($ch); 
// Convert XML TO JSON 
    $xmlNode = simplexml_load_file('orders.xml'); 
    $arrayData = xmlToArray($xmlNode); 
    $OpenOrder = $arrayData['OpenOrders']['bns:OpenOrder']; 
// dd($OpenOrder); 
// Goto view 
    return view('bol.open-orders', compact('OpenOrder')); 
} 

DD從數組:

array:2 [▼ 
    0 => array:6 [▼ 
    "bns:OrderId" => "123" 
    "bns:DateTimeCustomer" => "2016-11-07T15:20:08.904" 
    "bns:DateTimeDropShipper" => "2016-11-07T15:20:08.904" 
    "bns:Paid" => "true" 
    "bns:Buyer" => array:2 [▶] 
    "bns:OpenOrderItems" => array:1 [▶] 
] 
1 => array:6 [▼ 
    "bns:OrderId" => "321" 
    "bns:DateTimeCustomer" => "2016-11-07T15:20:08.904" 
    "bns:DateTimeDropShipper" => "2016-11-07T15:20:08.904" 
    "bns:Paid" => "false" 
    "bns:Buyer" => array:2 [▶] 
    "bns:OpenOrderItems" => array:1 [▶] 
    ] 
] 

實施例葉片的模板:

@foreach ($OpenOrder as $order) 
    {{ $order->bns:OrderId }} 
@endforeach 
+0

提供您的控制器和完整的查詢。讓我看看'dd($ OpenOrder);'數據。 –

+0

改變問題文本 –

+0

請不要共享您的憑據,例如:公共和普里瓦重點公共區域.. :) –

回答

0

該查詢返回arrays值不是Object的集合。使用此{{ $order["bns:OrderId"] }}而不是此{{ $order->bns:OrderId }}

試試這個:

@foreach ($OpenOrder as $order) 
    {{ $order["bns:OrderId"] }} 
@endforeach 
+0

這並獲得成功!謝謝 –

+0

@RudiWerner樂於幫助:) –