我需要从第三方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();
但是这会输出产品数据(可能是默认设置),而不是客户数据。有谁能指出我正确的方向?
答案 0 :(得分:0)
最后,我想出了这个并发布答案,以便它可以帮助任何人渴望解决方案或在截止日期前战斗。
扩展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);
}
}
在需要的地方构建上述类的对象
public function getCustomersDetails($page_size, $page_number)
{
$requestData = [
'pageSize' => $page_size,
'pageNumber' => $page_number
];
$data = $this->client->__soapCall('RetrieveCollection', [$requestData]);
return $this->client->__getLastResponse();
}
public function statementBalance()
{
$responsexml = $this->getCustomersDetails(1, 1);
$xml = preg_replace("/(<\/?)(\w+):([^>]*>)/", "$1$2$3", $responsexml);
@$xml = simplexml_load_string($xml);
$json = json_encode($xml);
$responseArray = json_decode($json, true);
echo '<pre>';
print_r($responseArray);
}
快乐的编码!