PHP + curl,HTTP POST 打开购物车,添加到购物车部分?

PHP + curl, HTTP POST to Open cart, add to cart section?

任何人都可以告诉我如何使用 HTTP POST 执行 PHP curl 以使用 API 打开购物车吗?

我想发送这样的数据:

product_id = 700, quantity = 1

www.example.com

我希望卷曲 return 的响应类似于 {"success":"Success: You have modified your shopping cart!"} 有任何示例吗?

按如下方式操作:

<?php
$output = apirequest();
function apirequest()
{
    $params['product_id'] = 700;
    $params['quantity'] = 1;
    $input = array('data' => json_encode($params));
    $options = array(CURLOPT_RETURNTRANSFER=> true,  //return web page
        CURLOPT_HEADER=> false,  //don't return headers
        CURLOPT_AUTOREFERER=> true,  //set referrer on redirect
        CURLOPT_CONNECTTIMEOUT=> 180,  //timeout on connect
        CURLOPT_TIMEOUT=> 180,  //timeout on response
        CURLOPT_POST=> 1,  //I am sending post data
        CURLOPT_POSTFIELDS=> $input
    );

    $ch = curl_init("www.example.com");
    curl_setopt_array($ch, $options);
    $result = curl_exec($ch);
    curl_close($ch);
    return $result;
}

?>