使用集成的Shopware6身份验证有时无法正常工作以下是我的代码
$authData = array('client_id' => $client_id,
'client_secret' => $client_secret,
'scopes' => 'write',
'grant_type' => 'client_credentials',
);
$url = rtrim($url, '/') . '/api/oauth/token';
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($authData));
curl_setopt( $curl,
CURLOPT_HTTPHEADER,
['Content-Type: application/json; charset=utf-8']
);
$response = json_decode(curl_exec($curl));
echo "<pre>";
print_r($response);
exit;它说用户凭据不正确,但凭据是正确的,您能帮我提前谢谢...
发布于 2020-10-26 19:21:52
我使用的是Guzzle客户端,一切都很正常。我使用next代码
$httpClient = new Client();
$postBody = json_encode([
'grant_type' => 'client_credentials',
'client_id' => $this->sw6AccessKey,
'client_secret' => $this->sw6SecretKey
]);
$response = $httpClient->post('http://test.com/api/oauth/token', [
'headers' => ['Content-Type' => 'application/json'],
'body' => $postBody
]);一般来说,您的代码看起来不错。
请确保凭据正确,并且在Shopware集成设置中启用了写入权限。
https://stackoverflow.com/questions/64535712
复制相似问题