Пример php-кода для программной проверки SOAP-соединения в Magento 2

Я попробовал приведенный ниже код, хотя я не уверен, является ли это необходимым набором сценариев, но он не работает и дает

"SOAP-ERROR: Parsing WSDL: Couldn't load from  : Start tag expected, '<' not found"
$wsdlUrl = 'http://localhost/magento20_0407/soap/default?wsdl_list=1';
$apiUser = 'testUser';
$apiKey = 'admin123';
$token = 'xioxnuuebn7tlh8ytu7781t14w7ftwmp';

$opts = array('http' => array('method' => "GET", 'header' => "Accept-language: en\r\nConnection: close\r\n"));
$context = stream_context_create($opts);
stream_context_set_option($context, "http", "protocol_version", 1.1);
fpassthru(fopen($wsdlUrl, 'r', false, $context));
$opts = array('http'=>array('header' => 'Authorization: Bearer '.$token));
$serviceArgs = array("id"=>1);

try{
$context = stream_context_create($opts);
$soapClient = new SoapClient($wsdlUrl, array('version' => SOAP_1_2, 'context' => $context));
$soapResponse = $soapClient->customerCustomerAccountServiceV1($serviceArgs);
}catch(Exception $e){
$e->getMessage();
}
var_dump($soapResponse);exit;

Может кто-нибудь поделиться кодом для создания SOAP-соединения в Magento2.x

В Magento1.x приведенный ниже код прекрасно работает для подключения SOAP

$apiUrl = 'http://localhost/magento_28_03/index.php/api/soap?wsdl';
$apiUser = 'testUser';
$apiKey = 'admin123';

ini_set("soap.wsdl_cache_enabled", "0");
try{
$client = new SoapClient($apiUrl, array('cache_wsdl' => WSDL_CACHE_NONE));
} catch (SoapFault  $e) {
echo 'Error in Soap Connection : '.$e->getMessage();
}
try {
$session = $client->login($apiUser, $apiKey);
if($session) echo 'SOAP Connection Successful.';
else echo 'SOAP Connection Failed.';

} catch (SoapFault  $e) {
echo 'Wrong Soap credentials : '.$e->getMessage();
}

Но вышесказанное не работает для Magento1.x.
Кто-нибудь может сказать, что изменения вышеуказанного кода должны нормально работать для Magent2.x?

1

Решение

Для вызова SOAP API выполните следующие действия.

test.php

require('vendor/zendframework/zend-server/src/Client.php');
require('vendor/zendframework/zend-soap/src/Client.php');
require('vendor/zendframework/zend-soap/src/Client/Common.php');$addArgs = array('num1'=>2, 'num2'=>1);// Get Request
$sumArgs = array('nums'=>array(2,1000));// Post request//$wsdlUrl = YOUR_BASE_URL."soap?wsdl&services=customerAccountManagementV1,customerCustomerRepositoryV1,alanKentCalculatorWebServiceCalculatorV1";//To declar multiple
$wsdlUrl = YOUR_BASE_URL."soap?wsdl&services=alanKentCalculatorWebServiceCalculatorV1";
try{
$opts = ['http' => ['header' => "Authorization: Bearer " . $token]];
$context = stream_context_create($opts);

$soapClient = new \Zend\Soap\Client($wsdlUrl);
$soapClient->setSoapVersion(SOAP_1_2);
$soapClient->setStreamContext($context);
}catch(Exception $e){
echo 'Error1 : '.$e->getMessage();
}

try{
$soapResponse = $soapClient->alanKentCalculatorWebServiceCalculatorV1Add($addArgs);print_r($soapResponse);
$soapResponse = $soapClient->alanKentCalculatorWebServiceCalculatorV1Sum($sumArgs);print_r($soapResponse);
}catch(Exception $e){
echo 'Error2 : '.$e->getMessage();
}

?>

Http: //YOUR_BASE_URL/test.php

2

Другие решения

"SOAP-ERROR: Parsing WSDL: Couldn't load from  : Start tag expected, '<' not found"

Сообщает вам все, что вам нужно знать, URL, который вы пытаетесь загрузить, не является надлежащим WSDL.

Каково содержание: HTTP: // локальный / magento20_0407 / мыло / по умолчанию wsdl_list = 1

0

По вопросам рекламы [email protected]