PHP-EWS - Notification Service
Hi,
I'm implementing the PHP-EWS plugin in my Laravel 5.3 project. Specifically, I'm coupling the fullcalendar plugin in our CRM-Program with my Exchange Calendar. I've succeeded in retrieving events from exchange, updating events in fullcalendar and updating Exchange. However I'm now working on the Notifications. If something changes in Exchange Calendar, I need to warn the user to refresh his calendar (or automatically refresh). I'm having a difficult time implementing examples that I found online.
Here is my controller
<?php
namespace App\Http\Controllers;
use auth;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
use \jamesiarmes\PhpEws\Client;
use jamesiarmes\PhpEws\Enumeration\CalendarItemCreateOrDeleteOperationType;
use \jamesiarmes\PhpEws\Request\FindItemType;
use \jamesiarmes\PhpEws\ArrayType\NonEmptyArrayOfBaseFolderIdsType;
use \jamesiarmes\PhpEws\ArrayType\NonEmptyArrayOfNotificationEventTypesType;
use \jamesiarmes\PhpEws\Enumeration\DefaultShapeNamesType;
use \jamesiarmes\PhpEws\Enumeration\DistinguishedFolderIdNameType;
use \jamesiarmes\PhpEws\Enumeration\ResponseClassType;
use \jamesiarmes\PhpEws\Enumeration\ItemQueryTraversalType;
use \jamesiarmes\PhpEws\Request\SubscribeType;
use \jamesiarmes\PhpEws\Type\CalendarViewType;
use \jamesiarmes\PhpEws\Type\DistinguishedFolderIdType;
use \jamesiarmes\PhpEws\Type\ItemResponseShapeType;
use \jamesiarmes\PhpEws\Type\PushSubscriptionRequestType;
use \jamesiarmes\PhpEws\Request\UpdateItemType;
use \jamesiarmes\PhpEws\ArrayType\NonEmptyArrayOfItemChangeDescriptionsType;
use \jamesiarmes\PhpEws\Enumeration\CalendarItemUpdateOperationType;
use \jamesiarmes\PhpEws\Enumeration\ConflictResolutionType;
use \jamesiarmes\PhpEws\Enumeration\UnindexedFieldURIType;
use \jamesiarmes\PhpEws\Type\CalendarItemType;
use \jamesiarmes\PhpEws\Type\ItemChangeType;
use \jamesiarmes\PhpEws\Type\ItemIdType;
use \jamesiarmes\PhpEws\Type\PathToUnindexedFieldType;
use \jamesiarmes\PhpEws\Type\SetItemFieldType;
use SoapServer;
class CalendarController extends Controller
{
private $host;
private $username;
private $password;
private $version;
public function __construct()
{
$this->host = "example.exchange.com";
$this->username = "user@exchange";
$this->password = "PWD";
$this->version = Client::VERSION_2010;
}
public function index() {
$this->notifications();
return view ('calendar.calendar');
}
public function notifications() {
$client = new Client( $this->host, $this->username, $this->password, $this->version);
$subscribe_request = new SubscribeType();
$pushSubscription = new PushSubscriptionRequestType();
$pushSubscription->StatusFrequency = 1;
$pushSubscription->URL = 'http://localhost/calendar/subscription-response';
$folderIDs = new NonEmptyArrayOfBaseFolderIdsType();
$eventTypes = new NonEmptyArrayOfNotificationEventTypesType();
$folderIDs->DistinguishedFolderId = new DistinguishedFolderIdType();
$folderIDs->DistinguishedFolderId->Id = DistinguishedFolderIdNameType::CALENDAR;
$eventTypes->EventType = "NewMailEvent";
$pushSubscription->FolderIds = $folderIDs;
$pushSubscription->EventTypes = $eventTypes;
$subscribe_request->PushSubscriptionRequest = $pushSubscription;
$response = $client->Subscribe($subscribe_request);
}
public function subscriptionresponse()
{
$server = new SoapServer( 'wsdl/services.wsdl', array('uri' => 'http://localhost/calendar/subscription-response'));
$server->setObject( $service = new ewsService() );
$server->handle();
}
}
class ewsService {
public function SendNotification( $arg ) {
file_put_contents("C:\\exlog\\log_".time().".txt", print_r($arg,1));
file_put_contents("C:\\exlog\\log_".time().".txt", print_r($arg,1));
$result = new SendNotificationResultType();
$result->SubscriptionStatus = 'OK';
//$result->SubscriptionStatus = 'Unsubscribe';
return $result;
}
}
The SOAP response from the function notifications
SubscribeResponseType {#396 ▼
+ResponseMessages: ArrayOfResponseMessagesType {#397 ▼
+SubscribeResponseMessage: array:1 [▼
0 => SubscribeResponseMessageType {#398 ▼
+SubscriptionId: "FQBzZXJ2ZXIuZXhjaGFuZ2UubG9jYWwQAAAABzRzPnKL10qeIE8KArlRujP8D9VbOdQI"
+Watermark: "AQAAANfwhcDMeYFOiTUbLVhp7ZSO6bsKAAAAAAA="
+DescriptiveLinkKey: null
+MessageText: null
+MessageXml: null
+ResponseClass: "Success"
+ResponseCode: "NoError"
}
]
}
}
This indicates that I'm succesfully subscribed to the notification service. The callback location is setup as follows:
Route::get('/calendar/subscription-response', 'CalendarController@subscriptionresponse');
I'm however not getting anything back. Is this a code issue or is this because im developing local?
Please or to participate in this conversation.