我在WS-I兼容模式下使用Magento v2 Web服务
当试图列出产品时,我得到例外
SOAP-ERROR: Encoding: object has no 'sessionId' property
我的代码列在下面
$proxy = new SoapClient('http://127.0.0.1/Magento1620/index.PHP/api/v2_soap?wsdl',array('trace' => 1,'connection_timeout' => 120)); $sessionId = $proxy->login(array( 'username' => "zzc000",'apiKey' => "zzc000" )); $filters = array( 'sku' => array('like'=>'zol%') ); $products = $proxy->catalogProductList($sessionId,$filters);
请帮忙,谢谢
解决方法
在WS-I模式下,使用API有一些细微差别.
> $proxy-> login()的结果是一个对象.您需要提取sessionId.
>调用$proxy-> catalogProductList()时,需要在关联数组中提供参数(就像使用$proxy-> login()一样).
请试试这个:
<?PHP try { error_reporting(E_ALL | E_STRICT); ini_set('display_errors',1); $proxy = new SoapClient('http://127.0.0.1/Magento1620/index.PHP/api/v2_soap?wsdl','connection_timeout' => 120)); $session = $proxy->login(array( 'username' => "zzc000",'apiKey' => "zzc000" )); $sessionId = $session->result; $filters = array( 'sku' => array('like'=>'zol%') ); $products = $proxy->catalogProductList(array("sessionId" => $sessionId,"filters" => $filters)); echo '<h1>Result</h1>'; echo '<pre>'; var_dump($products); echo '</pre>'; } catch (Exception $e) { echo '<h1>Error</h1>'; echo '<p>' . $e->getMessage() . '</p>'; }