PHP Soap客户端调用

时间:2018-07-10 15:32:52

标签: php xml api soap request

我很绝望。我正在尝试从php这样的xml调用soap请求

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"xmlns:hot="http://hotelconcepts.com/">   <soapenv:Header>
  <hot:Authentication>
     <!--Optional:-->
     <hot:User>?</hot:User>
     <!--Optional:-->
     <hot:Password>?</hot:Password>
     <!--Optional:-->
     <hot:CrsProperty>?</hot:CrsProperty>
     <!--Optional:-->
     <hot:VendorId>?</hot:VendorId>
     <!--Optional:-->
     <hot:Version>?</hot:Version>
  </hot:Authentication>   
</soapenv:Header>   
<soapenv:Body>
  <hot:CwiPackageAvailabilityDetails>
     <!--Optional:-->
     <hot:PropertyCode>?</hot:PropertyCode>
     <!--Optional:-->
     <hot:Packages>
        <!--Zero or more repetitions:-->
        <hot:string>?</hot:string>
     </hot:Packages>
     <hot:StartDate>?</hot:StartDate>
     <hot:EndDate>?</hot:EndDate>
     <!--Optional:-->
     <hot:Adults>0</hot:Adults>
     <!--Optional:-->
     <hot:Children>0</hot:Children>
     <!--Optional:-->
     <hot:Infants>0</hot:Infants>
     <!--Optional:-->
     <hot:Nights>0</hot:Nights>
  </hot:CwiPackageAvailabilityDetails>

我正在尝试类似的操作,但是我不知道如何通过php soap客户端模仿这个xml请求。

    $client = new SoapClient($this->wsdl);

    $headers = array(
        "Authentication" => array(
            "User" => $this->user,
            "Password" => $this->pass,
            "CrsProperty" => $this->crsProperty
        )
    );

    $client->__setSoapHeaders($headers);

    /* Set your parameters for the request */
    $params = array(
        "User" => $this->user,
        "Password" => $this->pass,
        "CrsProperty" => $this->crsProperty,
        "PropertyCode" => $this->propertyCode,
        "StartDate" => $startDate,
        "EndDate" => $endDate,
        "Adults" => $adults,
        "Children" => $children,

    );
    try {
        /* Invoke webservice method with your parameters, in this case: Function1 */
        $response = $client->__soapCall("CwiPackageAvailabilityDetails", array($params, $headers));
    } catch (\Exception $e) {
        echo $e->getMessage();
    }
        echo "REQUEST:\n" . $client->__getLastRequest() . "\n";
    /* Print webservice response */
    var_dump($response);
}

但是我只收到以下消息:服务器无法处理请求。 --->未通过财产认证

谢谢您的帮助

1 个答案:

答案 0 :(得分:0)

我强烈建议您使用PackageGenerator,就像在WSDL中很好地声明了标头一样,那么在发送请求之前,您将具有适当的方法对其进行设置。每个参数都由生成的类表示,例如适当的ServiceType类中的每个操作。