我正在使用laravel 4框架和magento api soap。这是我的登录方法:
public function APIauthentication( $apiUser, $apiKey ) {
$error = array();
if( empty( $apiUser ) ) {
$error[] = 'Unknown api user';
}
if( empty( $apiKey ) ) {
$error[] = 'Invalid api key';
}
if( empty( $error ) ) {
$client = $this->_getClient();
$token = $client->login( $apiUser, $apiKey );
$this->_setToken( $token );
return $this->_apiJsonResult( $token );
} else {
return $this->_apiJsonResult( $error );
}
}
现在我正在使用laravel屏幕SoapFault Access被拒绝。
如果url不正确或API用户/密钥不正确,我需要返回错误字符串。
像这样:return Redirect::to('user/stores/magento/')->with('status', 'apie user or key is incorrect');
怎么做?有故障代码,但我不知道如何记录 http://www.magentocommerce.com/api/soap/introduction.html#Introduction-GlobalAPIFaults
答案 0 :(得分:0)
SoapFault是一个需要捕获的异常。可以通过Exception访问故障代码和错误字符串。此外,请确保使用'例外'来实例化SoapClient。选项设置为true,否则我认为PHP只会引发致命错误。
if( empty( $error ) ) {
$client = $this->_getClient();
try {
$token = $client->login( $apiUser, $apiKey );
} catch (SoapFault $e) {
// login failed logic
$faultcode = $e->faultcode; // ex: 2
$message = $e->faultstring; // ex: Access denied.
// return redirect, etc...
}
// login successful logic
$this->_setToken( $token );
return $this->_apiJsonResult( $token );
} else {
return $this->_apiJsonResult( $error );
}