英语不是我的母语所以请耐心等待。
我需要一个特定的信封来使用WebService,因为服务器管理员是非合作人员。现在我有点困惑,因为我不知道从哪里开始。
我需要报告一些信件和账单的状态,能够使用PHP制作一个脚本,在MySQL数据库中搜索报告trought webService的信息。
管理员而不是通过" wsdl"向我发送IP地址。制作PHP Soap Client的配置,发送一个示例文本文件(xml类型)来制作信封。使用SoapUI能够得到一个答案(一个错误的答案,但仍然是一个答案),但我试图做一个自动报告(使用Cron),但我不知道如何从一个信封XML使SoapClient报告。
示例信封如下:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.esb.comfenalcovalle.com.co/">
<soapenv:Header/>
<soapenv:Body>
<ws:requestMessageOut>
<ws:header>
<ws:invokerDateTime>2017-05-05</ws:invokerDateTime>
<ws:moduleId>ACTUALIZA_CORRESPONDENCIA</ws:moduleId>
<ws:systemId></ws:systemId>
<ws:messageId>ACTUALIZA_CORRESPONDENCIA|123456789</ws:messageId>
<ws:logginData>
<ws:sourceSystemId></ws:sourceSystemId>
<ws:destinationSystemId></ws:destinationSystemId>
</ws:logginData>
<ws:destination>
<ws:namespace>http://co/com/comfenalcovalle/esb/ws/BPSirapActualizaCorrespondencia</ws:namespace>
<ws:name>BPSirapActualizaCorrespondencia</ws:name>
<ws:operation>execute</ws:operation>
</ws:destination>
<ws:securityCredential>
<ws:userName></ws:userName>
<ws:userToken></ws:userToken>
</ws:securityCredential>
<ws:classification>
<!--Zero or more repetitions:-->
<ws:classification></ws:classification>
</ws:classification>
</ws:header>
<ws:body>
<ws:request>
<BPSirapActualizaCorrespondenciaProcessRequest>
<pividdocu>1075000000010907</pividdocu>
<pinidesdo>25</pinidesdo>
<pinidmoed></pinidmoed>
<pivdireccion>CR 34-10 229</pivdireccion>
<pivcodigoLeyMuni>76001</pivcodigoLeyMuni>
<pivcodigoLeyDpto>76</pivcodigoLeyDpto>
<pivnumeroGuia>574127725</pivnumeroGuia>
<pivnumeroRemision>0102205-12</p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W7Jos/EICXsrVNu+Ca92BpKYAB+wy0apXcKwkh+VkGm7jsbUVP5tlDUUtJXj7wTE16HZJ1GlQ/Ysa824ttmzMx41qAXrdJTlGiYZEiKeu0asRruD9n7HTZDIlaebMFYWUm+7YXEyQOPJxjRG1ZHkYnnairKJB3YxmL8LN5xhSW3Dk6cMcGOV9RkA6lYpkA2LJFJZEya3rhMZTmmWCmxTy8t5p2yLBMLoIgMwBr/hayI7kYSz5Mruam6dusuUYZMtu0cy3nZ6XyQOq4lWw07/HKtJMYr0aNNZMv9724q+WVuvKn3/pymmdzhqYlw5CAkmwjVSXwM0nmLomyB+c2NvqnLnRzmFg1jbvKkJoU/x6Z3r4fCzdf/H3o6Invf0WAxjgkMf7S8Nlfy8bhYJ5FH1VB2SpFPFe5Ga8+X9mymiBXs3DTrop8jagQ3jz5Qxd8tO2eRf8KlmeOhWijhXBlSoWAuq2FLMBJuvHpRl9azQO2maNft11Fv22SoGJQSHJjw0sX4oEe0iegoaYI9dssLACroudBXr8vs9dv18DYjo6+EUw73ZwseflEO2zky2jja8vMtJhxx9jLDohu5caDRGUPaSNpLmlClAhIGWFdID3FBuyf/pH410TE/yB/CzAAZIXaj6vGZXwAAAAASUVORK5CYII=</pivguiaDigitalizada>
</BPSirapActualizaCorrespondenciaProcessRequest>
</ws:request>
</ws:body>
</ws:requestMessageOut>
</soapenv:Body>
</soapenv:Envelope>
如果您将此代码复制/粘贴到SoapUI并设置&#34;端点&#34; to:https://virtual.comfenalcovalle.com.co/esbtest/WSChannelAdapter ...你会得到我正在谈论的错误答案。
我正在寻找一些链接,寻找答案:
how to generate a soap request in php from this xml?
https://www.wackylabs.net/2004/07/creating-a-web-service-and-wsdl-using-nusoap/
how to create soap xml request in php
PHP SoapClient: multiple complex types are overwritten in soapcall
how to generate XML with soap envelope and body tag using php
------------------&GT; 5月18日更新
感谢Alex Blex的回答,使用他的观点将XML作为&#34; String&#34;可以使用变通方法来使用WebService,而不是配置客户端只需使用&#34; null&#34;。
$location_URL = 'https://virtual.comfenalcovalle.com.co/esbtest/WSChannelAdapter';
$action_URL = "https://virtual.comfenalcovalle.com.co/esbtest/WSChannelAdapter";
$client = new SoapClient(null, array(
'location' => $location_URL,
'uri' => "https://virtual.comfenalcovalle.com.co/esbtest/WSChannelAdapter",
'trace' => 1,
));
$return = $client->__doRequest($xmlString,$location_URL,$action_URL,1);
遗憾的是,$ return也是一个String,而不是一个对象或XML,因此获取报告并存储在数据库中非常困难。
当我使用Alex Blex提出的方法时,没有收到任何内容,这是对他的代码的一个小修改:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://virtual.comfenalcovalle.com.co/esbtest/WSChannelAdapter');
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $xmlstring );
$result = curl_exec($ch);
$info = curl_getinfo($ch);
$errors = curl_error($ch);
$resArr = array();
$resArr = json_decode($result);
$xml = simplexml_load_string($result);
echo "<pre>"; print_r($result); echo "</pre>";
echo "<pre>"; print_r($info); echo "</pre>";
echo "<pre>"; print_r($resArr); echo "</pre>";
echo "<pre>"; print_r($errors); echo "</pre>";
curl_close($ch);
我已经在为客户工作,但任何更正或新方法都可以尽快实施。
答案 0 :(得分:1)
你可以用cURL做低级别。
如果您将xml发布到API,如
curl --request POST \
--url https://virtual.comfenalcovalle.com.co/esbtest/WSChannelAdapter \
--data '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.esb.comfenalcovalle.com.co/"> .... </soapenv:Envelope>'
您实际上获得了成功的回复
....
<NS1:responseMessageOut xmlns:NS1="http://ws.esb.comfenalcovalle.com.co/">
<NS1:header>
<NS1:invokerDateTime>2017-05-05</NS1:invokerDateTime>
<NS1:moduleId>ACTUALIZA_CORRESPONDENCIA</NS1:moduleId>
<NS1:systemId></NS1:systemId>
<NS1:messageId>ACTUALIZA_CORRESPONDENCIA|123456789</NS1:messageId>
<NS1:logginData>
<NS1:sourceSystemId></NS1:sourceSystemId>
<NS1:destinationSystemId></NS1:destinationSystemId>
</NS1:logginData>
<NS1:destination>
<NS1:namespace>http://co/com/comfenalcovalle/esb/ws/BPSirapActualizaCorrespondencia</NS1:namespace>
<NS1:name>BPSirapActualizaCorrespondencia</NS1:name>
<NS1:operation>execute</NS1:operation>
</NS1:destination>
<NS1:responseStatus>
<NS1:statusCode>SUCESS</NS1:statusCode>
</NS1:responseStatus>
</NS1:header>
<NS1:body>
<NS1:response>
<BPSirapActualizaCorres
....
在php中它应该像
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://virtual.comfenalcovalle.com.co/esbtest/WSChannelAdapter');
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $theXML );
$result = curl_exec($ch);
curl_close($ch);
$result
中的响应可以使用DOMXml或SimpleXML进行解析。