0

我正在使用https://github.com/Garethp/php-ews/库来访问我在 Exchange 服务器上的公共联系人文件夹。

这就是我创建联系人的方式。

$api = API::withUsernameAndPassword($server, $user, $pass);
$folder = $api->getFolderByDisplayName('Public', Enumeration\DistinguishedFolderIdNameType::PUBLICFOLDERSROOT);
$contattiTotali = $api->getFolderByDisplayName('Contacts', $folder->getFolderId());
$id=$contattiTotali->getFolderId()->getId();
$api->setFolderId($contattiTotali->getFolderId());

$api->createContacts(array(
    'GivenName' => 'Homer',
    'Surname' => 'Simpson',
    'EmailAddresses' => array(
        'Entry' => array('Key' => Enumeration\EmailAddressKeyType::EMAIL_ADDRESS_1, '_value' => 'h.simpson@gmail.com')
    ),
    //Creating multiple entries
    'PhoneNumbers' => array(
        'Entry' => array(
            array('Key' => Enumeration\PhoneNumberKeyType::HOME_PHONE, '_value' => '000'),
            array('Key' => Enumeration\PhoneNumberKeyType::BUSINESS_PHONE, '_value' => '111'),
        )
    ),
    'PhysicalAddresses' => array(
        'Entry' => array(
            'Key' => Enumeration\PhysicalAddressKeyType::HOME,
            'street' => '123 Street',
            'city' => '123 City',
            'state' => '123 State',
            'countryOrRegion' => '123 Country',
            'postalCode' => '12345',
        )
    ),
));

实际上,该代码工作正常,但如果我多次执行它,它会复制联系人。

有没有办法在创建新联系人之前检查联系人(电子邮件地址是否足够好)是否已经存在?

4

1 回答 1

0

判断联系人是否已存在特定电子邮件地址的最简单方法是使用 ResolveName 操作,例如

    $request = new EWSType_ResolveNamesType();

    $request->UnresolvedEntry = "address@domain.com";
    $request->ReturnFullContactData = true;
    $return = $ews->ResolveNames($request);

    if ($return->ResponseMessages->ResolveNamesResponseMessage->ResponseCode == "NoError") {
        return $return->ResponseMessages->ResolveNamesResponseMessage->ResolutionSet->Resolution->Mailbox->EmailAddress;
    }
于 2018-06-28T01:40:03.773 回答