Précédent   Forum des professionnels en informatique > PHP > Bibliothèques et frameworks > XML
XML Forum d'entraide sur XML avec PHP. Exemples : SimpleXML, OpenXML... Avant de poster -> FAQ XML, Cours XML et Sources XML
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 11/06/2007, 17h59   #1
Nouveau Membre du Club
 
Développeur Web
Inscription : 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 : 28
Points : 28
Envoyer un message via MSN à lehic Envoyer un message via Skype™ à lehic
Par défaut 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 :
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 :
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
lehic est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 14/06/2007, 11h42   #2
Membre éclairé
 
Inscription : janvier 2004
Messages : 424
Détails du profil
Informations personnelles :
Âge : 39
Localisation : France, Paris (Île de France)

Informations forums :
Inscription : janvier 2004
Messages : 424
Points : 311
Points : 311
Moi je faisais un truc dans ce genre :

Code :
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 :
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..
zevince est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 15/06/2007, 16h58   #3
Nouveau Membre du Club
 
Développeur Web
Inscription : 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 : 28
Points : 28
Envoyer un message via MSN à lehic Envoyer un message via Skype™ à lehic
Merci, j'ai regle mon prob comme ceci :
Code :
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";
		}
lehic est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 14h35.


 
 
 
 
Partenaires

Hébergement Web