使用SOAP发送XML - PHP

时间:2017-09-11 14:43:30

标签: php xml soap wsdl

我需要您的帮助,根据我的提供商的说明通过SOAP发送XML。

问题:

  1. 它不会生成完整的命名空间(Top xmlns:xsi和xmlns:xsd)
  2. 它不会为数组字段生成变量类型(ns1:值xsi:type =“xsd:string”)
  3. 这是我的代码和生成我的XML

    $WebService = new SoapClient('https:url.asmx?wsdl', array( 'trace' => 1 ) );
    
    $dateClient["PSEHostingField"][0] = array("Name"=>"id_client","Value"=>"123456789");
    $dateClient["PSEHostingField"][1] = array("Name"=>"name_client","Value"=>"Daniel");
    $dateClient["PSEHostingField"][2] = array("Name"=>"tel_client","Value"=>"123456");
    
    $params = array(
        "ticketOfficeID" => 2259, 
        "amount" => 291944,
        "vatAmount" => 5444,
        "paymentID" => 9561,
        "paymentDescription" => PAGOS PSE,
        "referenceNumber1" => 10.10.10.244,
        "referenceNumber2" => NIT,
        "referenceNumber3" => 900000000,
        "serviceCode" => 5001,
        "email" => correocliente@gmail.com,
        "fields" => $dateClient,
        "entity_url" => "http:urlRespoce.php",
    );
    
    $Responce = $WebService->createTransactionPaymentHosting( $params );
    

    这是抛出我的XML

    <?xml version="1.0" encoding="UTF-8"?>
    <SOAP-ENV:Envelope
        xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
        xmlns:ns1="http://www.achcolombia.com.co/PSEHostingWS">
        <SOAP-ENV:Body>
            <ns1:createTransactionPaymentHosting>
                <ns1:ticketOfficeID>2259</ns1:ticketOfficeID>
                <ns1:amount>291944</ns1:amount>
                <ns1:vatAmount>5444</ns1:vatAmount>
                <ns1:paymentID>9561</ns1:paymentID>
                <ns1:paymentDescription>PAGOS PSE</ns1:paymentDescription>
                <ns1:referenceNumber1>10.10.10.244</ns1:referenceNumber1>
                <ns1:referenceNumber2>NIT</ns1:referenceNumber2>
                <ns1:referenceNumber3>900000000</ns1:referenceNumber3>
                <ns1:serviceCode>5001</ns1:serviceCode>
                <ns1:email>correocliente@gmail.com</ns1:email>
                <ns1:fields>
                    <ns1:PSEHostingField>
                        <ns1:Name>id_client</ns1:Name>
                        <ns1:Value>123456789</ns1:Value>
                    </ns1:PSEHostingField>
                    <ns1:PSEHostingField>
                        <ns1:Name>name_client</ns1:Name>
                        <ns1:Value>Daniel</ns1:Value>
                    </ns1:PSEHostingField>
                    <ns1:PSEHostingField>
                        <ns1:Name>tel_client</ns1:Name>
                        <ns1:Value>123456</ns1:Value>
                    </ns1:PSEHostingField>
                </ns1:fields>
                <ns1:entity_url>http:urlResponce.php</ns1:entity_url>
            </ns1:createTransactionPaymentHosting>
        </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
    

    这是我应该发送的XML

    <?xml version="1.0" encoding="UTF-8"?>
    <SOAP-ENV:Envelope
        xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
        xmlns:ns1="http://www.achcolombia.com.co/PSEHostingWS">
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <SOAP-ENV:Body>
            <ns1:createTransactionPaymentHosting>
                <ns1:ticketOfficeID>2259</ns1:ticketOfficeID>
                <ns1:amount>291944</ns1:amount>
                <ns1:vatAmount>5444</ns1:vatAmount>
                <ns1:paymentID>9561</ns1:paymentID>
                <ns1:paymentDescription>PAGOS PSE</ns1:paymentDescription>
                <ns1:referenceNumber1>10.10.10.244</ns1:referenceNumber1>
                <ns1:referenceNumber2>NIT</ns1:referenceNumber2>
                <ns1:referenceNumber3>900000000</ns1:referenceNumber3>
                <ns1:serviceCode>5001</ns1:serviceCode>
                <ns1:email>correocliente@gmail.com</ns1:email>
                <ns1:fields>
                    <ns1:PSEHostingField>
                        <ns1:Name>id_client</ns1:Name>
                        <ns1:Value xsi:type="xsd:string">123456789</ns1:Value>
                    </ns1:PSEHostingField>
                    <ns1:PSEHostingField>
                        <ns1:Name>name_client</ns1:Name>
                        <ns1:Value xsi:type="xsd:string">Daniel</ns1:Value>
                    </ns1:PSEHostingField>
                    <ns1:PSEHostingField>
                        <ns1:Name>tel_client</ns1:Name>
                        <ns1:Value xsi:type="xsd:string">123456</ns1:Value>
                    </ns1:PSEHostingField>
                </ns1:fields>
                <ns1:entity_url>http:urlResponce.php</ns1:entity_url>
            </ns1:createTransactionPaymentHosting>
        </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
    

    我已经尝试了一些像SOAPUI和NUSOAP库这样的工具,我得到了相同的结果,我收到以下错误:

      

    在Assembly'System.Xml,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'中键入'System.Xml.XmlNode'未标记为可序列化。'

    提供者告诉我,这是因为我上面提到的两个问题。

1 个答案:

答案 0 :(得分:0)

在另一个来源中找到解决方案,如果它为某人提供了该出版物

添加SoapVar对象

$datosCliente["PSEHostingField"][0] = array("Name"=>"id_client","Value"=>new SoapVar("123456789", XSD_STRING, "string", "http://www.w3.org/2001/XMLSchema"));
$datosCliente["PSEHostingField"][1] = array("Name"=>"name_client","Value"=>new SoapVar("Daniel", XSD_STRING, "string", "http://www.w3.org/2001/XMLSchema"));
$datosCliente["PSEHostingField"][2] = array("Name"=>"tel_client","Value"=>new SoapVar("123456", XSD_STRING, "string", "http://www.w3.org/2001/XMLSchema"));