如果“message”受到保护,我该如何检索名为“message”的SOAP响应?

时间:2015-12-04 18:14:03

标签: php soap

我真的坚持这个。在这篇文章的底部,我附上了我正在使用的API文档。当响应(“问”)不是“成功”时,我想抓住“消息”。看似合理,对吧?但是,当我做类似的事情时:

sfcSendError('Something went wrong. This is the message from the API: ' . $result->message);

我收到致命错误:

PHP Fatal error: Cannot access protected property SoapFault::$message

我找到this seemingly related question on SO,所以我尝试将“message”更改为“getMessage()”但是(毫不奇怪)会导致调用未定义函数的致命错误。

这是我的代码段:

    $client = mySoapClient(MODULE_SHIPPING_SFC_API_URL);
    if (!$client) {
        sfcSendError('could not make a SOAP connection. Halting until next CRON. [' . __FILE__ . ':' . __LINE__ . ']', 'SOAP Failure in cron job');
        exit; //halt and wait for the next time cron runs
    } else {
        $HeaderRequest = array(
                        'customerId' => MODULE_SHIPPING_SFC_ACCOUNT,
                        'appToken' => MODULE_SHIPPING_SFC_TOKEN,
                        'appKey' => MODULE_SHIPPING_SFC_KEY
        );

        $reg = array(
                    'HeaderRequest'  => $HeaderRequest,
                    'detailLevel' => 1,
                    'ordersCode' => $_query->fields['sfc_ordersCode']
        );
        $result = $client->getOrderByCode($reg);
        if ($result->ask != "Success") {
            sfcSendError('Something went wrong. This is the message from SFC:  ' . $result->message, 'SOAP Failure in cron job');
            $_query->MoveNext();
            continue;
        }
}

这是引用的功能:

function mySoapClient($url)
{
    try {
        $client = @new SoapClient($url, array(
            'trace' => 1,
            'exceptions' => 0,
            'encoding' => 'UTF-8'
        ));
    } catch (SoapFault $e) {
        return 0;
    }
    return $client;
}

我做错了什么?或者这是API的一个“错误”,他们真的不应该在他们的回复中使用“消息”吗?

enter image description here

0 个答案:

没有答案