php
  • xml
  • api
  • soap
  • nodes
  • 2016-06-17 7 views 0 likes 
    0

    私はCURLを使用して、コールのSOAP APIリクエストをしようとここに私のコードでいます:xmlノードレベルの値を読み取る方法は?

    $wsdl = "http://xxxxx//xxxxx//xxxxx"; 
    $body = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:par="http:///xxxxx.com"> 
        <soapenv:Header/> 
        <soapenv:Body> 
         <par:createReservationReq> 
         <par:garageID>47</par:garageID> 
         <par:orderNumber>orderNumber'.$id.'</par:orderNumber> 
         <!--1 or more repetitions:--> 
         <par:vehicles> 
          <par:barCode>barCode'.$id.'</par:barCode> 
          <!--Optional:--> 
          <par:licensePlate>licensePlate'.$id.'</par:licensePlate> 
          <par:startTime>2015-11-20T22:53:45.547</par:startTime> 
          <par:endTime>2015-11-21T22:53:45.547</par:endTime> 
          <!--Optional:--> 
          <par:vehicleMake>vehicleMake'.$id.'</par:vehicleMake> 
          <!--Optional:--> 
          <par:vehicleModel>vehicleMode'.$id.'</par:vehicleModel> 
          <!--Optional:--> 
          <par:vehicleColor>vehicleColor'.$id.'</par:vehicleColor> 
         </par:vehicles> 
         <!--Optional:--> 
         <par:grossPrice>152.6</par:grossPrice> 
         <!--Optional:--> 
         <par:commFee>162.6</par:commFee> 
         <!--Optional:--> 
         <par:customerName>customerName'.$id.'</par:customerName> 
         <!--Optional:--> 
         <par:customerEmail>customerEmail'.$id.'</par:customerEmail> 
         <!--Optional:--> 
         <par:customerPhone>customerPhone'.$id.'</par:customerPhone> 
         <!--Optional:--> 
         <par:reentryAllowed>true</par:reentryAllowed> 
         </par:createReservationReq> 
        </soapenv:Body> 
    </soapenv:Envelope>'; 
    
    // initializing cURL with the IPG API URL: 
    $ch = curl_init($wsdl); 
    
    // setting the request type to POST: 
    curl_setopt($ch, CURLOPT_POST, 1); 
    
    // setting the content type: 
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml")); 
    
    // setting the authorization method to BASIC: 
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); 
    
    // filling the request body with your SOAP message: 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $body); 
    
    // telling cURL to verify the server certificate: 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
    
    // telling cURL to return the HTTP response body as operation result 
    // value when calling curl_exec: 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    
    // calling cURL and saving the SOAP response message in a variable which 
    // contains a string like "<SOAP-ENV:Envelope ...>...</SOAP-ENV:Envelope>": 
    
    $result = curl_exec($ch); 
    
    // loads the XML 
    $xml = simplexml_load_string($result); 
    

    今、私は、XML応答から値を読み取る方法を理解していません。あなたが適切なアイデアを得ることができますので、私はここに私の応答データを追加してい:

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> 
        <soapenv:Header/> 
        <soapenv:Body xmlns:s="http://www.w3.org/2003/05/soap-envelope"> 
         <tns:createReservationResp xmlns:tns="http://xxxxx.com"> 
         <tns:success>true</tns:success> 
         <tns:message>Test Garage order orderNumber168. created 2015-11-19 00:30:57.905</tns:message> 
         <tns:orderTime>2015-11-19 00:30:57.905</tns:orderTime> 
         <tns:reservations> 
          <tns:garageID>47</tns:garageID> 
          <tns:barCode>barCode168</tns:barCode> 
          <tns:licensePlate>licensePlate168</tns:licensePlate> 
          <tns:orderNumber>orderNumber168</tns:orderNumber> 
          <tns:used>false</tns:used> 
          <tns:cancelled>false</tns:cancelled> 
          <tns:startTime>2015-11-20 22:53:45.547</tns:startTime> 
          <tns:endTime>2015-11-21 22:53:45.547</tns:endTime> 
          <tns:cancelledTime/> 
          <tns:checkInTime/> 
          <tns:checkOutTime/> 
          <tns:grossPrice>152.6</tns:grossPrice> 
          <tns:commFee>162.6</tns:commFee> 
          <tns:customerName>customerName168</tns:customerName> 
          <tns:customerEmail>customerEmail168</tns:customerEmail> 
          <tns:customerPhone>customerPhone168</tns:customerPhone> 
          <tns:vehicleMake>vehicleMake168</tns:vehicleMake> 
          <tns:vehicleModel>vehicleModel68</tns:vehicleModel> 
          <tns:vehicleColor>vehicleColor168</tns:vehicleColor> 
          <tns:reentryAllowed>true</tns:reentryAllowed> 
         </tns:reservations> 
         </tns:createReservationResp> 
        </soapenv:Body> 
    </soapenv:Envelope> 
    

    私は応答からこの値を読みたい:

    <tns:success>true</tns:success> 
    <tns:message>Test Garage order orderNumber168. created 2015-11-19 00:30:57.905</tns:message> 
    <tns:orderTime>2015-11-19 00:30:57.905</tns:orderTime> 
    
    <tns:garageID>47</tns:garageID> 
    <tns:barCode>barCode168</tns:barCode> 
    

    任意のアイデア?

    ありがとうございました。

    +0

    多分これは役立ちます:http://stackoverflow.com/questions/6516902/how-to-get-response-using-curl-in-php – Rumpelstinsk

    +1

    サイドノートを:SOAPを呼び出すと、[のSoapClientとのより良いです](http://php.net/manual/en/soapclient.soapcall.php) –

    答えて

    1

    一般に、curlの代わりにSOAPを処理する場合は、SoapClientを使用する必要があります。よりクリーンなインターフェースを提供します。あなたの場合、SimpleXML関数で作業する必要があります。良いチュートリアルはSitePointです。

    $soapenv = $xml->children("http://schemas.xmlsoap.org/soap/envelope/"); 
    $tns = $soapenv->Body->children("http://xxxxx.com"); 
    echo "success: " . $tns->createReservationResp->success . "\n"; 
    echo "message: " . $tns->createReservationResp->message . "\n"; 
    echo "orderTime: " . $tns->createReservationResp->orderTime . "\n"; 
    echo "garageID: " . $tns->createReservationResp->reservations->garageID . "\n"; 
    echo "barCode: " . $tns->createReservationResp->reservations->barCode . "\n"; 
    
    +0

    このトピックについて助けてもらえますか? 'http://stackoverflow.com/questions/38055023/php-not-able-to-可能であれば、read-xml-sub-node-value'を使用します。 –

    関連する問題