开发者

How to authenticate with Pear SOAP_Client

开发者 https://www.devze.com 2023-03-14 22:29 出处:网络
I am trying to login to my magento\'s web services from a server that does not have SoapClient enabled.So I figured I would install and use Pear\'s SOAP_Clientbut I can\'t figure out 开发者_运维百科ho

I am trying to login to my magento's web services from a server that does not have SoapClient enabled. So I figured I would install and use Pear's SOAP_Client but I can't figure out 开发者_运维百科how to login.

With SoapClient I use:

$client = new SoapClient($WSDL);
$session = $client->login($user, $api_key);
$response = $client->call($session, $method, $arguments);

But I can't find an analog to the login method for SOAP_Client

I gather that I should be setting something in the $proxy_params of the constructor, but I can't find what the indexes should be.

$proxy_params = array();
$client = new SOAP_Client($wsdl, true, false, $proxy_params);
$client->call($method, $arguments)


So I figured this out, and there are a couple of factors here.

  1. There isn't a login function for SoapClient, the login I was calling is a call as defined in the WSDL

  2. The various magento API methods are not defined in the WSDL, you provide an argument resource method to method defined as call by the WSDL. This created a bit of confusion because using $client->call() seems to invoke call as defined by the SOAP_Client class, so I need to use $client->call('call') to invoke the SOAP method call

The final code ended up being:

$method = 'catalog_product.info';
$args = array($product_id);

$client = new SOAP_Client($wsdl, true);
$session_id = $client->call(
    'login',
    array(
        'username'=>$username,
        'apiKey'=> $pasword
    )
);
$ret = $client->call(
    'call',
    array(
        'sessionId'=>$session_id,
        'resourcePath'=>$method,
        'args'=>$args
    )
);
0

精彩评论

暂无评论...
验证码 换一张
取 消