这是我使用的库https://github.com/php-twinfield/
当我调用 Oauth 登录时,这是一个问题。我已经用用户名和密码完成了几乎所有的 API,但客户希望它使用 Oauth。我认为redirectUri 有问题。当我调用 Oauth 时,它总是显示:
{
"success": false,
"error": "invalid_grant"
}
这是我的凭证。Clientid 和 clientsecret 是从邮件和从 Openid Twinfield 链接设置的重定向 uri 中获取的。如果凭据有任何错误,请纠正我。
clientId : Demorent
clientSecret : /iY7gyWn3Hkdgs4XzUG66SDyPNkk177x3A==
redirectUri : https://www.oauth.client.redirect.uri.com
使用的代码:
public function login(\Illuminate\Http\Request $request)
{
try {
// In the $request param all the credential given
$provider = new \PhpTwinfield\Secure\Provider\OAuthProvider([
'clientId' => $request->clientId,
'clientSecret' => $request->clientSecret,
'redirectUri' => $request->redirectUri
]);
// Here pass the authorization code
$accessToken = $provider->getAccessToken("authorization_code", ["code" =>'NLA000067']);
$refreshToken = $accessToken->getRefreshToken();
$office = \PhpTwinfield\Office::fromCode("1008");
$connection = new \PhpTwinfield\Secure\OpenIdConnectAuthentication($provider, $refreshToken, $office);
$customerApiConnector = new \PhpTwinfield\ApiConnectors\CustomerApiConnector($connection);
$result = $customerApiConnector->get('1008',$office);
$jsonResponse = JsonResponse::success($result);
} catch(SoapFault $e) {
$jsonResponse = empty($e->getMessage()) ? JsonResponse::error(class_basename($e)) : JsonResponse::error($e->getMessage());
}
return $jsonResponse;
}