donglu5728 2015-12-04 18:14
浏览 36

如果“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

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 关于使用MATLAB中copularnd函数的问题
    • ¥20 在虚拟机的pycharm上
    • ¥15 jupyterthemes 设置完毕后没有效果
    • ¥15 matlab图像高斯低通滤波
    • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
    • ¥15 钢筋实图交点识别,机器视觉代码
    • ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)
    • ¥50 400g qsfp 光模块iphy方案
    • ¥15 两块ADC0804用proteus仿真时,出现异常
    • ¥15 关于风控系统,如何去选择