在PHP中显示SOAP API结果

时间:2018-11-01 10:36:45

标签: php soap soap-client

我很难找到关于此的资源,要使用PHP连接到SOAP API并很容易将数组结果附加到变量上以进行显示。

这是API中GetCostCenters函数的SOAP API XML:

<Response><Status><Result>1</Result><Description>OK</Description></Status><CostCenters><CostCenter><ID>4</ID><Branch>Adelaide</Branch></CostCenter><CostCenter><ID>6</ID><Branch>Derby</Branch></CostCenter><CostCenter><ID>33</ID><Branch>GT Perth</Branch></CostCenter><CostCenter><ID>7</ID><Branch>Hobart Branch</Branch></CostCenter><CostCenter><ID>46</ID><Branch>Lawns & Maintenance</Branch></CostCenter><CostCenter><ID>10</ID><Branch>London</Branch></CostCenter><CostCenter><ID>3</ID><Branch>Melbourne</Branch></CostCenter><CostCenter><ID>45</ID><Branch>NECA Apprentices</Branch></CostCenter><CostCenter><ID>17</ID><Branch>New York</Branch></CostCenter><CostCenter><ID>48</ID><Branch>Nursing NSW</Branch></CostCenter><CostCenter><ID>1</ID><Branch>Perth</Branch></CostCenter><CostCenter><ID>44</ID><Branch>Registration</Branch></CostCenter><CostCenter><ID>16</ID><Branch>Rio</Branch></CostCenter><CostCenter><ID>50</ID><Branch>Subiaco</Branch></CostCenter><CostCenter><ID>51</ID><Branch>Subiaco</Branch></CostCenter><CostCenter><ID>2</ID><Branch>Sydney</Branch></CostCenter><CostCenter><ID>42</ID><Branch>test - tester</Branch></CostCenter><CostCenter><ID>49</ID><Branch>TesterOM</Branch></CostCenter><CostCenter><ID>8</ID><Branch>Tom Price</Branch></CostCenter><CostCenter><ID>47</ID><Branch>Traffic Control NSW</Branch></CostCenter></CostCenters></Response>

这是我的PHP:

    $client = new SoapClient("https://api.myfeed.com/feed.asmx?WSDL", array(
    'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
    'trace'    => true
 ));

// GET RESULTS
    $result = $client->GetCostCenters(array(
        'CompanyID'     => 'MYID',
        'APIKey'     => 'MYKEY',
        'APIPassword' => 'MYPASS',
        'features'  =>  SOAP_SINGLE_ELEMENT_ARRAYS,
        'trace' =>  true
    ));

    echo '<pre>';
    print_r($result);
    echo '</pre>';

以[any]的形式将其全部输出,如下所示:

stdClass Object
(
    [GetCostCentersResult] => stdClass Object
        (
            [any] => 1OK4Adelaide6Derby33GT Perth7Hobart Branch46Lawns & Maintenance10London3Melbourne45NECA Apprentices17New York48Nursing NSW1Perth44Registration16Rio50Subiaco51Subiaco2Sydney42test - tester49TesterOM8Tom Price47Traffic Control NSW
        )

)

我不知道为什么,理想情况下,我希望将其作为数组,以便我可以分配变量并运行循环以显示信息。

有什么想法吗?预先感谢。

0 个答案:

没有答案