Web services : Client SOAP PHP

Résolu/Fermé
clementinemonrency Messages postés 7 Date d'inscription mercredi 23 septembre 2015 Statut Membre Dernière intervention 19 octobre 2015 - 23 sept. 2015 à 09:47
clementinemonrency Messages postés 7 Date d'inscription mercredi 23 septembre 2015 Statut Membre Dernière intervention 19 octobre 2015 - 2 oct. 2015 à 18:29
Bonjour,

Je suis en train de créer un client pour communiquer avec un web services, mais je suis bloqué sur une erreur d'authentification.
Voici le code de test que j'ai :

<?php

// la requête soap
$data='POST /API/API.asmx HTTP/1.1
Host: api.xxx.net
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/GetHotels"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetHotels xmlns="https://www.bing.com/?toHttps=1&redig=E2A68CC53634401DA4F71B1599B6E7DE">
<request>
<AGENTINFO>
<AGENT_ID>xxx</AGENT_ID>
<AGENT_PWD>xxx</AGENT_PWD>
</AGENTINFO>
<PASSENGERLIST>
<PASSENGER>
<ID>1000</ID>
<TITLE>titre1</TITLE>
<LASTNAME>lastname1</LASTNAME>
<FIRSTNAME>firstname1</FIRSTNAME>
<PASSTYPE>ADT</PASSTYPE>
<DOB>12.02.1990</DOB>
<GENDER>MR</GENDER>
</PASSENGER>
<PASSENGER>
<ID>1001</ID>
<TITLE>titre2</TITLE>
<LASTNAME>lastname2</LASTNAME>
<FIRSTNAME>firstname2</FIRSTNAME>
<PASSTYPE>ADT</PASSTYPE>
<DOB>05.11.1980</DOB>
<GENDER>MR</GENDER>
</PASSENGER>
</PASSENGERLIST>
<TOWNCODE>Alanya</TOWNCODE>
<CHECKINDATE>02.11.2015</CHECKINDATE>
<CHECKOUTDATE>10.11.2015</CHECKOUTDATE>
<HOTELCODE>BA</HOTELCODE>
<LANGUAGECODE>ENG</LANGUAGECODE>
</request>
</GetHotels>
</soap:Body>
</soap:Envelope>';

// connexion au web services
$wsdl="http://api.xxx.net/API/API.asmx?WSDL";
$user="xxx";
$pwd="xxx";

try{
$auth = array(
'login' => $user,
'password' => $pwd,
"authentication" => SOAP_AUTHENTICATION_BASIC,
"trace" => true,
"exceptions" => 0,
"cache_wsdl" => WSDL_CACHE_NONE
);
$sClient = new SoapClient($wsdl, $auth);
echo "<h2>TRY response</h2>";
// récupération de la réponse
$response = $sClient->GetHotels($data);
echo "<form><TEXTAREA readonly rows=20 cols=132>";
print_r($response);
echo "</TEXTAREA></form>";

}

// récupération de l'erreur
catch(SoapFault $e){
echo "<h2>CATCH response</h2>";

echo "<form><TEXTAREA readonly rows=20 cols=132>";
print_r($e);
echo "</TEXTAREA></form>";
}

?>
A voir également:

2 réponses

nicelife90 Messages postés 615 Date d'inscription vendredi 24 septembre 2010 Statut Membre Dernière intervention 10 avril 2018 151
Modifié par nicelife90 le 30/09/2015 à 02:10
J'ai ceci qui semble fonctionner, mais je n'ai pas de user, pass donc je sais pas trop!

Il ce peux que les clé doivent être en minuscule!

ATTENTION LE CODE EST DIFFÉRENT DU CODE PRÉCÉDENT :

error_reporting(E_ALL);
ini_set("display_errors", 1);
 

$wsdl = "http://api.suaytur.net/API/API.asmx?WSDL";
$user="allo";
$pwd="test";

$data = array(
    'request' => array(
        'AGENTINFO' => array('AGENT_ID' => $user, 'AGENT_PWD' => $pwd),
        'PASSENGERLIST' => array(
            array(
                'ID' => '1000',
                'TITLE' => 'titre1',
                'LASTNAME' => 'lastname1',
                'FIRSTNAME' => 'firstname1',
                'PASSTYPE' => 'ADT',
                'DOB' => '12.02.1990',
                'GENDER' => 'MR'
            ),
            array(
                'ID' => '1001',
                'TITLE' => 'titre2',
                'LASTNAME' => 'lastname2',
                'FIRSTNAME' => 'firstname2',
                'PASSTYPE' => 'ADT',
                'DOB' => '05.11.1980',
                'GENDER' => 'MR'
            )
        ),
        'TOWNCODE' => 'Alanya',
        'CHECKINDATE' => '02.11.2015',
        'CHECKOUTDATE' => '10.11.2015',
        'HOTELCODE' => 'BA',
        'LANGUAGECODE' => 'ENG',
    )
);

try{
	$sClient = new SoapClient($wsdl, array('trace' => 1));
	$response = $sClient->GetHotels($data);
	
	echo "<pre>";
	
	//AFFICHE LA RÉPONSE 
	print_r($response);
	
	//AFFICHE LA REQUËTE XML
	echo "REQUEST:<br/>" . htmlentities(str_ireplace('><', ">\n<", $sClient->__getLastRequest())) . "<br/><br/><br/>";
	
	//AFFICHE LA RÉPONSE XML
	echo "Response:<br/>" . htmlentities(str_ireplace('><', ">\n<", $sClient->__getLastResponse())) . "<br/>";
	
	echo "</pre>";
} 
catch(SoapFault $fault){
	echo $fault->faultstring;
} 


Voici la requête que mon code crée!

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/">
<SOAP-ENV:Body>
<ns1:GetHotels>
<ns1:request>
<ns1:AGENTINFO>
<ns1:AGENT_ID>allo</ns1:AGENT_ID>
<ns1:AGENT_PWD>test</ns1:AGENT_PWD>
</ns1:AGENTINFO>
<ns1:PASSENGERLIST>
<ns1:PASSENGER>
<ns1:ID>1000</ns1:ID>
<ns1:TITLE>titre1</ns1:TITLE>
<ns1:LASTNAME>lastname1</ns1:LASTNAME>
<ns1:FIRSTNAME>firstname1</ns1:FIRSTNAME>
<ns1:PASSTYPE>ADT</ns1:PASSTYPE>
<ns1:DOB>12.02.1990</ns1:DOB>
<ns1:GENDER>MR</ns1:GENDER>
</ns1:PASSENGER>
<ns1:PASSENGER>
<ns1:ID>1001</ns1:ID>
<ns1:TITLE>titre2</ns1:TITLE>
<ns1:LASTNAME>lastname2</ns1:LASTNAME>
<ns1:FIRSTNAME>firstname2</ns1:FIRSTNAME>
<ns1:PASSTYPE>ADT</ns1:PASSTYPE>
<ns1:DOB>05.11.1980</ns1:DOB>
<ns1:GENDER>MR</ns1:GENDER>
</ns1:PASSENGER>
</ns1:PASSENGERLIST>
<ns1:TOWNCODE>Alanya</ns1:TOWNCODE>
<ns1:CHECKINDATE>02.11.2015</ns1:CHECKINDATE>
<ns1:CHECKOUTDATE>10.11.2015</ns1:CHECKOUTDATE>
<ns1:HOTELCODE>BA</ns1:HOTELCODE>
<ns1:LANGUAGECODE>ENG</ns1:LANGUAGECODE>
</ns1:request>
</ns1:GetHotels>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>


Je suis donc pas mal sur que ça fonctionne!

Bonne chance à toi et bonne fin de journée!
N!C£-L!F£!!!
1
clementinemonrency Messages postés 7 Date d'inscription mercredi 23 septembre 2015 Statut Membre Dernière intervention 19 octobre 2015
Modifié par clementinemonrency le 1/10/2015 à 10:16
Merci déjà pour ton code :)
Maintenant, j'ai cette erreur :
stdClass Object
(
[GetHotelsResult] => stdClass Object
(
[SEARCH_RESPONSE] => stdClass Object
(
[ROOMPRICE] => 0
[COMMISSIONAMOUNT] => 0
[ERRORINFO] => Input string was not in a correct format.
[minChildAge] => 0
[maxChildAge] => 0
[monthControl] => 0
)

)

)
0
clementinemonrency Messages postés 7 Date d'inscription mercredi 23 septembre 2015 Statut Membre Dernière intervention 19 octobre 2015
1 oct. 2015 à 13:33
Problème résolu.
La variable TOWNCODE devrait être Int pourtant elle est String sur la doc.
Merci !
0
clementinemonrency Messages postés 7 Date d'inscription mercredi 23 septembre 2015 Statut Membre Dernière intervention 19 octobre 2015
Modifié par clementinemonrency le 2/10/2015 à 18:58
Bonjour,
Je reviens vers toi car après la récupération de la réponse SOAP, je pouvais pas configurer le parsing XML.

Voici un extrait de la response SOAP :

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetHotelsResponse xmlns="https://www.bing.com/?toHttps=1&redig=E2A68CC53634401DA4F71B1599B6E7DE">
<GetHotelsResult>

<SEARCH_RESPONSE>
<HOTELCODE>BA</HOTELCODE>
<CANCELLATIONLIST>
<CANCELLATION_POLICY>
<cancelBeginDate>2015-10-02T00:00:00</cancelBeginDate>
<cancelEndDate>2015-10-17T00:00:00</cancelEndDate>
<PENALTY>171.60</PENALTY>
</CANCELLATION_POLICY>
<CANCELLATION_POLICY>
<cancelBeginDate>2015-10-17T00:00:00</cancelBeginDate>
<cancelEndDate>2015-10-25T00:00:00</cancelEndDate>
<PENALTY>249.60</PENALTY>
</CANCELLATION_POLICY>
</CANCELLATIONLIST>
</SEARCH_RESPONSE>

<SEARCH_RESPONSE>
<HOTELCODE>SH</HOTELCODE>
<CANCELLATIONLIST>
<CANCELLATION_POLICY>
<cancelBeginDate>2015-10-02T00:00:00</cancelBeginDate>
<cancelEndDate>2015-10-17T00:00:00</cancelEndDate>
<PENALTY>277.20</PENALTY>
</CANCELLATION_POLICY>
</CANCELLATIONLIST>
</SEARCH_RESPONSE>

</GetHotelsResult>
</GetHotelsResponse>
</soap:Body>
</soap:Envelope>

Je cherche à afficher le résultat de cette forme :
Code : BA
Pénalités d'annulation:
- Entre 02-10-2015 et 17-10-2015 : 171.6
- Entre 17-10-2015 et 25-10-2015 : 249.6
Code : SH
Pénalités d'annulation:
- Entre 02-10-2015 et 17-10-2015 : 277.2

Ce code ...
$rcXML = simplexml_load_string($ghdata);

envoie cette erreur :
Warning: simplexml_load_string(): Entity: line 1: parser error : Start tag expected, '<' not found in /var/www/vhosts/.../GetHotels.php on line 115

Warning: simplexml_load_string(): <?xml version="1.0" encoding="utf-8"?> in /var/www/vhosts/.../GetHotels.php on line 115

Warning: simplexml_load_string(): ^ in /var/www/vhosts/.../GetHotels.php on line 115


Merci !
0
nicelife90 Messages postés 615 Date d'inscription vendredi 24 septembre 2010 Statut Membre Dernière intervention 10 avril 2018 151
24 sept. 2015 à 03:07
Bonjour,

Est-ce possible d'avoir plus de détails sur le service web que tu essais d'exploité.

0
nicelife90 Messages postés 615 Date d'inscription vendredi 24 septembre 2010 Statut Membre Dernière intervention 10 avril 2018 151
24 sept. 2015 à 03:10
Je dois voir la doc de l'API pour pouvoir t'aider d'avantage!
0
clementinemonrency Messages postés 7 Date d'inscription mercredi 23 septembre 2015 Statut Membre Dernière intervention 19 octobre 2015
29 sept. 2015 à 12:41
J'ai ce lien : http://api.suaytur.net/API/API.asmx
0