codeigniter 如何将XML发送到wsdl端点

3b6akqbq  于 2022-12-16  发布在  其他
关注(0)|答案(1)|浏览(147)

我希望大家都做得很好。我需要一点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>
jv4diomz

jv4diomz1#

整个请求将如下所示。

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

相关问题