php SOAP请求生成体始终为空

时间:2018-01-02 13:52:04

标签: php soap

我试图在我们的应用程序中使用Soap API, 但是我尝试了很多东西,身体要求总是空的。

这是我的实际代码。

$api_params = new stdClass();
  $api_params->contractNumber = "965916";
  $api_params->password = "fYmp120";
  $output_format = new stdClass();
  $output_format->x = 0;
  $output_format->y = 0;
  $output_format->outputPrintingType = "PDF_10x15_300dpi";
  $api_params->outputFormat = new stdClass();
  $api_params->outputFormat = $output_format;
  $api_params->letter = new stdClass();
  $service = new stdClass();
  $service->productCode = "DOM";
  $service->orderNumber = $order_id;
  $service->commercialName = TEXT_SENDER_NAME;
  $api_params->letter->service = new stdClass();
  $api_params->letter->service = $service;
  $parcel = new stdClass();
  $parcel->weight = $weight;
  $api_params->letter->parcel = new stdClass();
  $api_params->letter->parcel = $parcel;
  $sender = new stdClass();
  $sender = $this->get_sender();
  $api_params->letter->sender = new stdClass();
  $api_params->letter->sender->senderParcelRef = randomise_order_num($order_id);
  $api_params->letter->sender->address = new stdClass();
  $api_params->letter->sender->address = $sender;
  $addressee = new stdClass();
  $addressee = $this->get_addressee($order_id);
  $api_params->letter->addressee = new stdClass();
  $api_params->letter->addressee = $addressee;
  $api_struct = new soapVar($api_params, SOAP_ENC_OBJECT);
  $wsdl = "https://ws.colissimo.fr/sls-ws/SlsServiceWS?wsdl";
    $soap_client = new SoapClient($wsdl, array('trace' => true, 'exception' => false));

  try {
    $api_result = $soap_client->generateLabel(array($api_struct));
  } catch(Exception $e) {
    echo "====== REQUEST HEADERS =====" . PHP_EOL;
    var_dump($soap_client->__getLastRequestHeaders());
    echo "========= REQUEST ==========" . PHP_EOL;
    var_dump(htmlentities($soap_client->__getLastRequest()));
    echo "========= RESPONSE =========" . PHP_EOL;
  }
echo '<pre style="background:black; color:white; font-size:16px; font-      weight:bold; direction:ltr!important; text-align:left;">';
print_r($api_struct);
echo '</pre>';

以下是请求的内容:

"<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://sls.ws.coliposte.fr"><SOAP-ENV:Body><ns1:generateLabel/></SOAP-ENV:Body></SOAP-ENV:Envelope> 

$array_struct var dump:

SoapVar Object
(
    [enc_type] => 301
    [enc_value] => stdClass Object
    (
        [contractNumber] => XXXXXXX
        [password] => XXXXXXX
        [outputFormat] => stdClass Object
            (
                [x] => 0
                [y] => 0
                [outputPrintingType] => PDF_10x15_300dpi
            )

        [letter] => stdClass Object
            (
                [service] => stdClass Object
                    (
                        [productCode] => DOM
                        [orderNumber] => 52600
                        [commercialName] => TEXT_SENDER_NAME
                    )

                [parcel] => stdClass Object
                    (
                        [weight] => 1
                    )

                [sender] => stdClass Object
                    (
                        [senderParcelRef] => T01222345
                        [address] => stdClass Object
                            (
                                [companyName] => TEXT_SENDER_NAME
                                [line2] => TEXT_SENDER_ADDRESS
                                [countryCode] => TEXT_SENDER_COUNTRY_CODE
                                [city] => TEXT_SENDER_CITY
                                [zipCode] => TEXT_SENDER_ZIPCODE
                                [phoneNumber] => TEXT_SENDER_PHONE_NUMBER
                            )

                    )

                [addressee] => stdClass Object
                    (
                        [address] => stdClass Object
                            (
                                [companyName] => ****
                                [firstName] => jc
                                [lastName] => ***
                                [line2] => ********
                                [countryCode] => FR
                                [city] => ***
                                [zipCode] => ***
                                [mobileNumber] => ******
                                [email] => *****
                            )

                    )

            )

    )

)

我尝试过很多东西(例如有或没有soapVar),现在挖掘stackoverflow和其他资源一段时间,但我现在真的开始努力了。

对此有任何建议。

1 个答案:

答案 0 :(得分:0)

我找到了,抱歉在我的两天多次尝试中,我在generateLabel调用中留下了数组,它应该是:

$api_result = $soap_client->generateLabel($api_struct);