Guzzle 6批量Httppost请求购买api

时间:2017-09-30 19:07:27

标签: php heroku http-post guzzle6 shopify-app

我使用php,Guzzle 6在Heroku上托管shopify网络应用程序创建订单。使用了以下代码段。

        //json encode
    $orderdata = array(
        'order' => array(
        'line_items' => array(
                    0 => array(
                        'title' => 'Avocado',
                        'quantity' => 1,
                        'variant_id' => 42837938757,
                        'vendor'=>'Saaraketha Organics',
                        'product_id'=>9043955845
                        ),
                    )
            )
        );
    $order = json_encode ($orderdata);
        $logcontent = "$order\n";
    file_put_contents("php://stderr", $logcontent);

    //create client and post data
        $url =(string)('https://api_key:password@domain/admin/orders.json');
        $client = new Client();
        $RequestResponse = $client->post($url, ['headers' => ['Content-Type' => 'application/json', 'Accept' => 'application/json'], 'body' => $order]);

虽然它成功创建了订单,但却反复发生。

这是我得到的Heroku日志。 Log

enter image description here

1 个答案:

答案 0 :(得分:0)

我已经弄清楚了。 该应用程序正在订单创建webhook上调用。在同一个应用程序控制器中,它会发布订单,这会再次触发相同的webhook,从而产生无限的请求序列。