【发布时间】:2017-09-30 19:07:26
【问题描述】:
我正在使用托管在 Heroku 上的 php、Guzzle 6 使用 shopify 网络应用程序创建订单。使用以下代码 sn -p。
//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
【问题讨论】:
-
反复出现是什么意思?我认为脚本没有理由多次发出请求
-
当我检查 Shopify Shopfront 时,一旦创建了 191 个订单,第二次创建了 181 个订单,直到我再次提交有错误的代码,故意防止它发生。我不知道为什么会这样。
-
我认为问题出在 $client->post() 语法上。尝试使用错误的 $url 进行检查,我可以看到已发送 6 个请求。
标签: php heroku http-post guzzle6 shopify-app