我在Magento2订单API连接上遇到错误

时间:2018-09-05 10:29:04

标签: api magento2.2.3

可捕获的致命错误:无法在此行上将stdClass类的对象转换为字符串

  

curl_setopt($ ch,CURLOPT_HTTPHEADER,array(“ Content-Type:   application / json“,”授权:承载“。json_decode($ token)));

$userData = array("username" => "xxxx", "password" => "xxxxxx");
    $ch = curl_init("http://magento2.local.com/index.php/rest/V1/integration/admin/token");
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($userData));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Content-Lenght: " . strlen(json_encode($userData))));

    $token = curl_exec($ch);

    $ch = curl_init("http://magento2.local.com/index.php/rest/V1/orders/1");
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Authorization: Bearer " . json_decode($token)));

    $result = curl_exec($ch);

    $result = json_decode($result, 1);
    echo '<pre>';print_r($result);

0 个答案:

没有答案