PHP SOAP请求:无效的架构

时间:2015-03-17 11:32:44

标签: php xml soap

我试图将一些数据发送到Royal Mail API,但我收到一条消息:E0004架构验证失败。按照我用来创建请求的代码:

$api_password = "xxxx";
$api_username = "xxx@xxx.comAPI";
$api_application_id = "xxxxxx";
$api_service_type = "D";
$api_service_code = "SD1";
$api_service_format = "";
$api_certificate_passphrase = "xxxxx";
$api_service_enhancements = "";

$data = new ArrayObject();
$data->order_tracking_id = "";
$data->shipping_name = "Felipe";
$data->shipping_company = "splash";
$data->shipping_address1 = "23, St johns road"; 
$data->shipping_address2 = "";
$data->shipping_town = "london";
$data->shipping_postcode = "NW11 0PE";
$data->order_tracking_boxes = "0";
$data->order_tracking_weight = "1500";

                    $time = gmdate('Y-m-d\TH:i:s');
                    $created = gmdate('Y-m-d\TH:i:s\Z');
                    $nonce = mt_rand();
                    $nonce_date_pwd = xyz . xyz . pack("H**", sha1($api_password));
             $passwordDigest = base64_encode(pack('ZH**',sha1($nonce_date_pwd)));
             $ENCODEDNONCE = base64_encode($nonce);

                    $soapclient_options = array();
                    $soapclient_options['cache_wsdl'] = 'WSDL_CACHE_NONE';
                    $soapclient_options['local_cert'] = "certificate.pem";
                    $soapclient_options['passphrase'] = $api_certificate_passphrase;
                    $soapclient_options['trace'] = true;
                    $soapclient_options['ssl_method'] = 'SOAP_SSL_METHOD_SSLv3';
                    $soapclient_options['location'] = 'https://api.royalmail.com/shipping/onboarding';
                    $soapclient_options['soap_version'] = 'SOAP_1_1';

                    //'soap_version' => SOAP_1_2,

                    //launch soap client
                    $client = new SoapClient("SAPI/ShippingAPI_V2_0_8.wsdl", $soapclient_options);
                    $client->__setLocation($soapclient_options['location']);

                  //  print_r($client);

        //headers needed for royal mail
$HeaderObjectXML  = '<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
                      xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
           <wsse:UsernameToken wsu:Id="UsernameToken-xxxxxx">
              <wsse:Username>'.$api_username.'</wsse:Username>
              <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">'.$passwordDigest.'</wsse:Password>
              <wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">'.$ENCODEDNONCE.'</wsse:Nonce>
              <wsu:Created>'.$created.'</wsu:Created>
           </wsse:UsernameToken>
       </wsse:Security>';

        //push the header into soap
$HeaderObject = new SoapVar( $HeaderObjectXML, XSD_ANYXML );

        //push soap header
$header = new SoapHeader( 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd', 'Security', $HeaderObject );
$client->__setSoapHeaders($header);

        //build the request
$request = array(
    'integrationHeader' => array(
        'dateTime' => $time,
        'version' => '2.0',
        'identification' => array(
            'applicationId' => $api_application_id,
            'transactionId' => $data->order_tracking_id
        )
    ),
    'requestedShipment' => array(
                                'shipmentType' => array('code' => 'Delivery'),
                                'serviceOccurence' => '1',
                                'serviceType' => array('code' => $api_service_type),
                                'serviceOffering' => array('serviceOfferingCode' => array('code' => $api_service_code)),
                                'serviceFormat' => array('serviceFormatCode' => array('code' => $api_service_format)),
                                'shippingDate' => date('Y-m-d'),
                                'recipientContact' => array('name' => $data->shipping_name, 'complementaryName' => $data->shipping_company),
                                'recipientAddress' => array('addressLine1' => $data->shipping_address1,  'addressLine2' => $data->shipping_address2, 'postTown' => $data->shipping_town, 'postcode' => $data->shipping_postcode),
                                'items' => array('item' => array(                                                                                                                                                            'numberOfItems' => $data->order_tracking_boxes,                                                                                                                                                            'weight' => array( 'unitOfMeasure' => array('unitOfMeasureCode' => array('code' => 'g')),                                                                                                                                                                                                                                                'value' => ($data->order_tracking_weight) //weight of each individual item
                                                                                                                                                                                                                                )
                                                                                                                                                        )
                                                                                )
    )
);


        $body = new SoapVar( $request, SOAP_ENC_OBJECT );

        //if any enhancements, add it into the array
        if($api_service_enhancements != "") {
                    $request['requestedShipment']['serviceEnhancements'] = array('enhancementType' => array('serviceEnhancementCode' => array('code' => $api_service_enhancements)));
        }

        try {
                    $response = $client->__soapCall( 'createShipment', array($request), array('soapaction' => 'https://api.royalmail.com/shipping/onboarding') );
                    print_r($response);

        }           catch (Exception $e) {

                    //catch the error message and echo the last request for debug
                    //print_r($e);
                    echo $e->getMessage();
                    echo "REQUEST:\n" . htmlentities($client->__getLastRequest()) . "\n";
                   // die;
        }

按照代码创建的请求进行操作:

    <?xml version="1.0" encoding="UTF-8"?>
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.royalmailgroup.com/integration/core/V1" xmlns:ns2="http://www.royalmailgroup.com/api/ship/V2" xmlns:ns3="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
    <SOAP-ENV:Header>
        <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
                   <wsse:UsernameToken wsu:Id="UsernameToken-xxxxxx">
                      <wsse:Username>xxx@xxxxx</wsse:Username>
                      <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">ztyoDZ0RtlCehYvlhEYYCOCXt0CY=</wsse:Password>
                      <wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">MjA5MzA5jNjU1MQ==</wsse:Nonce>
                      <wsu:Created>2015-03-17T10:56:02Z</wsu:Created>
                   </wsse:UsernameToken>
        </wsse:Security>
    </SOAP-ENV:Header>

    <SOAP-ENV:Body>
       <ns2:createShipmentRequest>
       <ns2:integrationHeader><ns1:dateTime>2015-03-17T10:56:02</ns1:dateTime><ns1:version>2.0</ns1:version><ns1:identification><ns1:applicationId>xxxxx</ns1:applicationId><ns1:transactionId>730222611</ns1:transactionId></ns1:identification></ns2:integrationHeader>

       <ns2:requestedShipment>
       <ns2:shipmentType><code>Delivery</code></ns2:shipmentType>
       <ns2:serviceType><code>D</code></ns2:serviceType>
       <ns2:serviceOffering><serviceOfferingCode><code>SD1</code></serviceOfferingCode></ns2:serviceOffering>
       <ns2:serviceFormat><serviceFormatCode><code></code></serviceFormatCode></ns2:serviceFormat>
       <ns2:shippingDate>2015-03-17</ns2:shippingDate>
       <ns2:recipientContact>
            <ns2:name>Felipe</ns2:name>
            <ns2:complementaryName>splash</ns2:complementaryName>
        </ns2:recipientContact>
        <ns2:recipientAddress>
            <addressLine1>27, St johns road</addressLine1>
            <addressLine2></addressLine2>
            <postTown>london</postTown>
            <postcode>NW11 0PE</postcode>
       </ns2:recipientAddress>
       <ns2:items>
          <ns2:item>
            <ns2:numberOfItems>0</ns2:numberOfItems>
            <ns2:weight><unitOfMeasure><unitOfMeasureCode><code>g</code></unitOfMeasureCode></unitOfMeasure><value>1500</value></ns2:weight>
          </ns2:item>
       </ns2:items>
        </ns2:requestedShipment></ns2:createShipmentRequest></SOAP-ENV:Body></SOAP-ENV:Envelope>

按照示例请求:

                   <?xml version="1.0" encoding="UTF-8"?>
           <soapenv:Envelope xmlns:oas="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://www.royalmailgroup.com/integration/core/V1" xmlns:v2="http://www.royalmailgroup.com/api/ship/V2">
              <soapenv:Header><wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><wsse:UsernameToken wsu:Id="UsernameToken-xxxxxxxxxxxxxx"><wsse:Username>xxxx@xxx.comAPI</wsse:Username><wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">gShxrkDCihB04r5iG+xA+p7aqMU=</wsse:Password><wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">Kxv2sk4hXnvAHLbOVIsuvw==</wsse:Nonce><wsu:Created>2015-03-09T08:01:28.132Z</wsu:Created></wsse:UsernameToken></wsse:Security>

              </soapenv:Header>
              <soapenv:Body>
                 <v2:createShipmentRequest>
                    <v2:integrationHeader>
                       <v1:dateTime>2015-03-08T08:52:03</v1:dateTime>
                       <v1:version>2</v1:version>
                       <v1:identification>
                          <v1:applicationId>xxxxxxxxx</v1:applicationId>
                          <v1:transactionId>730222611</v1:transactionId>
                       </v1:identification>
                    </v2:integrationHeader>
                    <v2:requestedShipment>
                       <v2:shipmentType>
                          <code>Delivery</code>
                       </v2:shipmentType>
                       <v2:serviceOccurrence>1</v2:serviceOccurrence>
                       <v2:serviceType>
                          <code>D</code>
                       </v2:serviceType>
                       <v2:serviceOffering>
                          <serviceOfferingCode>
                             <code>SD1</code>
                          </serviceOfferingCode>
                       </v2:serviceOffering>
                       <v2:serviceFormat>
                          <serviceFormatCode/>
                       </v2:serviceFormat>
                       <v2:signature>1</v2:signature>
                       <v2:shippingDate>2015-02-09</v2:shippingDate>
                       <v2:recipientContact>
                          <v2:name>Mr Tom Smith</v2:name>
                          <v2:complementaryName>Department 98</v2:complementaryName>
                          <v2:telephoneNumber>
                             <countryCode>0044</countryCode>
                             <telephoneNumber>07801123456</telephoneNumber>
                          </v2:telephoneNumber>
                          <v2:electronicAddress>
                             <electronicAddress>tom.smith@royalmail.com</electronicAddress>
                          </v2:electronicAddress>
                       </v2:recipientContact>
                       <v2:recipientAddress>
                          <addressLine1>3 Vantage Walk</addressLine1>
                          <postTown>Hastings</postTown>
                          <postcode>TN38 0YP</postcode>
                          <country>
                             <countryCode>
                                <code>GB</code>
                             </countryCode>
                          </country>
                       </v2:recipientAddress>
                       <v2:items>
                          <v2:item>
                             <v2:numberOfItems>1</v2:numberOfItems>
                             <v2:weight>
                                <unitOfMeasure>
                                   <unitOfMeasureCode>
                                      <code>g</code>
                                   </unitOfMeasureCode>
                                </unitOfMeasure>
                                <value>100</value>
                             </v2:weight>
                          </v2:item>
                       </v2:items>
                       <v2:customerReference>CustSuppRef1</v2:customerReference>
                       <v2:senderReference>SenderReference1</v2:senderReference>
                    </v2:requestedShipment>
                 </v2:createShipmentRequest>
              </soapenv:Body>
           </soapenv:Envelope>

我真的坚持下去,我尝试的任何工作都没有。我觉得这件事真的很小,我找不到。 任何帮助都会很棒。 感谢

0 个答案:

没有答案