РЕДАКТИРОВАТЬ :
Мне нужен способ использования службы SOAP с использованием PHP.
curl -vvvv -k -s -X POST --header 'Content-type: text/xml;charset="utf-8"' --header 'SOAPAction: vend' -u 'USER':'PIN' -d "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soapenv:Header/><soapenv:Body><vend xmlns=\"http://host.vim.services.co.uk/xsd\"><sequence>6922343</sequence><origMsisdn>xxxxxxxxxxxxx </origMsisdn><destMsisdn>xxxxxxxxxxxxx</destMsisdn><amount>1000</amount><tariffTypeId>1</tariffTypeId></vend></soapenv:Body></soapenv:Envelope>" https://xxx.xxx.x.xxx:443/modlue/services/TargetOne ; echo;
Уже у меня есть этот фрагмент запроса скручивания (выше ), который дает мне успешный ответ, как показано ниже.
* Trying xxx.xxx.x.xxx...
* TCP_NODELAY set
* Connected to xxx.xxx.x.xxx (xxx.xxx.x.xxx) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
* CAfile: /etc/ssl/certs/ca-certificates.crt
CApath: /etc/ssl/certs
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* ALPN, server did not agree to a protocol
* Server certificate:
* subject: CN=*.xxx.xxxxxxe.com
* start date: Sep 10 00:00:00 2018 GMT
* expire date: Nov 28 12:00:00 2020 GMT
* issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=RapidSSL RSA CA 2018
* SSL certificate verify ok.
* Server auth using Basic with user 'username'
> POST /axis2/services/HostIFService HTTP/1.1
> Host: xxx.xxx.x.xxx
> Authorization: Basic V4mp00vKL2wb3LL6Z2hZZSIzI2RzCL2kbNPlQjExMQ==
> User-Agent: curl/7.58.0
> Accept: */*
> Content-type: text/xml;charset="utf-8"
> SOAPAction: vend
> Content-Length: 409
>
* upload completely sent off: 409 out of 409 bytes
< HTTP/1.1 200
< Content-Type: text/xml;charset=UTF-8
< Content-Length: 568
< Date: Wed, 15 Jan 2020 14:24:53 GMT
< Vary: Accept-Encoding
<
* Connection #0 to host xxx.xxx.x.xxx left intact
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><xsd:vendResponse xmlns:xsd="http://xxxxxx.xxx.xxxxx.xx.xx/xxx"><xsd:sequence>0000000001</xsd:sequence><xsd:statusId>301</xsd:statusId><xsd:txRefId>2020011515245375604706230</xsd:txRefId><xsd:origBalance>0.00</xsd:origBalance><xsd:origMsisdn>12345678910112 </xsd:origMsisdn><xsd:destMsisdn>12345678910112</xsd:destMsisdn><xsd:responseCode>0</xsd:responseCode><xsd:responseMessage>Insufficient Airtime</xsd:responseMessage></xsd:vendResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
Однако я хочу иметь возможность преобразовать запрос curl в правильный класс PHP (используя либо SoapClient, либо любую другую библиотеку), поэтому что я смогу извлечь ответ для использования в моем приложении.
ВОПРОС
Как этого добиться, используя PHP?
ЧТО Я ПОПРОБОВАЛ
Я попробовал приведенный ниже код из библиотеки Nu Soap и также пытался следовать ответу на этот вопрос , но продолжаю получать это Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from ...
. SoapClient включен на моем apache сервере.
$params = array(
"param" => "value"
);
$soap_client = new nusoap_client($wsdl_url, true);
$soap_client->setCredentials(USER_SERVICE, PASS_SERVICE, 'basic');
$soap_client->soap_defencoding = 'UTF-8'; //Fix encode erro, if you need
$soap_return = $soap_client->call("method_name", $params);
ДОПОЛНИТЕЛЬНАЯ ИНФОРМАЦИЯ
Ниже приведен пример запроса WSDL и соответствующий ответ
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://host.vim.services.co.uk/xsd">
<soapenv:Header/>
<soapenv:Body>
<xsd:vend>
<xsd:origMsisdn>2349062058470</xsd:origMsisdn>
<xsd:destMsisdn>09062058617</xsd:destMsisdn>
<xsd:amount>100</xsd:amount>
<xsd:sequence>138</xsd:sequence>
<xsd:tariffTypeId>1</xsd:tariffTypeId>
<xsd:serviceproviderId>1</xsd:serviceproviderId>
</xsd:vend>
</soapenv:Body>
</soapenv:Envelope>
NB: Запрос должен содержать поле заголовка вида Авторизация: Basi c, где учетными данными являются кодировка base64 идентификатора и пароля, соединенные двоеточием. Ниже приведены применимые свойства объекта контекста клиента.
Authorization Data : MjM0OTAwMDAwMTIzNC9oYW5kc2V0OjU1MjY=
charset : UTF-8
content-type : application/xml
SoapAction : urn:Vend
И, наконец, вот ответ на запрос
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<vendResponse>
<destBalance>998860.0</destBalance>
<destMsisdn>09062058617</destMsisdn>
<origBalance>999360.0</origBalance>
<origMsisdn>2349062058470</origMsisdn>
<responseCode>0</responseCode>
<responseMessage>Successful</responseMessage>
<sequence>139</sequence>
<statusId>0</statusId>
<txRefId>2018122611455497901000006</txRefId>
<voucherPIN>40692125281574</voucherPIN>
<voucherSerial>600000000001</voucherSerial>
</vendResponse>
</soapenv:Body>