2016-12-04 1 views
0

J'ai besoin d'aide pour envoyer des données de demande à l'API SOAP en utilisant wsdl en PHP. J'ai installé l'extension de soapclient pour PHP et cela fonctionne bien. Voici le script:Demande SOAP PHP avec wsdl ne fonctionne pas, il me donne une erreur "SOAP-ERROR: Encodage: objet n'a pas de propriété 'phoneNumber'"

<?php 

$client = new SoapClient($wsdlUrl, array('username' => USER_NAME, 'password' => PASSWORD,'trace'=>'1','exception'=>0)); 
$method = "templateSMS"; 

$xmlr = new SimpleXMLElement("<Sms></Sms>"); 
$xmlr->addChild("phoneNumber",PHONE_NUMBER); 
$xmlr->addChild('message', 'Hi how are you'); 
$xmlr->addChild('unicodeMessage', 0); 
$xmlr->addChild('sms_type_id', 1); 
$xmlr->addChild('senderId', SENDER_ID); 
$xmlr->addChild('notify', 0); 
$xmlr->addChild('priority', 1); 
$xmlr->addChild('vbApp', 'SoapRequest'); 
$xmlr->addChild('vbIdTime', time()); 
$params = new stdClass(); 
$params->xml = $xmlr->asXML(); 
try {  
    $data = $client->$method($params); 
    var_dump($data); 
}catch (SoapFault $e) {  
    echo "<pre> Exceptions Break :"; 
    print_r($e); 
    echo "</pre>"; 
} 
?> 

Quand je lance au-dessus du code dans le navigateur, il me donne une erreur « SOAP ERREUR: Encoding: objet n'a pas « phoneNumber » »

Voici le journal des erreurs , pourrait être plus serviable pour résoudre mon problème:

Exceptions Break :SoapFault Object 
(
[message:protected] => SOAP-ERROR: Encoding: object has no 'phoneNumber' property 
[string:Exception:private] => 
[code:protected] => 0 
[file:protected] => C:\xampp\htdocs\soapDemo\opt3.php 
[line:protected] => 18 
[trace:Exception:private] => Array 
    (
     [0] => Array 
      (
       [file] => C:\xampp\htdocs\soapDemo\opt3.php 
       [line] => 18 
       [function] => __call 
       [class] => SoapClient 
       [type] => -> 
       [args] => Array 
        (
         [0] => templateSMS 
         [1] => Array 
          (
           [0] => stdClass Object 
            (
             [xml] => 
    Hi how are you0101SoapRequest1480835353 

            ) 

          ) 

        ) 

      ) 

     [1] => Array 
      (
       [file] => C:\xampp\htdocs\soapDemo\opt3.php 
       [line] => 18 
       [function] => templateSMS 
       [class] => SoapClient 
       [type] => -> 
       [args] => Array 
        (
         [0] => stdClass Object 
          (
           [xml] => 
     Hi how are you0101SoapRequest1480835353 

          ) 

        ) 

      ) 

    ) 

[previous:Exception:private] => 
[faultstring] => SOAP-ERROR: Encoding: object has no 'phoneNumber' property 
[faultcode] => Client 
[faultcodens] => http://schemas.xmlsoap.org/soap/envelope/ 
) 

équipe de soutien me donne un code XML exemple pour passer le format de demande et est ici l'échantillon format de requête XML, demande devrait être le même que ci-dessous:

<?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:templateSMS" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns2="urn:ElbaridTNS" xmlns:ns3="namespace" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> 
<SOAP-ENV:Header> 
<ns3:AuthHeader> 
<username>username </username> 
<password>password</password> 
</ns3:AuthHeader> 
</SOAP-ENV:Header> 
<SOAP-ENV:Body> 
<ns1:templateSMS> 
<Sms xsi:type="ns2:Sms"><phoneNumber xsi:type="xsd:string">xxxxxx</phoneNumber> 
<message xsi:type="xsd:string">test SMS </message> 
<unicodeMessage xsi:type="xsd:string">test SMS</unicodeMessage> 
<sms_type_id xsi:type="xsd:string">1</sms_type_id> 
<notify xsi:type="xsd:string">0</notify> 
<senderId xsi:type="xsd:string">SenderId</senderId> 
<priority xsi:type="xsd:string">2</priority> 
<vbApp xsi:type="xsd:string">SoapRequest</vbApp> 
<vbIdTime xsi:type="xsd:string">20161130101112</vbIdTime> 
<destinationPort xsi:type="xsd:string">-1</destinationPort></Sms> 
</ns1:templateSMS> 
</SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 

réponse devrait ressembler à ceci:

<?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:templateSMS" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> 
<SOAP-ENV:Body> 
<ns1:templateSMSResponse> 
<templateSMSResponse xsi:type="xsd:string">0#!#200#!#http://198.101.210.203/Soap/service/elbarid|http://212.98.137.180/Soap/service/elbarid#!#SenderId </templateSMSResponse> 
</ns1:templateSMSResponse> 
</SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 

Quelqu'un peut-il me aider à résoudre mon problème? J'essaye aussi avec CURL mais j'ai la même erreur répond.

Merci :)

Répondre

0

Vous devez utiliser un tableau de passes comme paramètre.

$params = array('Sms'=>array('phoneNumber'=>'123456879','message'=>'test')); //add all params. in Sms array. 

Et puis appeler la méthode

$data = $client->$method($params); 
+0

Merci pour la réponse .... Mais je reçois même erreur: SOAP ERREUR: Encoding: objet n'a pas 'phoneNumber' – JGandhi