为什么我不能通过php + curl从opencart获取真实内容?

时间:2019-02-07 17:39:02

标签: php curl xmlhttprequest opencart

我需要opencart的自动购买脚本。注册和购物车运作良好。我发现XHR发布请求以保存结果,但是当我尝试结帐时,出现此错误:

$ch = curl_init();

curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, 'http://some_url.com/index.php?route=checkout/payment_method/save');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'payment_method=pp_pro&comment=&agree=1');
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$data = curl_exec($ch);

print $data;

{"error":{"warning":"Warning: Payment method required!"}}

1 个答案:

答案 0 :(得分:0)

Opencart API是解决您的问题的方法。观看下面的视频:

https://www.youtube.com/watch?v=bc2govdEiuA

OpenCart API允许您的应用程序访问OpenCart中的当前数据。通过API,可以在OpenCart上执行几个常用操作。操作包括:

create —使用指定的参数创建。 例如,您可以按照OpenCart API对产品或product_id的请求后的要求将产品添加到购物车中 /index.php?route=api/cart/add read —读取有关指定对象的信息。 query —检索符合指定条件的对象。 update —更新现有对象的元素。 upsert —更新现有对象的元素(如果存在)。如果该对象不存在,则使用提供的参数创建一个。

https://webocreation.com/blog/opencart-api-documentation-to-create-read-query-update-and-upsert