如何调用CS购物车API来创建订单?

时间:2019-04-17 09:31:11

标签: php api iis crud cs-cart

我正在我的一个CS购物车网站中创建api函数,并通过api函数提交订单。

这是针对运行MySQL 5,PHP 5.6和IIS的新Windows服务器。而且我正在邮递员上尝试验证已传输的数据。

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://my-testwebsite.com/api.php?_d=orders&ajax_custom=1",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "{\r\n  \"user_id\": \"4\",\r\n  \"shipping_id\": \"0\",\r\n  \"payment_id\": \"6\",\r\n  \"products\": {\r\n      \"1000323256\": {\r\n        \"product_id\": \"1002\",\r\n        \"amount\": \"100\"\r\n       },\r\n      \"103101663\": {\r\n        \"product_id\": \"1002\",\r\n        \"amount\":\"100\"\r\n      }\r\n  }\r\n}",
  CURLOPT_HTTPHEADER => array(
    "Authorization: Basic dmluY2VudC5hcm9ja2lhcmFqQGZ1amlmaWxtLmNvbTplUUE3NzdmN2RrSUR0ODVieVoyM1R0NDYxVzMwRGNTMQ==",
    "Content-Type: application/json",
    "Postman-Token: 050a8bff-d6da-4a0d-b6e8-4cb01bd2c112",
    "cache-control: no-cache"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;