php-ews:致命错误:未捕获的SoapFault异常:[Client]Class';EWS_Exception


php-ews: Fatal error: Uncaught SoapFault exception: [Client] Class 'EWS_Exception'

信息

我已经运行这个代码一年了,直到昨天一切都很好。请参阅下面的错误消息。该代码只获取收件箱中未读电子邮件的数量。随着数量的增加,它还会在运行代码的客户端上播放声音。我的Exchange服务器正在运行Exchange server 2013 CU12,但它一直在使用ExchangeWebServices:VERSION_2010(请参阅代码bolow)。

错误消息

致命错误:未捕获的SoapFault异常:[Client]类"EWS_exception"未在/var/www/html/php-EWS/NTLSoapClient.php中找到:87堆栈跟踪:#0/var/www/html/php-EWS/NTLSoap Client.php(87):NTLMSoapClient::__doRequest()#1[内部函数]:NTLMSoapClient->__doRequesthttps://mail.se...','http://schemas....',1,0)#2/var/www/html/php-ews/ExchangeWebServices.php(552):SoapClient->__call('FindItem',Array)#3/var/www/html/php-eews/ExchangeWebServices.php

我的代码基于以下代码:http://litphp.info/want_to_print_unread_mail_body_and_subject_using_ews_from_exchange_server_in_php

我的代码

function __autoload($class_name)
{
    // Start from the base path and determine the location from the class name,
    $base_path = 'php-ews';
    $include_file = $base_path . '/' . str_replace('_', '/', $class_name) . '.php';
    return (file_exists($include_file) ? require_once $include_file : false);
}
$ews = new ExchangeWebServices("mail.server.path.com", $mailuser, $mailpass, ExchangeWebServices::VERSION_2010);
$request = new EWSType_FindItemType();
$itemProperties = new EWSType_ItemResponseShapeType();
$itemProperties->BaseShape = EWSType_DefaultShapeNamesType::ID_ONLY;
$itemProperties->BodyType = EWSType_BodyTypeResponseType::BEST;
$request->ItemShape = $itemProperties;
$fieldType = new EWSType_PathToUnindexedFieldType();
$fieldType->FieldURI = 'message:IsRead';
$constant = new EWSType_FieldURIOrConstantType();
$constant->Constant = new EWSType_ConstantValueType();
$constant->Constant->Value = "0";
$IsEqTo = new EWSType_IsEqualToType();
$IsEqTo->FieldURIOrConstant = $constant;
$IsEqTo->Path = $fieldType;
$request->Restriction = new EWSType_RestrictionType();
$request->Restriction->IsEqualTo = new EWSType_IsEqualToType();
$request->Restriction->IsEqualTo->FieldURI = $fieldType;
$request->Restriction->IsEqualTo->FieldURIOrConstant = $constant;
$request->IndexedPageItemView = new EWSType_IndexedPageViewType();
$request->IndexedPageItemView->BasePoint = 'Beginning';
$request->IndexedPageItemView->Offset = 0;
$request->ParentFolderIds = new EWSType_NonEmptyArrayOfBaseFolderIdsType();
$request->ParentFolderIds->DistinguishedFolderId = new EWSType_DistinguishedFolderIdType();
$request->ParentFolderIds->DistinguishedFolderId->Mailbox = new StdClass;
$request->ParentFolderIds->DistinguishedFolderId->Mailbox->EmailAddress = 'emailaddress@test.com';
$request->ParentFolderIds->DistinguishedFolderId->Id = EWSType_DistinguishedFolderIdNameType::INBOX;
$request->Traversal = EWSType_ItemQueryTraversalType::SHALLOW;
$result = new EWSType_FindItemResponseMessageType();
$result = $ews->FindItem($request);
if ($result->ResponseMessages->FindItemResponseMessage->ResponseCode == 'NoError' && $result->ResponseMessages->FindItemResponseMessage->ResponseClass == 'Success'){
    // Need this variable to check for the new value.
    $count_new = $result->ResponseMessages->FindItemResponseMessage->RootFolder->TotalItemsInView;
    // Play sound if value has increased.
    if($_SESSION['count_previous'] < $count_new) {
        echo '<script type="text/javascript">play_sound();</script>';
    }
    // Saving the value for later usage.
    $count = $result->ResponseMessages->FindItemResponseMessage->RootFolder->TotalItemsInView;
    // Saving the current count to a session. Need it to compair with the new value ($count_new).
    $_SESSION['count_previous'] = $count;
    if($count > 0) {
        echo '<script type="text/javascript">document.body.style.backgroundColor = "#fc2828";</script>';
        echo "<h1>" . $count . "</h1><br>";
        echo '<img src="img/mail.png" height="165px">';
    } else {
        echo '<h1 class="paddingH12 test">No mail</h1>';
    }
}

过了一段时间,我想可能是代码"像"VERSION_2010一样停止了工作,因为服务器是2013 CU12。我尝试了以下解决方案,但没有成功:https://github.com/jamesiarmes/php-ews/issues/195

有人知道如何解决这个问题吗?这有点令人沮丧,因为代码工作了大约一年,现在却没有了。服务器端没有任何更改。

提前谢谢。

很抱歉收到这篇文章。现在它又开始工作了。我不知道问题出在哪里。可能是Exchange服务器或网络上的高负载。请随意使用此代码只获取未读的电子邮件。

我还在60秒后刷新页面(否则声音就不起作用):

<meta http-equiv="refresh" content="60">

声音的JavaScript(在标题中):

<script type="text/javascript">
    function play_sound() {
        var audioElement = document.createElement('audio');
        audioElement.setAttribute('src', '/sound/mail.mp3');
        audioElement.setAttribute('autoplay', 'autoplay');
        audioElement.load();
        audioElement.play();
    }
</script>