aspose/email-sdk-php

此包已被弃用,不再维护。作者建议使用 aspose/aspose-email-cloud 包。

此存储库包含 Aspose Cloud SDK for PHP 源代码。Aspose Cloud SDK for PHP 允许 PHP 开发者快速轻松地在云端转换和处理各种文件格式。

20.2.0 2020-02-26 12:47 UTC

This package is auto-updated.

Last update: 2020-03-02 21:54:46 UTC


README

此存储库包含 Aspose.Email Cloud SDK for PHP 源代码。此 SDK 允许您在 PHP 应用程序中快速轻松地使用 Aspose.Email Cloud REST API,且无需初始成本。

Aspose.Email Cloud 主页
API 参考

主要功能

Aspose.Email Cloud 是一个 REST API,用于创建与标准电子邮件文件格式兼容的电子邮件应用程序。此 SDK

  • 允许开发者操作不同的电子邮件格式,如 Outlook MSG、EML、VCard 和 iCalendar 文件
  • 内置电子邮件客户端
  • 支持 AI 功能
    • 名片识别
    • 用于解析和处理个人姓名的姓名 API

如何使用 SDK?

完整的源代码可在 GIT 存储库中找到。使用 参考文档本文档中的示例维基

先决条件

要使用此 SDK,您需要一个 App SID 和一个 App Key;它们可以在 Aspose Cloud Dashboard 中找到(这需要免费注册 Aspose Cloud)。

安装

您可以直接通过源代码在项目中使用 SDK,或者通过 Packagist 分发 获取。从命令行

composer require aspose/aspose-email-cloud

使用示例

要使用 API,您应该创建一个 EmailApi 对象

$configuration = new Configuration(); // Aspose\Email\Configuration
$configuration
    ->setAppKey($_ENV["Your App Key"])
    ->setAppSid($_ENV["Your App SID"]);
$api = new EmailApi(
    null, //GuzzleHttp client, will be created automatically if parameter is null
    $configuration);

API 调用可以是同步的或异步的(使用 GuzzleHttp\Promise)

$file = "iCalendarFileName.ics"; //iCalendar file name on storage
$folder = "path/to/iCalendar/file/on/storage";
$storage = "First Storage"; //Storage name

$result = $api->getCalendar(new GetCalendarRequest($file, $folder, $storage));
// or
$promise = $api->getCalendarAsync(new GetCalendarRequest($file, $folder, $storage));
$result = $promise->wait();

名片识别 API

以下为示例

解析名片图片到 VCard 联系人文件
$folder = "some/folder/on/storage";
$storage = "First Storage"; //Storage name
$path = "C:\\path\\to\\business\\card\\image\\on\\file\\system";
$imageFile = "someFileName.png"; //Supports different image formats: PNG, JPEG, BMP, TIFF, GIF, etc.
$storagePath = $folder."/".$imageFile;
// Upload business card image to storage
$api->uploadFile(new UploadFileRequest($storagePath, $path, $storage));
$outFolderPath = "some/folder/on/storage"; //Business card recognition results will be saved here
$api->createFolder(new CreateFolderRequest($outFolderPath, $storage));
// Call business card recognition action
$result = $api->aiBcrParseStorage(new AiBcrParseStorageRequest(
    new AiBcrParseStorageRq(null,
        array( //We can process multiple images in one request
            new AiBcrImageStorageFile(true, //Flag isSingle determines that image contains single VCard or more.
                                            //Only single VCard on image variant is supported in current version.
                new StorageFileLocation($storage, $folder, $imageFile))),
        new StorageFolderLocation($storage, $outFolderPath))));
// Get file name from recognition result
$contactFile = $result->getValue()[0]; //$result->getValue() can contain multiple files, if we sent multicard images or multiple images
// You can download the VCard file, which produced by the recognition method ...
$contactTempFile = $api->downloadFile(new DownloadFileRequest(
    $contactFile->getFolderPath()."/".$contactFile->getFileName(),
    $storage));
// ... read content and print it
$fileContent = $contactTempFile->fread($contactTempFile->getSize());
echo $fileContent;
// Also, you can get VCard object properties’ list using Contact API
$contactProperties = $api->getContactProperties(
    new GetContactPropertiesRequest(
        'vcard',
        $contactFile->getFileName(),
        $contactFile->getFolderPath(),
        $storage));
//All VCard’s properties are available as a list. Complex properties are represented as hierarchical structures.
//Let's print all primitive properties’ values:
$filtered = array_filter(
    $contactProperties->getInternalProperties(),
    function($var) {
        return $var->getType() == "PrimitiveObject";
    });
foreach($filtered as $property)
{
    echo "Property name: ".$property->getName().", value: ".$property->getValue();
}
直接解析图片,不使用存储
//Read image from file and convert it to Base64 string
$path = "C:\\path\\to\\business\\card\\image\\on\\file\\system";
$content = file_get_contents($path);
$imageBase64 = base64_encode($content);
$result = $api->aiBcrParse(new AiBcrParseRequest(
    new AiBcrBase64Rq(null, array(new AiBcrBase64Image(true, $imageBase64)))));
//Result contains all recognized VCard objects (only the one in our case)
$contactProperties = $result->getValue()[0];
//VCard object is available as a list of properties, without any external calls:
$filtered = array_filter(
    $contactProperties->getInternalProperties(),
    function($var) {
        return $var->getType() == "PrimitiveObject";
    });
foreach($filtered as $property)
{
    echo "Property name: ".$property->getName().", value: ".$property->getValue();
}

姓名 API

以下为示例

通过姓名检测一个人的性别
$result = $api->aiNameGenderize(new AiNameGenderizeRequest("John Cane"));
// the result contains a list of hypothesis about a person's gender.
// all hypothesis include score, so you can use the most scored version,
// which will be the first in a list:
echo $result->getValue()[0]->getGender(); //prints "Male"
使用定义的格式格式化人员姓名
$result = $api->aiNameFormat(new AiNameFormatRequest(
    "Mr. John Michael Cane", null, null, null, null, "%t%L%f%m"));
echo $result->getName(); //prints "Mr. Cane J. M."
比较姓名以确定它们是否属于同一个人
$first = "John Michael Cane";
$second = "Cane J.";
$result = $api->aiNameMatch(new AiNameMatchRequest($first, $second));
echo $result->getSimilarity() >= 0.5 ? "true" : "false"; //prints "true", names look similar
将一个人的姓名展开为可能的替代列表
$name = "Smith Bobby";
$result = $api->aiNameExpand(new AiNameExpandRequest($name));
$expandedNames = array_map(function($weightedName) {
    return $weightedName->getName();
}, $result->getNames());
foreach($expandedNames as $name)
{
    echo $name; //prints "Mr. Smith", "B. Smith", etc.
}
获取给定起始字符的前 k 个最可能的姓名
$prefix = "Dav";
$result = $api->aiNameComplete(new AiNameCompleteRequest($prefix));
$names = array_map(function ($weightedName) use ($prefix) {
    return $prefix.$weightedName->getName();
}, $result->getNames());
foreach($names as $name)
{
    echo $name; //prints "David", "Dave", "Davis", etc.
}
从电子邮件地址中解析出一个人的姓名。
$address = "john-cane@gmail.com";
$result = $api->aiNameParseEmailAddress(
    new AiNameParseEmailAddressRequest($address));
$extractedNames = array_map(function ($value) {
    return $value->getName();
}, $result->getValue());
$reduced = array_reduce($extractedNames, 'array_merge', array());
$givenName = array_values(array_filter($reduced, function ($value) {
    return $value->getCategory() == "GivenName";
}))[0];
$surname = array_values(array_filter($reduced, function ($value) {
    return $value->getCategory() == "Surname";
}))[0];
echo $givenName; //John
echo $surname; //Cane

许可

所有 Aspose.Email for Cloud SDK、辅助脚本和模板均在 MIT 许可证 下授权。

资源