“账户登录错误或您的账户暂时被禁用。请稍候,稍后重试。”}

问题描述 投票:0回答:1

我已经在 Magento 中为客户创建了一个用户。我需要为客户创建一个登录 api。为此,我需要一个令牌来使用。为了生成它,我使用了以下代码,最终出现以下错误。

{"message":"帐号登录错误或您的帐号暂时被禁用,请稍后重试。"}

我的代码如下

    <?php

$userData = ["username" => "[email protected]", "password" => "xxx"];
$ch = curl_init("https://www.djbjsdjs.com/rest/V1/integration/customer/token");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($userData));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Content-Lenght: " . strlen(json_encode($userData))));

$token = curl_exec($ch);
print_r($token);
php magento2 magento-rest-api
1个回答
0
投票

首先,调用 /rest/default/V1/integration/customer/token 而不是 /index.php/rest/default/V1/integration/customer/token。

其次,确保您不调用映射的子域。例如,如果您将 localhost 或 127.0.0.1 映射到 /etc/hosts 中的 mydomain.local,则不要调用 http://mydomain.local/rest/default/V1/integration/customer/token,而是调用http://127.0.0.1/rest/default/V1/integration/customer/token

© www.soinside.com 2019 - 2024. All rights reserved.