简体   繁体   English

Magento:Soap API无法正常工作

[英]Magento : Soap api not working

Hi i am using magento vesion 1. 9 and i am trying to call magento soap apiv2 using php. 嗨,我正在使用magento vesion1。9,我正在尝试使用php调用magento soap apiv2。

i use the following code. 我使用以下代码。

$proxy = new SoapClient('http://domain/index.php/api/v2_soap/?wsdl=1');
$sessionId = $proxy->login((object)array('username' => 'user', 'apiKey' => 'password'));
$product=$proxy->catalogProductInfo((object)array('sessionId' => $sessionId->result, 'productId' => '27'));

i get the session id (i testes it by printing the id) but when i make a soap call 我得到了会话ID(我通过打印ID进行测试),但是当我打了个电话时

$product=$proxy->catalogProductInfo((object)array('sessionId' => $sessionId->result, 'productId' => '27'));

the browser showing "Server error" 浏览器显示“服务器错误”

api user having full permission in the back end. 后端具有完全权限的api用户。 but still it is not working. 但仍然无法正常工作。 please some one help me to find the solution. 请有人帮我找到解决方案。

Your code seems a bit bloated. 您的代码似乎有点肿。 Try this: 尝试这个:

$proxy = new SoapClient('http://domain/index.php/api/v2_soap/?wsdl=1');
$sessionId = $proxy->login("username", "password");
$product = $proxy->catalogProductInfo($sessionId, '27');
print_r($product); // just to see the output

If you want to re-use the code I'd suggest the following anyway: 如果您想重新使用该代码,无论如何我建议如下:

$host = "domain.ext"; // replace with your domain name
$username = "username"; // replace with your soap user
$password = "password"; // replace with your user's password
$productId = "27";

$proxy = new SoapClient("http://".$host."/index.php/api/v2_soap/?wsdl=1");
$sessionId = $proxy->login($username, $password);
$product = $proxy->catalogProductInfo($sessionId, $productId);

print_r($product); // just to see the output

A nice hint if you want to see what other functions are available: 如果您想查看还有哪些其他功能可以使用,这是一个很好的提示:

$functions = $proxy->__getFunctions ();
var_dump($functions);

Hope it helps :) 希望能帮助到你 :)

Regards 问候

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM