guilty / apsis
APSIS PHP API 客户端
1.1.0
2019-09-10 13:48 UTC
Requires
- php: ^7.2
- guzzlehttp/guzzle: ^6.3
- ramsey/uuid: ^3.8
README
APSIS API 客户端,用于与 APSIS API 交互: http://se.apidoc.anpdm.com
安装
您可以通过 composer 安装此包
composer require guilty/apsis
Laravel
此包与 Laravel 兼容
您可以通过以下方式发布配置文件
php artisan vendor:publish --provider="Guilty\Apsis\ApsisServiceProvider" --tag="config"
这是已发布配置文件的内容
return [ /* * This is the API key for your APSIS account. * Read how to generate an api key here: * http://se.apidoc.anpdm.com/Help/GettingStarted/Getting%20started */ "api_key" => env("APSIS_API_KEY") ];
要开始,将以下环境变量添加到您的 .env 文件中
APSIS_API_KEY="your-api-key"
您可以使用外观类如下
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; class NewsletterController extends Controller { public function index() { $newsletters = Apsis::newsletter()->getNewslettersPaginated(1, 10); return view('home', [ "newsletters" => $newsletters->Result->Items ]); } }
API 使用
可用服务
use \Guilty\Apsis\Factory; $apiKey = "YOUR-API-KEY"; // Create a factory like so $factory = Factory::create($apiKey); // Then fetch the service you need $accountService = $factory->account(); $eventService = $factory->event(); $subscriberService = $factory->subscriber(); $openService = $factory->open(); $bounceService = $factory->bounce(); $smsService = $factory->sms(); $filterService = $factory->filter(); $transactionalService = $factory->transactional(); $folderService = $factory->folder(); $clickService = $factory->click(); $mailingListService = $factory->mailingList(); $newsletterService = $factory->newsletter(); $sendingService = $factory->sending(); $optOutService = $factory->optOut(); $importService = $factory->import();
账户服务
$apiKey = "YOUR-API-KEY"; $accountService = Factory::create($apiKey)->account() $accountService->createSingleSignOnUrl(); $accountService->getDemographicData();
退订服务
$apiKey = "YOUR-API-KEY"; $bounceService = Factory::create($apiKey)->bounce(); $bounceService->getAll(); $bounceService->getAllPaginated($pageNumber, $pageSize); $bounceService->getBouncesForSendingPaginated($sendQueueId, $pageNumber, $pageSize); $bounceService->getByDateInterval(\DateTimeInterface $start, \DateTimeInterface $end); $bounceService->getByDateIntervalPaginated(\DateTimeInterface $start, \DateTimeInterface $end, $pageNumber, $pageSize); $bounceService->getBySendqueueIds($sendqueueIds);
点击服务
$apiKey = "YOUR-API-KEY"; $clickService = Factory::create($apiKey)->click(); $clickService->getClicksBySendqueueIdPaginated($sendQueueId, $pageNumber, $pageSize);
事件服务
$apiKey = "YOUR-API-KEY"; $eventService = Factory::create($apiKey)->event(); $eventService->addAttendee($eventId, $sessionId, $attendeeData); $eventService->getAttendees($eventId, $sessionId = null, $attendeeStatus = null); $eventService->getControls($eventId); $eventService->getEventParticipantStatus($eventId); $eventService->getEvents(); $eventService->getEventSessionAttendee($eventId, $sessionId, $attendeeEmail); $eventService->getEventsWithSessions($filters = null); $eventService->getEventWithSessions($eventId); $eventService->getOptionsDataCategories($eventId); $eventService->registerAttendee($eventId, $sessionId, $attendeeData); $eventService->updateAttendee($eventId, $sessionId, $attendeeId, $attendeeData); $eventService->updateAttendeeStatus($eventId, $attendeeId, $attendeeStatus);
过滤器服务
$apiKey = "YOUR-API-KEY"; $filterService = Factory::create($apiKey)->filter(); $filterService->createFilterByDemographicData($filterName, $demographicDataName, $operatorValue, $demographicDataValue); $filterService->getAllFilters();
文件夹服务
$apiKey = "YOUR-API-KEY"; $folderService = Factory::create($apiKey)->folder(); $filterService->createFilterByDemographicData($filterName, $demographicDataName, $operatorValue, $demographicDataValue); $filterService->createFolder($folderName, $folderType); $filterService->getAllFolders();
邮件列表服务
$apiKey = "YOUR-API-KEY"; $mailingListService = Factory::create($apiKey)->mailingList(); $mailingListService->createMailinglist($mailingListDetails); $mailingListService->createSingleSubscription($mailinglistId, $subscriberId); $mailingListService->createSubscriptions($mailinglistId, $recipientIds); $mailingListService->deleteAllMailinglistSubscriptions($mailinglistId); $mailingListService->deleteAllSubscriptionsForSubscriber($subscriberId); $mailingListService->deleteMultipleMailingLists($mailinglistIds); $mailingListService->deleteSingleSubscription($mailinglistId, $subscriberId); $mailingListService->getAllMailingLists(); $mailingListService->getMailingListDetails($mailinglistId); $mailingListService->getMailinglistsPaginated($pageNumber, $pageSize); $mailingListService->getMailinglistSubscribers($mailinglistId, $allDemographics = false, $fieldNames = []); $mailingListService->getMailinglistSubscribersPaginated($mailingListId, $pageNumber, $pageSize); $mailingListService->getMailinglistSubscribersWithFilter($mailinglistId, $filterId, $allDemographics = false, $fieldNames = []); $mailingListService->getMailinglistSubscriptionCount($mailinglistId); $mailingListService->updateMailingList($mailinglistId, $mailingListDetails);
新闻通讯列表服务
$apiKey = "YOUR-API-KEY"; $newsletterListService = Factory::create($apiKey)->newsletter(); $newsletterListService->createNewsletter($newsletterData); $newsletterListService->deleteMultipleNewsletters($newsletterIds); $newsletterListService->deleteSingleNewsletter($newsletterId); $newsletterListService->getAllNewsletters(); $newsletterListService->getNewsletterLinks($newsletterId); $newsletterListService->getNewslettersPaginated($pageNumber, $pageSize); $newsletterListService->getNewsletterWebVersionLink($newsletterId); $newsletterListService->updateNewsletter($newsletterId, $newsletterData);
打开服务
$apiKey = "YOUR-API-KEY"; $openService = Factory::create($apiKey)->open(); $openService->getOpensBySendqueueIdPaginated($sendQueueId, $pageNumber, $pageSize);
退订服务
$apiKey = "YOUR-API-KEY"; $optOutService = Factory::create($apiKey)->optOut(); $optOutService->deleteSubscriberFromOptOutAllByEmail($subscriberEmail); $optOutService->deleteSubscribersFromOptOutAll($subscriberIds); $optOutService->deleteSubscribersFromOptOutAllByEmail($subscriberEmails); $optOutService->deleteSubscribersFromOptOutListByEmail($mailinglistId, $subscriberEmails); $optOutService->getOptOutAll(); $optOutService->getOptOutAllByDateInterval(\DateTimeInterface $start, \DateTimeInterface $end); $optOutService->getOptOutAllByDateIntervalPaginated(\DateTimeInterface $start, \DateTimeInterface $end, $pageNumber, $pageSize); $optOutService->getOptOutAllPaginated($pageNumber, $pageSize); $optOutService->getOptOutList($mailinglistId); $optOutService->getOptOutListByMailingListPaginated($mailinglistId, $pageNumber, $pageSize); $optOutService->getOptOutListBySendqueueId($sendQueueId); $optOutService->getOptOutListBySendqueueIdPaginated($sendQueueId, $pageNumber, $pageSize); $optOutService->moveSubscribersToOptOutList($mailinglistId, $optOutListSubscriberItems); $optOutService->optOutAllSubscribers($optOutListSubscriberItems);
发送服务
$apiKey = "YOUR-API-KEY"; $sendingService = Factory::create($apiKey)->sending(); $sendingService->deleteSendingById($sendQueueId); $sendingService->getBounces($sendQueueId, \DateTimeInterface $dateFrom, \DateTimeInterface $dateTo); $sendingService->getClicks($sendQueueId, \DateTimeInterface $dateFrom, \DateTimeInterface $dateTo); $sendingService->getFutureSendings(); $sendingService->getOpens($sendQueueId, \DateTimeInterface $dateFrom, \DateTimeInterface $dateTo); $sendingService->getOptOuts($sendQueueId, \DateTimeInterface $dateFrom, \DateTimeInterface $dateTo); $sendingService->getPaginated($pageNumber, $pageSize); $sendingService->getSendingById($sendQueueId); $sendingService->getSendingsByDateInterval(\DateTimeInterface $start, \DateTimeInterface $end); $sendingService->getSendingsByNewsletterId($newsletterId); $sendingService->getSendingsBySubscriberId($subscriberId, $pageNumber, $pageSize); $sendingService->sendNewsletter($newsletterDetails);
短信服务
$apiKey = "YOUR-API-KEY"; $smsService = Factory::create($apiKey)->sms(); $smsService->createSmsMessage($name, $text, $folderId = null); $smsService->getIncomingSmsMessages($numberRespondedTo, \DateTimeInterface $start, \DateTimeInterface $end); $smsService->getSmsCredits(); $smsService->getSmsMessages(); $smsService->getSmsRecipientsBySendQueueId($sendQueueId); $smsService->send($message, $countryCode, $phoneNumber, $senderName = null, $isLinked = false, \DateTimeInterface $sendDate = null); $smsService->sendSmsMessage($smsMessageId, $mailingListIds, $senderName = null, \DateTimeInterface $sendDate = null, $filterId = null, $campaignId = null):
订阅者服务
$apiKey = "YOUR-API-KEY"; $subscriberService = Factory::create($apiKey)->subscriber(); $subscriberService->createSubscriber($mailingListId, $updateIfExists, $subscriber); $subscriberService->createSubscribers($mailinglistId, $subscribers); $subscriberService->createSubscriberWithDoubleOptIn($mailinglistId, $subscriber); $subscriberService->deleteMultipleSubscribersByEmail($subscriberEmails); $subscriberService->deleteMultipleSubscribersById($subscriberIds); $subscriberService->getAllSubscribers($allDemographics = true, $fieldNames = []); $subscriberService->getAllSubscribersWithFilter($filterId, $allDemographics = true, $fieldNames = []); $subscriberService->getAllSubscribersWithoutSubscription($allDemographics = true, $fieldNames = []); $subscriberService->getRecipientsBySendQueueId($sendQueueId); $subscriberService->getSubscriberDetailsById($subscriberId); $subscriberService->getSubscriberIdByEmail($email); $subscriberService->getSubscriberMailinglists($subscriberId); $subscriberService->getSubscribersByExternalId($externalId); $subscriberService->getSubscribersPaginated($pageNumber, $pageSize); $subscriberService->updateSubscribers($subscribers);
事务服务
$apiKey = "YOUR-API-KEY"; $transactionalService = Factory::create($apiKey)->transactional(); $transactionalService->getTransactionalBounces($projectId, \DateTimeInterface $dateFrom = null, \DateTimeInterface $dateTo = null); $transactionalService->getTransactionalClicks($projectId, \DateTimeInterface $dateFrom = null, \DateTimeInterface $dateTo = null); $transactionalService->getTransactionalOpens($projectId, \DateTimeInterface $dateFrom = null, \DateTimeInterface $dateTo = null); $transactionalService->getTransactionalProjects(); $transactionalService->getTransactionResult($transactionId, $includeDemographicData); $transactionalService->sendTransactionalEmail($projectId, TransactionalEmail $transactionalEmail, \DateTimeInterface $sendDate = null, $allowInactiveProjects = true);
导入服务
$apiKey = "YOUR-API-KEY"; $importService = Factory::create($apiKey)->import(); $importService->createImportByCsv($mailingListId, CsvImport $csvImport); $importService->createImportByXml($mailingListId, $xmlData, $demographicNameMapping = false); $importService->getImportIgnoredDuplicates($importId); $importService->getImportInvalidEmails($importId); $importService->getImportRecipientsOnOptOutAll($importId); $importService->getImportRecipientsOnOptOutList($importId); $importService->getImportResults($importId); $importService->getImportStatus($importId);
队列方法
为了更容易地使用 队列方法,您可以使用 QueueMethodHelper 来轮询并检索任何队列方法的数据。
只需将队列方法的响应传递给 QueueMethodHelper::fromJson()
方法,您就会得到一个实例。
以下是如何使用此方法的示例
$factory = \Guilty\Apsis\Factory::create("YOUR-API-KEY"); $newsletterService = $factory->newsletter(); // 'deleteMultipleNewsletters' is a queued method. $response = $newsletterService->deleteMultipleNewsletters([1, 2, 3, 4]); // Pass the QueuedMethodHelper the response from a queued method. $poll = QueuedMethodHelper::fromJson($response, $factory->getClient()); while (true) { echo "Polling: {$poll->getPollUrl()}"; try { // Poll for latest status $poll->poll(); // Check if the data is ready now. if ($poll->isDataReady()) { break; // Jump out of loop if it is. } // Wait 1 second sleep(1); } catch (Exception $e) { die("Something unexpected happened..."); } } // Fetch the data $queuedMethodDataResult = $poll->retrieveData();
实现的服务
这些服务目前已实现,其余正在开发中,完成后将进行检查。
- 账户
- 退订
- 点击
- 事件
- 过滤器
- 文件夹
- 导入
- 邮件列表
- 新闻通讯
- 打开
- 退订
- 发送
- 短信
- 订阅者
- 事务性(注意:sendTransactionalEmail() 可能不会正常工作)
安全
如果您发现任何与安全相关的问题,请通过 tech@guilty.no 发送电子邮件,而不是使用问题跟踪器。
许可协议
MIT 许可协议(MIT)。有关更多信息,请参阅 许可文件。
由 Guilty AS 提供
APSIS 标志和商标属于 APSIS International AB