如何将 XML 发送到 wsdl 端点



我希望你们都过得好。我几乎不需要 SOAP API 方面的帮助。 我想发送 XML,并且我有 WSDL 端点。有人可以帮助我,如何做到这一点?帮助将不胜感激。

首先,CURL和soapClient的好方法是什么?

这是端点http://some_ip/some_channel/services/some_service?wsdl

XML在这里:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<ban:someMthod>
<chnlNum>somenumber</chnlNum>
<chnlPasWd>some password</chnlPasWd>
<userNum>some number</userNum>
<amount>some amount</amount>
<requestDate>some date</requestDate>
<requestId>some random number</requestId>
</ban:someMethod>
</soapenv:Body>
</soapenv:Envelope>

整个请求将如下所示。

$soapurl = "http://some_ip_endpoint";
$date = date("Y-m-d h:i:sa");
$requestID = (new DateTime())->getTimestamp();

// Make your own custom request.
$xml_post_string = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<ban:someMthod>
<chnlNum>somenumber</chnlNum>
<chnlPasWd>some password</chnlPasWd>
<userNum>some number</userNum>
<amount>some amount</amount>
<requestDate>' . $date . '</requestDate>
<requestId>' . $requestID . '</requestId>
</ban:someMethod>
</soapenv:Body>
</soapenv:Envelope>';

// Don't for get to mention a proper header 
$headers = array(
"Content-Type: text/xml; charset=UTF-8",
"Pragma: no-cache",
"Content-length: " . strlen($xml_post_string),
"Connection: Keep-Alive"
);

// The actual curl request.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $soapurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP request
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

// Get a response and filter it out accordingly 
$response = curl_exec($ch);
curl_close($ch);
$xml = $response;
$xml = preg_replace("/(</?)(w+):([^>]*>)/", '$1$2$3', $xml);
$xml = simplexml_load_string($xml);
$json = json_encode($xml);

相关内容

  • 没有找到相关文章

最新更新