Soap 如何在magento2中使用第三方wsdl

Soap 如何在magento2中使用第三方wsdl,soap,soapui,magento2,Soap,Soapui,Magento2,我需要从第三方获取客户信息。我可以使用SOAPUI连接它并获得所需的响应,但我无法通过Magento2连接它。到目前为止我试过了 $requestData = [ 'pageSize' => 1, 'pageNumber' => 1 ]; $webservice_url = 'http://xx.xxx.xxx.xx:xxxx/MAGENTO/?wsdl'; $token =

我需要从第三方获取客户信息。我可以使用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,您可以更改操作、请求和位置

  • 在需要的地方构造一个以上类别的对象

    }

    公共功能语句balance() { $responsexml=$this->getCustomersDetails(1,1); $xml=preg_replace(“/(]*>)/”、“$1$2$3”、$responsexml); @$xml=simplexml\u load\u字符串($xml); $json=json_encode($xml); $responseArray=json_decode($json,true); 回声'; 打印费用($responseArray); }
  • 快乐编码

    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();