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

I'm really stuck on this one. At the bottom of this post, I've attached the API documentation I'm working with. I want to catch the "message" when the response ("ask") isn't "Success". Seems reasonable enough, right? But when I do something like:

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

I get a fatal error:

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

I found this seemingly related question on SO, so I tried changing "message" to "getMessage()" but (no surprise) that results in a different fatal error about calling an undefined function.

Here's my code snippet:

    $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;
        }
}

This is the referenced function:

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

What am I doing wrong? Or is this a "bug" with the API where they really shouldn't be using "message" in their response?

enter image description here

donglikuang8145
donglikuang8145 或者在课程中导航并搜索您可以找到的方法:return$this->message;
4 年多之前 回复
dongqi8030
dongqi8030 提供mySoapClient()类的链接;
4 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问