脚本宝典收集整理的这篇文章主要介绍了PHP-EWS – 订阅/推送通知 – 完整示例,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
<?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); ?>
输出:
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=" } } }
<?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的新的respone / StatusCheck.当我发送电子邮件到administrator@testdom.local时,我也会立即收到新的通知(因为收件箱中的“NewMailEvent”).
我确认它是正确的XML,以保持订阅…
到现在为止还挺好.
但是在日志文件(only_ok_1435488594.txt)中只有……
Array()
<?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()”:
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文档中,Exchange服务器重试状态消息的3倍以从侦听器获得“OK”.
我从GOOGLESeArch下载了NotificationService.wsdl.
<?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>
<wsdl:service name="NotificationServices"> <wsdl:port name="NotificationServicePort" binding="tns:NotificationServiceBinding"> <soap:address location="" /> </wsdl:port> </wsdl:service>
我不是SOAP的专家……这里出了什么问题?
谢谢
奥利
以上是脚本宝典为你收集整理的PHP-EWS – 订阅/推送通知 – 完整示例全部内容,希望文章能够帮你解决PHP-EWS – 订阅/推送通知 – 完整示例所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。