如何在 magento2 中使用 3rd Party wsdl
How to consume 3rd Party wsdl in magento2
我需要从第三方获取客户信息 http://91.209.142.215:2803/SXYMAGENTO/?wsdl。我可以使用 SOAPUI 连接它并获得所需的响应,但我无法通过 Magento2 连接它。到目前为止我试过了
$requestData = [
'pageSize' => 1,
'pageNumber' => 1
];
$webservice_url = 'http://xx.xxx.xxx.xx:xxxx/MAGENTO/?wsdl';
$token = 'm31oix12hh6dfthmfmgk7j5k5dpg8mel';
$opts = array(
'http'=>array(
'header' => 'Authorization: Bearer '.$token)
);
$context = stream_context_create($opts);
$soapClient = new \SoapClient($webservice_url, ['version' => SOAP_1_2, 'context' => $context]);
$collection = $soapClient->RetrieveCollection($requestData);
print_r($collection);
die();
但这会输出产品数据(可能这是默认设置),而不是客户数据。谁能给我指出正确的方向?
最后,我想出了这个问题并发布了答案,这样它可以帮助任何渴望解决方案或与最后期限作斗争的人。
扩展 SoapClient,您可以更改操作、请求和位置
namespace Namespace\SoapModule\Api;
class CustomSoap extends \SoapClient
{
public function __doRequest($request, $location, $action, $version, $one_way = 0)
{
$action = 'Your/Action/Obtainedfrom/SOAPAction';
$this->__last_request = $request; //Optional. You should do this if you dont want to get confused when print $request somewhere else in the module
return parent::__doRequest($request, $location, $action, $version, $one_way);
}
}
在需要的地方构造一个以上class的对象
public function getCustomersDetails($page_size, $page_number)
{
$requestData = [
'pageSize' => $page_size,
'pageNumber' => $page_number
];</p>
<pre><code> $data = $this->client->__soapCall('RetrieveCollection', [$requestData]);
return $this->client->__getLastResponse();
}
public function statementBalance()
{
$responsexml = $this->getCustomersDetails(1, 1);
$xml = preg_replace("/(<\/?)(\w+):([^>]*>)/", "", $responsexml);
@$xml = simplexml_load_string($xml);
$json = json_encode($xml);
$responseArray = json_decode($json, true);
echo '<pre>';
print_r($responseArray);
}
编码愉快!
我需要从第三方获取客户信息 http://91.209.142.215:2803/SXYMAGENTO/?wsdl。我可以使用 SOAPUI 连接它并获得所需的响应,但我无法通过 Magento2 连接它。到目前为止我试过了
$requestData = [
'pageSize' => 1,
'pageNumber' => 1
];
$webservice_url = 'http://xx.xxx.xxx.xx:xxxx/MAGENTO/?wsdl';
$token = 'm31oix12hh6dfthmfmgk7j5k5dpg8mel';
$opts = array(
'http'=>array(
'header' => 'Authorization: Bearer '.$token)
);
$context = stream_context_create($opts);
$soapClient = new \SoapClient($webservice_url, ['version' => SOAP_1_2, 'context' => $context]);
$collection = $soapClient->RetrieveCollection($requestData);
print_r($collection);
die();
但这会输出产品数据(可能这是默认设置),而不是客户数据。谁能给我指出正确的方向?
最后,我想出了这个问题并发布了答案,这样它可以帮助任何渴望解决方案或与最后期限作斗争的人。
扩展 SoapClient,您可以更改操作、请求和位置
namespace Namespace\SoapModule\Api; class CustomSoap extends \SoapClient { public function __doRequest($request, $location, $action, $version, $one_way = 0) { $action = 'Your/Action/Obtainedfrom/SOAPAction'; $this->__last_request = $request; //Optional. You should do this if you dont want to get confused when print $request somewhere else in the module return parent::__doRequest($request, $location, $action, $version, $one_way); } }
在需要的地方构造一个以上class的对象
public function getCustomersDetails($page_size, $page_number) { $requestData = [ 'pageSize' => $page_size, 'pageNumber' => $page_number ];</p> <pre><code> $data = $this->client->__soapCall('RetrieveCollection', [$requestData]); return $this->client->__getLastResponse();
}
public function statementBalance() { $responsexml = $this->getCustomersDetails(1, 1); $xml = preg_replace("/(<\/?)(\w+):([^>]*>)/", "", $responsexml); @$xml = simplexml_load_string($xml); $json = json_encode($xml); $responseArray = json_decode($json, true); echo '<pre>'; print_r($responseArray); }
编码愉快!