我想使用php发送带有多个项目的肥皂请求

时间:2018-10-17 15:31:22

标签: php soap request

我想使用php发送肥皂请求,但是我发现这里存在一个问题,我必须以XML格式发送

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/">
  <soap:Header/>
  <soap:Body>
    <tem:getImpayee>
      <tem:tocken>reererer</tem:tocken>
      <tem:CodeCreancier>1013</tem:CodeCreancier>
      <tem:CodeCreance>01</tem:CodeCreance>
      <tem:crVals>
        <tem:CreancierVals>
          <tem:nomChamp>montant</tem:nomChamp>
          <tem:ValeurChamp>45</tem:ValeurChamp>
        </tem:CreancierVals>
        <tem:CreancierVals>
          <tem:nomChamp>ND</tem:nomChamp>
          <tem:ValeurChamp>0663143327</tem:ValeurChamp>
        </tem:CreancierVals>
      </tem:crVals>
    </tem:getImpayee>
  </soap:Body>
</soap:Envelope>

但是问题是当我使用它时有多个“ tem:CreancierVals”

$client->__setLocation(url_PaiementWS);
$result = $client->getImpayee(
    array(
        'tocken' => $_SESSION['tocken'],
        'CodeCreancier' => $CodeCreancier,
        'CodeCreance' => $CodeCreance,
        'crVals' => array (
            'CreancierVals' => array(
                'nomChamp' => 'montant',
                'ValeurChamp' => $montant
            ),
            'CreancierVals' => array(
                'nomChamp' => 'ND',
                'ValeurChamp' => $ND
            )
        )
    )
);

它不起作用 就像重置“ CreancierVals” val 有没有可以使用php发送纯xml的解决方案?或只是一种动态方法,它不会重置“ CreancierVals” val,而是将一个作为数组添加到另一个。谢谢

1 个答案:

答案 0 :(得分:2)

尝试一下:

$result = $client->getImpayee(
    [
        'tocken'        => $_SESSION['tocken'],
        'CodeCreancier' => $CodeCreancier,
        'CodeCreance'   => $CodeCreance,
        'crVals'        => [
            'CreancierVals' => [
                [
                    'nomChamp'    => 'montant',
                    'ValeurChamp' => $montant,
                ],
                [
                    'nomChamp'    => 'ND',
                    'ValeurChamp' => $ND,
                ],
            ],
        ],
    ]
);