OpenCart 4 API在PHP中的调用



我试图在PHP中使用OpenCart 4 API,但我不知道如何正确获得令牌以及如何进行API调用。文档是用Python编写的,所以我甚至无法获得用于身份验证的令牌。

我使用下面的代码获得了早期版本的令牌:


$post = [
'username' => 'Username',
'key' => 'key',
];
$ch = curl_init('http://localhost/index.php?route=api/login');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
?>

但是在我得到令牌之后,我不知道如何进行实际调用来获取订单和其他东西,因为没有PHP文档。

在新版本(4.0.0.0)中,这段代码为我提供了一个未找到页面的HTML响应。所以有人知道如何做正确的调用在php在新的或旧的版本。如果PHP中有任何关于新版本或旧版本的文档,那将非常有帮助。

提前感谢!

我看到登录路径与以前的版本相比发生了变化。api/账户/登录

$post = [
'username' => 'Username',
'key' => 'key',
];
$ch = curl_init('http://localhost/index.php?route=api/account/login');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$response = curl_exec($ch);
curl_close($ch);
echo $response;

最新更新