【问题标题】:Why i cant get real content by php+curl from opencart?为什么我无法通过 opencart 中的 php+curl 获取真实内容?
【发布时间】:2019-07-01 21:56:35
【问题描述】:

我需要 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!"}}

【问题讨论】:

  • 其中哪一部分不起作用,您预计会发生什么?要具体并详细说明。
  • index.php?route=checkout/payment_address - 给我真实的信息。但接下来的步骤只返回我的模板。

标签: php curl xmlhttprequest opencart


【解决方案1】:

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

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

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

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

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

【讨论】:

  • 我不想在我的商店购买,我可以在哪里获得使用 api 的令牌?
  • {"error":"警告:用户名和/或密码不匹配。"}
  • 在上面的视频中大约 2:30 分钟显示youtu.be/bc2govdEiuA?t=149 Admin >> System >> Users >> API,您可以在其中创建它们。
  • 请您的管理员为 API 用户提供访问权限,否则我认为没有转机 :)
猜你喜欢
  • 2017-07-30
  • 2010-10-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-08-20
  • 2012-09-28
  • 2017-07-25
  • 2021-11-05
相关资源
最近更新 更多