0

我正在使用garethp/php-ews库下载推送到我的脚本的新电子邮件(通过推送通知)。作为推送通知的一部分,我需要回复“OK”状态;我在下面的尝试是抛出一个 SOAP 错误:

PHP 致命错误:SOAP-ERROR: Encoding: object has no 'SubscriptionStatus' property in ...

<?php

ini_set("soap.wsdl_cache_enabled", 0);
require_once('vendor/autoload.php');

use garethp\ews\API;
use garethp\ews\API\ExchangeWebServicesAuth;
use garethp\ews\API\Type\ConnectingSIDType;
use garethp\ews\API\Type\ExchangeImpersonation;
use garethp\ews\API\Type\ItemIdType;
use garethp\ews\API\Type\NonEmptyArrayOfBaseItemIdsType;
use garethp\ews\API\Type\ItemResponseShapeType;
use garethp\ews\API\Message\SendNotificationResultType;
use garethp\ews\API\Message\SendNotificationResult;
use garethp\ews\API\Message\ArrayOfResponseMessagesType;
use garethp\ews\API\Message\SendNotificationResponseType;
use garethp\ews\API\Message\GetItemType;
use garethp\ews\API\Enumeration\DefaultShapeNamesType;
use garethp\ews\API\Enumeration\SubscriptionStatusType;

class EwsPushService
{
    public function SendNotification($arg)
    {
        $responseCode = $arg->ResponseMessages->SendNotificationResponseMessage->ResponseCode;
        if ($responseCode == "NoError") {
            $notification = $arg->ResponseMessages->SendNotificationResponseMessage->Notification;
            if (isset($notification->NewMailEvent)) {
                // Download message
            }
        }

        $notificationResponse = new SendNotificationResultType();
        $notificationResponse->setSubscriptionStatus(SubscriptionStatusType::OK);

        return $notificationResponse;
    }
}

$service = new EwsPushService();
$server = new SoapServer('php-ews/wsdl/NotificationService.wsdl');
$server->setObject($service);
$server->handle();

我试图删除缓存的 WSDL 文件,并soap.wsdl_cache_enabled在我的脚本中设置为 0 没有任何运气。我正在使用的 WSDL 来自nginn-exchange,并添加了以下内容:

<wsdl:service name="NotificationServices">
    <wsdl:port name="NotificationServicePort" binding="tns:NotificationServiceBinding">
        <soap:address location="" />
    </wsdl:port> 
</wsdl:service>

我不确定出了什么问题,或者调查 SOAP 问题的最佳方法,但任何建议都将不胜感激。

[编辑] 我相信问题实际上出在我正在使用的库上;所以我提出了一个问题,当我确定时会更新......

4

1 回答 1

0

该库符合 PSR-2 代码样式,因此订阅状态存储在一个名为 的变量中$subscriptionStatus,通常这将作为类内调用的结果传递给ucfirst,这在我的情况下没有发生。为了解决这个问题,我需要这样调用:toXmlObjectTypetoXmlObject

$notificationResponse = new SendNotificationResultType();
$notificationResponse->setSubscriptionStatus(SubscriptionStatusType::OK);
return $notificationResponse->toXmlObject();
于 2018-01-30T10:51:37.143 回答