本文介绍了phpsoap客户端多节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次在 php 应用程序中使用带有 SOAP 的 Web 服务.其实我做这样的事情:

$urlxml = "https://rec.wspar51.april.fr/WSSante/WSSante.asmx?wsdl";$client = new SoapClient($urlxml);$parameters = new stdClass();$parameters->astr_Clef = "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}";$parameters->TarifParams = new stdClass();$parameters->TarifParams->IdCo = "00000";$parameters->TarifParams->Devis = new stdClass();$parameters->TarifParams->Devis->Assure = new stdClass();$parameters->TarifParams->Devis->Assure->Nom = "toto";$parameters->TarifParams->Devis->Assure->Prenom = "titi";$parameters->TarifParams->Devis->Assure->NumeroAssure = 1;$parameters->TarifParams->Devis->Assure->Type = "Adherent";$parameters->TarifParams->Devis->Assure->DateNaissance = "19800615";$parameters->TarifParams->Devis->Assure->RegimeObligatoire = "SS";$parameters->TarifParams->Devis->Parametres = new stdClass();$parameters->TarifParams->Devis->Parametres->DateEffet="20110809";$parameters->TarifParams->Devis->Parametres->CodePostal="27140";$parameters->TarifParams->Devis->Parametres->BesoinHospitalisation="Minimum";$parameters->TarifParams->Devis->Parametres->BesoinFraisMedicaux="Complete";$parameters->TarifParams->Devis->Parametres->BesoinDentaire="Complete";$parameters->TarifParams->Devis->Parametres->BesoinOptique="Maximum";$parameters->TarifParams->Devis->Parametres->Produit="";$parameters->TarifParams->Devis->Parametres->DeuxEurosMalins = False;尝试{echo "

";打印_r($参数);echo "</pre>";$response = $client->Tarif($parameters);echo "

";打印_r($响应);echo "</pre>";}捕获(异常 $e){echo '<br/><hr/>';echo "<b>Exception est:</b>" .$e;}

我的问题是:我怎样才能使Devis->Assure像在这个文档 还是下面的例子?

<Nom>#nom1#</Nom><Prenom>#prenom1#</Prenom><NumeroAssure>#panier#</NumeroAssure><类型>粘附</类型><DateNaissance>#dn1webservice#</DateNaissance><RegimeObligatoire>#reg1#</RegimeObligatoire></保证><cfif len(trim(civ2)) gt 0><保证><Nom>#nom2#</Nom><Prenom>#prenom2#</Prenom><NumeroAssure>#panier#</NumeroAssure><类型>联合</类型><DateNaissance>#dn2webservice#</DateNaissance><RegimeObligatoire>#reg1#</RegimeObligatoire></保证></cfif>'

我需要制作一个数组或类似的东西吗?

解决方案

我终于在 Assure 节点中创建了一个数组,如下所示:

$this->params_service->TarifParams->Devis->Assure[0] = new stdClass();$this->params_service->TarifParams->Devis->Assure[0]->Nom = $customerObject->lastname;$this->params_service->TarifParams->Devis->Assure[0]->Prenom = $customerObject->firstname;$this->params_service->TarifParams->Devis->Assure[0]->NumeroAssure = $customerObject->id;$this->params_service->TarifParams->Devis->Assure[0]->Type = "Adherent";$this->params_service->TarifParams->Devis->Assure[0]->DateNaissance = $this->formatDate($customerObject->birthday);//日期格式:YYYYMMDD$this->params_service->TarifParams->Devis->Assure[0]->RegimeObligatoire = $this->formatRegime($customerObject->regime_id);//获取客户家族$family = Family::getCompleteFamily($customerObject->id);$i = 0;如果($家庭){foreach ($family 作为 $member) {$i++;$this->params_service->TarifParams->Devis->Assure[$i] = new stdClass();$this->params_service->TarifParams->Devis->Assure[$i]->NumeroAssure = $member['id'];$this->params_service->TarifParams->Devis->Assure[$i]->Type = $this->formatType($member['type']);$this->params_service->TarifParams->Devis->Assure[$i]->DateNaissance = $this->formatDate($member['birthday']);$this->params_service->TarifParams->Devis->Assure[$i]->RegimeObligatoire = $this->formatRegime($member['regime_id']);}

它就像一个魅力:)

It's the first time I use a web service with SOAP in a php application.Actually I do something like this :

$urlxml = "https://rec.wspar51.april.fr/WSSante/WSSante.asmx?wsdl";
$client = new SoapClient($urlxml);

$parameters = new stdClass();
$parameters->astr_Clef = "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}";

$parameters->TarifParams = new stdClass();
$parameters->TarifParams->IdCo = "00000";

$parameters->TarifParams->Devis = new stdClass();
$parameters->TarifParams->Devis->Assure = new stdClass();
$parameters->TarifParams->Devis->Assure->Nom = "toto";
$parameters->TarifParams->Devis->Assure->Prenom  = "titi";
$parameters->TarifParams->Devis->Assure->NumeroAssure  = 1;
$parameters->TarifParams->Devis->Assure->Type  = "Adherent";
$parameters->TarifParams->Devis->Assure->DateNaissance  = "19800615";
$parameters->TarifParams->Devis->Assure->RegimeObligatoire  = "SS";

$parameters->TarifParams->Devis->Parametres = new stdClass();
$parameters->TarifParams->Devis->Parametres->DateEffet ="20110809";
$parameters->TarifParams->Devis->Parametres->CodePostal ="27140";
$parameters->TarifParams->Devis->Parametres->BesoinHospitalisation ="Minimum";
$parameters->TarifParams->Devis->Parametres->BesoinFraisMedicaux ="Complete";
$parameters->TarifParams->Devis->Parametres->BesoinDentaire ="Complete";
$parameters->TarifParams->Devis->Parametres->BesoinOptique ="Maximum";
$parameters->TarifParams->Devis->Parametres->Produit ="";
$parameters->TarifParams->Devis->Parametres->DeuxEurosMalins = False;

try{
  echo "<pre>";
  print_r($parameters);
  echo "</pre>";
  $response = $client->Tarif($parameters);
  echo "<pre>";
  print_r($response);
  echo "</pre>";
}
catch(Exception $e){
  echo '<br /><hr />';
  echo "<b>Exception est :</b> " . $e;
}

My question is : How can i make Many Devis->Assure as in this documentation or as is the example below ?

<Assure>
    <Nom>#nom1#</Nom>
    <Prenom>#prenom1#</Prenom>
    <NumeroAssure>#panier#</NumeroAssure>
    <Type>Adherent</Type>
    <DateNaissance>#dn1webservice#</DateNaissance>
    <RegimeObligatoire>#reg1#</RegimeObligatoire>
</Assure>
<cfif len(trim(civ2)) gt 0>
    <Assure>
        <Nom>#nom2#</Nom>
        <Prenom>#prenom2#</Prenom>
        <NumeroAssure>#panier#</NumeroAssure>
        <Type>Conjoint</Type>
        <DateNaissance>#dn2webservice#</DateNaissance>
        <RegimeObligatoire>#reg1#</RegimeObligatoire>
    </Assure>
</cfif>' 

I need to make an array or something like this ?

解决方案

I finally make an array in Assure node such like this :

$this->params_service->TarifParams->Devis->Assure[0] = new stdClass();
$this->params_service->TarifParams->Devis->Assure[0]->Nom = $customerObject->lastname;
$this->params_service->TarifParams->Devis->Assure[0]->Prenom  = $customerObject->firstname;
$this->params_service->TarifParams->Devis->Assure[0]->NumeroAssure  = $customerObject->id;
$this->params_service->TarifParams->Devis->Assure[0]->Type  = "Adherent";
$this->params_service->TarifParams->Devis->Assure[0]->DateNaissance  = $this->formatDate($customerObject->birthday);            // Date format : YYYYMMDD
$this->params_service->TarifParams->Devis->Assure[0]->RegimeObligatoire  = $this->formatRegime($customerObject->regime_id);
// Get the customer family
$family = Family::getCompleteFamily($customerObject->id);
$i = 0;
if($family){
    foreach ($family as $member) {
        $i++;
    $this->params_service->TarifParams->Devis->Assure[$i] = new stdClass();
    $this->params_service->TarifParams->Devis->Assure[$i]->NumeroAssure  = $member['id'];
        $this->params_service->TarifParams->Devis->Assure[$i]->Type  = $this->formatType($member['type']);
    $this->params_service->TarifParams->Devis->Assure[$i]->DateNaissance  = $this->formatDate($member['birthday']);
    $this->params_service->TarifParams->Devis->Assure[$i]->RegimeObligatoire  = $this->formatRegime($member['regime_id']);
    }

And it work like a charm :)

这篇关于phpsoap客户端多节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-08 03:03