首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >PHP-EWS -订阅/ PushNotification - complete示例

PHP-EWS -订阅/ PushNotification - complete示例
EN

Stack Overflow用户
提问于 2015-06-28 20:02:00
回答 1查看 1.2K关注 0票数 4

在沮丧的两天之后,我放弃了。我有一个虚拟机器"admx“与Win2012R2 +Exchange2013(试用版)和一个虚拟机器"webserver”与IIS-Webserver+PHP。

订阅新内容- sub.php:

代码语言:javascript
运行
复制
<?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';
    //$include_file = str_replace('_', '/', $class_name) . '.php';

    return (file_exists($include_file) ? require_once $include_file : false);
}

$server = "admx";
$host = $server;
$username = "administrator@testdom.local";
$password = "secret123";
$version = "Exchange2013";

$url = "http://webserver/testexchange/log.php";
$keepAliveFrequency = 1;

$ews = new ExchangeWebServices($server, $username, $password, $version);
$subscribe_request = new EWSType_SubscribeType();
$pushSubscription = new EWSType_PushSubscriptionRequestType();
$pushSubscription->StatusFrequency = $keepAliveFrequency;
$pushSubscription->URL = $url;
$folderIDs = new EWSType_NonEmptyArrayOfBaseFolderIdsType();
$eventTypes = new EWSType_NonEmptyArrayOfNotificationEventTypesType();
$folderIDs->DistinguishedFolderId = new EWSType_DistinguishedFolderIdType();
$folderIDs->DistinguishedFolderId->Id = EWSType_DistinguishedFolderIdNameType::INBOX;
$eventTypes->EventType = "NewMailEvent";
$pushSubscription->FolderIds = $folderIDs;
$pushSubscription->EventTypes = $eventTypes;
$subscribe_request->PushSubscriptionRequest = $pushSubscription;
$response = $ews->Subscribe($subscribe_request);

var_dump($response);
?>

输出:

代码语言:javascript
运行
复制
object(stdClass)#10 (1) { ["ResponseMessages"]=> object(stdClass)#11 (1) { ["SubscribeResponseMessage"]=> object(stdClass)#12 (4) { ["ResponseCode"]=> string(7) "NoError" ["ResponseClass"]=> string(7) "Success" ["SubscriptionId"]=> string(64) "EgBhZG14LnRlc3Rkb20ubG9jYWwQAAAA3keYE/U5Mkacz2FAg6DfHKdXyqelf9II" ["Watermark"]=> string(40) "AQAAAF57K7d1ihJLl9odwZ02gVahGgAAAAAAAAA=" } } } 

因此,订阅已成功注册。下面是监听器- log.php

代码语言:javascript
运行
复制
<?PHP
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns1=\"http://schemas.microsoft.com/exchange/services/2006/messages\">
    <SOAP-ENV:Body>
        <ns1:SendNotificationResult>
            <ns1:SubscriptionStatus>OK</ns1:SubscriptionStatus>
        </ns1:SendNotificationResult>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>";

file_put_contents("C:\\exlog\\only_ok_".time().".txt", print_r($_REQUEST,1));
?>

现在,我每分钟(因为$keepAliveFrequency = 1;)从Exchange-Server获得一个新的响应/ StatusCheck。当我向administrator@testdom.local发送eMail时,我也会立即收到新的通知(因为收件箱中的"NewMailEvent“)。我确认它是XML,以保持订阅的活动状态...到目前一切尚好。

但在日志文件(only_ok_1435488594.txt)中只有...

代码语言:javascript
运行
复制
Array()

更新log.php以获取通知信息:

代码语言:javascript
运行
复制
<?PHP
 class ewsService {
    public function SendNotification( $arg ) {
        file_put_contents("C:\\exlog\\logfile2_".time().".txt", print_r($arg,1));
        $result = new EWSType_SendNotificationResultType();
        $result->SubscriptionStatus = 'OK';
        //$result->SubscriptionStatus = 'Unsubscribe';
        return $result;
    }
}


$server = new SoapServer( 'php-ews/wsdl/NotificationService.wsdl', array(    'uri' => 'http://webserver/testexchange/log.php'));
$server->setObject( $service = new ewsService() );
$server->handle();
?>

现在,日志文件中包含了更多信息,如"array()":

代码语言:javascript
运行
复制
stdClass Object
(
    [ResponseMessages] => stdClass Object
        (
            [SendNotificationResponseMessage] => stdClass Object
                (
                    [ResponseCode] => NoError
                    [ResponseClass] => Success
                    [Notification] => stdClass Object
                        (
                            [SubscriptionId] => EgBhZG14LnRlc3Rkb20ubG9jYWwQAAAAvfY+2ehqCEOXroWYNAsn+mD+ZBQYf9II
                            [PreviousWatermark] => AQAAAF57K7d1ihJLl9odwZ02gVZNGAAAAAAAAAA=
                            [MoreEvents] => 
                            [StatusEvent] => stdClass Object
                                (
                                    [Watermark] => AQAAAF57K7d1ihJLl9odwZ02gVZNGAAAAAAAAAA=
                                )

                        )

                )

        )
)

问题:订阅在丢失3个以上的通知后获得。据我所知,从MSDN文档中,Exchangeserver重试3次listener消息,从监听器得到"OK“。

我已经从GoogleSearch下载了NotificationService.wsdl。

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2007 Microsoft Corporation. All rights reserved. -->
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" targetNamespace="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
    <wsdl:types>
        <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
            <xs:import namespace="http://schemas.microsoft.com/exchange/services/2006/messages" schemaLocation="messages.xsd"/>
        </xs:schema>
    </wsdl:types>
    <wsdl:message name="SendNotificationSoapIn">
        <wsdl:part name="request" element="tns:SendNotification" />
    </wsdl:message>
    <wsdl:message name="SendNotificationSoapOut">
        <wsdl:part name="SendNotificationResult" element="tns:SendNotificationResult" />
    </wsdl:message>
    <wsdl:portType name="NotificationServicePortType">
        <wsdl:operation name="SendNotification">
            <wsdl:input message="tns:SendNotificationSoapIn" />
            <wsdl:output message="tns:SendNotificationSoapOut" />
        </wsdl:operation>
    </wsdl:portType>


    <wsdl:binding name="NotificationServiceBinding" type="tns:NotificationServicePortType">
        <wsdl:documentation>
            <wsi:Claim conformsTo="http://ws-i.org/profiles/basic/1.0" xmlns:wsi="http://ws-i.org/schemas/conformanceClaim/" />
        </wsdl:documentation>
        <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />

        <wsdl:operation name="SendNotification">
            <soap:operation soapAction="http://schemas.microsoft.com/exchange/services/2006/messages/SendNotification" />
            <wsdl:input>
                <soap:body use="literal" />
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal" />
            </wsdl:output>
        </wsdl:operation>


    </wsdl:binding>

    <wsdl:binding name="NotificationServiceBinding12" type="tns:NotificationServicePortType">
        <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />

        <wsdl:operation name="SendNotification">
            <soap12:operation soapAction="http://schemas.microsoft.com/exchange/services/2006/messages/SendNotification" />
            <wsdl:input>
                <soap12:body use="literal" />
            </wsdl:input>
            <wsdl:output>
                <soap12:body use="literal" />
            </wsdl:output>
        </wsdl:operation>

    </wsdl:binding>

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


</wsdl:definitions>

我还添加了这个,因为如果没有它,我会得到一个“绑定错误”

代码语言:javascript
运行
复制
<wsdl:service name="NotificationServices">
    <wsdl:port name="NotificationServicePort" binding="tns:NotificationServiceBinding">
        <soap:address location="" />
    </wsdl:port>
</wsdl:service>

我不是肥皂方面的专业人士。这里出了什么问题?谢谢你,奥利

EN

回答 1

Stack Overflow用户

发布于 2015-08-10 16:34:56

下面是一个完整的工作示例:https://github.com/jamesiarmes/php-ews/issues/280

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31099562

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档