我正在使用PHP Exchange Web服务库(https://github.com/jamesiarmes/php-ews)来检索用户可用性而不会出现问题。我想要做的是为用户检索Out of Office响应(如果设置),似乎无法弄清楚如何正确设置请求。到目前为止我所拥有的:
$ews = new ExchangeWebServices();
$request = new EWSType_GetUserOofSettingsRequest();
$request->Mailbox->Address = 'TEstUser@Test.com';
$ewsResponse = $ews->GetUserOofSettings($request);
然而我回来的只有:
stdClass Object
(
[ResponseMessage] => stdClass Object
(
[MessageText] => Connection did not succeed. Try again later.
[ResponseCode] => ErrorConnectionFailed
[DescriptiveLinkKey] => 0
[ResponseClass] => Error
)
)
有关如何正确设置此请求的任何想法?
修改 由于我收到了一些用户的电子邮件,我觉得我会相应地更新这个问题。我无法再访问Exchange环境来测试此代码,因此任何更新都会有所帮助!
以下代码来自我的ldapAdapter文件,可以按以下方式使用:
$request = createEWSRequest();
$request->MailboxDataArray->MailboxData->Email->Address = $email;
$ewsResponse = $ews->GetUserAvailability($request);
$fbtInfo = getFreeBusyTime();
private function getFreeBusyTime() {
if (isset($this->ewsResponse->FreeBusyResponseArray->FreeBusyResponse->FreeBusyView->CalendarEventArray)) {
if (is_array($this->ewsResponse->FreeBusyResponseArray->FreeBusyResponse->FreeBusyView->CalendarEventArray->CalendarEvent)) {
$this->nextMeetingStart = $this->ewsResponse->FreeBusyResponseArray->FreeBusyResponse->FreeBusyView->CalendarEventArray->CalendarEvent[0]->StartTime;
$this->nextMeetingEnd = $this->ewsResponse->FreeBusyResponseArray->FreeBusyResponse->FreeBusyView->CalendarEventArray->CalendarEvent[0]->EndTime;
$this->busyType = $this->ewsResponse->FreeBusyResponseArray->FreeBusyResponse->FreeBusyView->CalendarEventArray->CalendarEvent[0]->BusyType;
} else {
$this->nextMeetingStart = $this->ewsResponse->FreeBusyResponseArray->FreeBusyResponse->FreeBusyView->CalendarEventArray->CalendarEvent->StartTime;
$this->nextMeetingEnd = $this->ewsResponse->FreeBusyResponseArray->FreeBusyResponse->FreeBusyView->CalendarEventArray->CalendarEvent->EndTime;
$this->busyType = $this->ewsResponse->FreeBusyResponseArray->FreeBusyResponse->FreeBusyView->CalendarEventArray->CalendarEvent->BusyType;
}
$this->meetingScheduled = true;
$date = new DateTime($this->nextMeetingStart, new DateTimeZone('America/Chicago'));
$date->setTimezone(new DateTimeZone('UTC'));
$this->nextMeetingStart = $date->format(DateTime::W3C);
$date = new DateTime($this->nextMeetingEnd, new DateTimeZone('America/Chicago'));
$date->setTimezone(new DateTimeZone('UTC'));
$this->nextMeetingEnd = $date->format(DateTime::W3C);
} else {
$this->meetingScheduled = false;
$this->nextMeetingStart = false;
$this->nextMeetingEnd = false;
$this->busyType = false;
}
}
private function createEWSRequest() {
$request = new EWSType_GetUserAvailabilityRequestType();
$request->TimeZone = new EWSType_SerializableTimeZone();
$request->TimeZone->Bias = '360';
$request->TimeZone->StandardTime = new EWSType_SerializableTimeZoneTime();
$request->TimeZone->StandardTime->Bias = '0';
$request->TimeZone->StandardTime->Time = '02:00:00';
$request->TimeZone->StandardTime->DayOrder = '5';
$request->TimeZone->StandardTime->Month = '1';
$request->TimeZone->StandardTime->DayOfWeek = 'Sunday';
$request->TimeZone->DaylightTime->Bias = '-60';
$request->TimeZone->DaylightTime->Time = '02:00:00';
$request->TimeZone->DaylightTime->DayOrder = '1';
$request->TimeZone->DaylightTime->Month = '4';
$request->TimeZone->DaylightTime->DayOfWeek = 'Sunday';
$request->MailboxDataArray = new EWSType_ArrayOfMailboxData();
$request->MailboxDataArray->MailboxData = new EWSType_MailboxData();
$request->MailboxDataArray->MailboxData->Email = new EWSType_EmailAddress();
$request->MailboxDataArray->MailboxData->Email->RoutingType = 'SMTP';
$request->MailboxDataArray->MailboxData->AttendeeType = 'Required';
$request->MailboxDataArray->MailboxData->ExcludeConflicts = false;
$request->FreeBusyViewOptions = new EWSType_FreeBusyViewOptionsType();
$request->FreeBusyViewOptions->TimeWindow = new EWSType_Duration();
$request->FreeBusyViewOptions->MergedFreeBusyIntervalInMinutes = '30';
$request->FreeBusyViewOptions->RequestedView = 'FreeBusy';
$date = new DateTime();
$this->startDate = date_format($date, DateTime::W3C);
$date->modify('+8 hours');
$this->endDate = date_format($date, DateTime::W3C);
$request->FreeBusyViewOptions->TimeWindow->StartTime = $this->startDate; //'2013-04-01T15:00:00';
$request->FreeBusyViewOptions->TimeWindow->EndTime = $this->endDate; //'2013-04-20T18:00:00';
return $request;
}