IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Bibliothèques et frameworks PHP Discussion :

[XML] Comment envoyer un flux XML avec SOAP et PHP5 ?


Sujet :

Bibliothèques et frameworks PHP

  1. #1
    Membre du Club
    Profil pro
    Développeur Web
    Inscrit en
    Août 2005
    Messages
    50
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Août 2005
    Messages : 50
    Points : 45
    Points
    45
    Par défaut [XML] Comment envoyer un flux XML avec SOAP et PHP5 ?
    Bonjour, je début avec SOAP.
    Je développe un site e-commerce, et je dois implémenter le payement avec http://www.beanstream.com.

    Dans leurs documentation ils expliquent comment leurs envoyer une transaction via un exemple en ASP:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
     
    <%
        Dim objSoapClient
        Dim trnRequest
        Dim trnResponse
     
        set objSoapClient = Server.CreateObject("MSSoap.SoapClient")
        objSoapClient.ClientProperty("ServerHTTPRequest") = True
        call objSoapClient.mssoapinit ("http://www.beanstream.com/Soap/ProcessTransaction.wsdl")
     
        trnRequest = "<transaction>" & _
                    "<merchant_id>108380000</merchant_id>" & _
                    "<trnType>P</trnType>" & _
                    "<trnCardOwner>Sam Shopper</trnCardOwner>" & _
                    "<trnCardNumber>5100000010001004</trnCardNumber>" & _
                    "<trnExpMonth>01</trnExpMonth>" & _
                    "<trnExpYear>05</trnExpYear>" & _
                    "<trnOrderNumber>1231</trnOrderNumber>" & _
                    "<trnAmount>500.00</trnAmount>" & _
                    "<ordEmailAddress>user@domain.com</ordEmailAddress>" & _
                    "<ordName>Sam Shopper</ordName>" & _
                    "<ordPhoneNumber>999-999-9999</ordPhoneNumber>" & _
                    "<ordAddress1>1020 Fort Street</ordAddress1>" & _
                    "<ordAddress2></ordAddress2>" & _
                    "<ordCity>Victoria</ordCity>" & _
                    "<ordProvince>BC</ordProvince>" & _
                    "<ordPostalCode>V8T4R5</ordPostalCode>" & _
                    "<ordCountry>CA</ordCountry>" & _
                    "<ref1></ref1>" & _
                    "<ref2></ref2>" & _
                    "<ref3></ref3>" & _
                    "<ref4></ref4>" & _
                    "<ref5></ref5>" & _
                    "</transaction>"
     
        'Set the soap client to make an SSL connection to the Beanstream transaction server.
        objSoapClient.ConnectorProperty("UseSSL") = True
        
        'Set communication timeout to 100000 miliseconds (1 minute 40 seconds) to insure that response is received from the server.  Server timout is 90 seconds.
        objSoapClient.ConnectorProperty("Timeout") = 100000
     
        'Submit the request to the Beanstream transaction server.
        trnResponse = objSoapClient.TransactionProcess(trnRequest)
                  
        'Display the transction response
        response.write  trnResponse
     
        'Deallocate the soap client object
        Set objSoapClient = Nothing
    
     
    
    %>
    Habituellement, âpres avoir créé mon objet SoapClient, j'interroge une méthode du fichier WSDL comme suit :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
     
    try {
    $clientSOAP = new SoapClient("http://www.beanstream.com/Soap/ProcessTransaction.wsdl", array (
    	'login' => $user,
    	'password' => $password
    	));
    	} catch (SoapFault $exception) {
    	}
     
    try {
          $tab = $clientSOAP->getPlans(array ('plansId' => $arg));
     
        } 
    catch (SoapFault $exception) 
        {
         echo $exception;
        }
    Mais la, je dois envoyer directement un XML, ma question est donc :
    Comment envoyer un flux XML avec SOAP et PHP5 ?
    Merci

  2. #2
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2004
    Messages
    489
    Détails du profil
    Informations personnelles :
    Âge : 51
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Janvier 2004
    Messages : 489
    Points : 388
    Points
    388
    Par défaut
    Moi je faisais un truc dans ce genre :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    <html>
     
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    </head>
     
    <body>
     
    <?php
      $client = new SoapClient("http://www.*******.fr/certification-xft/xft.php?wsdl",array(
        "trace"      => 1,
        "exceptions" => 0));
     
    $case = "GetQuotedAvailability";
    $begin_date = "2007-03-10";
     
    switch ($case) {
    case "GetAvailability":
        $myxml = '<?xml version="1.0" encoding="UTF-8"?>
    	<Transaction 
    		Version="1.1" 
    		xsi:type="TransactionRequestType" 
    		Target="Test" 
    		TimeStamp="2006-05-11T14:47:40.477+02:00" 
    		xmlns="http://www.av2s.com/xft" 
    		xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    	>
    		<Control>
    			<Requester Channel="LPB2B">
    				<Agency>
    					<Code Value="1102"/>
    					<NameText><![CDATA[IGAB2B]]></NameText>
    				</Agency>
    				<Agent Name="86009 "/>
    			</Requester>
    		</Control>
    		<Action Purpose="Get" Code="Availability"/>
    		<Trip>
    			<Segment xsi:type="SegmentProductType">
    				<Code Role="Product" Value="DUNESDOR"/>
    				<Begin Value="'.$begin_date.'"/>
    				<Duration Value="7" Unit="Night"/>
    			</Segment>
    			<Travellers>
    				<Traveller Type="Adult"/>
    				<Traveller Type="Adult"/>
    			</Travellers>
    			<From xsi:type="CityType" Code="PAR"/>
    		</Trip>
    	</Transaction>';
        break;
     
     
     
     
    case "GetQuotedAvailability":
        $myxml = '<?xml version="1.0" encoding="UTF-8"?>
    <Transaction xmlns:ct="http://www.iga.fr/xft-complex/XMLSchema" Version="1.0" xsi:type="TransactionRequestType" Target="Test" TimeStamp="2006-05-11T16:59:11.267+02:00" xmlns="http://www.av2s.com/xft" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.av2s.com/xft
    C:\Data\sync\xft\XFT\xft_transaction.xsd">
    <Control>
    		<Requester Channel="LPB2B">
    			<Agency>
    				<Code Value="1102"/>
    				<NameText><![CDATA[IGAB2B]]></NameText>
    			</Agency>
    			<Agent Name="86009 "/>
    		</Requester>
    	</Control>
    	<Action Purpose="Get" Code="QuotedAvailability"/>
    	<Trip>
    		<Segment xsi:type="SegmentProductType">
    			<Code Role="Product" Value="DUNESDOR"/>
    			<Begin Value="'.$begin_date.'"/>
    		</Segment>
    		<Travellers>
    			<Traveller ID="T1" Type="Adult"/>
    			<Traveller ID="T2" Type="Adult"/>
    			<Traveller ID="T3" Type="Child" BirthDate="1998-05-11"/>
    		</Travellers>
    		<From xsi:type="CityType" Code="PAR"/>
    	</Trip>
    </Transaction>';
        break;
     
     
     
     
     
        break;
    default:
    		exit("cas non trouvé");
    }    
     
     
      $O = htmlspecialchars($client->{$case}($myxml));
     
      print "<pre>\n";
      var_dump($client->__getFunctions());
      var_dump($O);
      print "</pre>";
    ?> 
     
    </body></html>

    Tu construis ton xml, et tu appelle ton $client->maFonctionWsdl($xml);


    Sinon, tu peux passer par un wrapper.. ca depend du webservice que tu attaque..


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    $client = new SoapClient($GLOBALS['urlServices'],array('trace' => 1));
    $wrapper->engineCriteria->responseFormat = new SoapVar("Full", XSD_STRING);
     
    //Liste des champs a recuperer
    $wrapper->engineCriteria->searchEngineField = new SoapVar('meal', XSD_STRING);
    $wrapper->engineCriteria->searchEngineField = new SoapVar('cc', XSD_STRING);
     
     
     
    $response = $client->__soapCall("getSearchEngine",array($wrapper));
    $xmlResponse = $client->__getLastResponse();
    $xmlResponse = str_replace('soap:', '', $xmlResponse);
    $xml = simplexml_load_string($xmlResponse);

    En esperant que ca t'aide.. j'ai bien galéré, vu le peu de doc SOAP qu'on trouve..

  3. #3
    Membre du Club
    Profil pro
    Développeur Web
    Inscrit en
    Août 2005
    Messages
    50
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Août 2005
    Messages : 50
    Points : 45
    Points
    45
    Par défaut
    Merci, j'ai regle mon prob comme ceci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
     
    try {
    			$clientSOAP = new SoapClient($url);
    		} catch (SoapFault $exception) {
    			echo "Error wsdl: $exception";
    		}
    		$merchant = "";
     
    		$xml = "<transaction>" . "<serviceVersion>1.2</serviceVersion>" . "<merchant_id>" . $rowBeanstream[1] . "</merchant_id>" . "<trnType>P</trnType>" . "<trnCardOwner>" . $rowInfoTransaction['nameCard'] . "</trnCardOwner>" . "<trnCardNumber>" . $rowInfoTransaction['cardNumber'] . "</trnCardNumber>" . "<trnExpMonth>" . $rowInfoTransaction['expirationMonth'] . "</trnExpMonth>" . "<trnExpYear>" . $rowInfoTransaction['expirationYear'] . "</trnExpYear>" . "<trnOrderNumber>1671111235</trnOrderNumber>" . "<trnAmount>" . $rowInfoTransaction['total'] . " </trnAmount>" . "<ordEmailAddress>" . $rowInfoTransaction['email'] . "</ordEmailAddress>" . "<ordName>" . $rowInfoTransaction['name'] . "</ordName>" . "<ordPhoneNumber>" . $rowInfoTransaction['phone'] . "</ordPhoneNumber>" . "<ordAddress1>" . $rowInfoTransaction['adress'] . "</ordAddress1>" . "<ordAddress2></ordAddress2>" . "<ordCity>" . $rowInfoTransaction['city'] . "</ordCity>" . "<ordProvince>" . $rowInfoTransaction['state'] . "</ordProvince>" . "<ordPostalCode>" . $rowInfoTransaction['zip'] . "</ordPostalCode>" . "<ordCountry>" . $rowInfoTransaction['country'] . "</ordCountry>" . "</transaction>";
     
    		try {
    			$response = $clientSOAP->TransactionProcess($xml);
     
    		} catch (SoapFault $exception) {
    			echo "Error TransactionProcess: $exception";
    		}

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [Mail] Comment envoyer des e-mails avec PHP
    Par lauryk dans le forum Langage
    Réponses: 2
    Dernier message: 03/09/2007, 17h16
  2. Comment envoyer un grand tableau avec socket UDP
    Par jhon_milou dans le forum Entrée/Sortie
    Réponses: 8
    Dernier message: 29/05/2007, 09h36
  3. Réponses: 1
    Dernier message: 21/07/2006, 16h03

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo