【问题标题】:Avoid duplicate items when creating contact in Php-Ews在 Php-Ews 中创建联系人时避免重复项目
【发布时间】:2018-06-28 09:40:03
【问题描述】:

我正在使用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',
        )
    ),
));

该代码实际上运行良好,但如果我多次执行它,它会复制联系人。

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

【问题讨论】:

    标签: php exchangewebservices php-ews


    【解决方案1】:

    判断联系人是否已存在特定电子邮件地址的最简单方法是使用 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;
        }
    

    【讨论】:

    • 感谢您的回答,但 EWSType_ResolveNamesType() 似乎没有与@Gaethp php-ews 库捆绑在一起,但我在 Yii2 中找到了它,但它不起作用。这是Fatal error: Uncaught Exception: Call to undefined method Exchange\Ews::ResolveNames() in /Volumes/Biro-HD/Sites/ews/vendor/segpacto/yii2-ews/Ews.php:709 Stack trace: #0 [internal function]: Exchange\Ews->exceptionHandler(Object(Error)) #1 {main} thrown in /Volumes/Biro-HD/Sites/ews/vendor/segpacto/yii2-ews/Ews.php on line 709 抛出的错误
    猜你喜欢
    • 1970-01-01
    • 2014-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-27
    相关资源
    最近更新 更多