trycourier/courier

Courier API 的 PHP 实现,作为 SDK,支持 Laravel 5.8+


README

Courier PHP SDK 支持

  • 发送 API
  • 消息 API
  • 配置文件 API
  • 偏好 API
  • 事件 API
  • 品牌 API
  • 列表 API
  • 通知 API
  • 自动化 API
  • 批量 API
  • 受众 API
  • 令牌管理 API
  • 审计事件 API
  • 租户 API
  • 用户 API

官方 Courier API 文档

有关请求和响应负载以及属性的完整描述,请参阅 官方 Courier API 文档

要求

  • PHP 7.2+
  • ext-json

安装

此库使用 HTTPlug 作为 HTTP 客户端。HTTPlug 是一种抽象,允许此库支持不同的 HTTP 客户端。因此,您需要提供您首选的 HTTP 库的客户端和/或适配器。您可以在 Packagist 中找到所有可用的适配器。本文档假定您使用 Guzzle 客户端,但您可以用任何您喜欢的客户端替换它。

安装 courier-php 的推荐方式是通过 Composer

composer require trycourier/courier guzzlehttp/guzzle

配置

使用您的授权令牌或用户名和密码实例化 Courier 客户端类。仅提供授权令牌将生成一个 "Bearer" 授权头,而提供用户名和密码将生成一个 "Basic"(base64 编码)授权头

$client = new CourierClient("base-url", "authorization-token", "username", "password");

选项

许多方法允许向 Courier 端点传递可选数据。此数据应为一个键/值对的关联数组。支持的选项取决于正在调用的端点。有关更多信息,请参阅官方 Courier 文档。

$profile = [
	"firstname" => "Johnny",
	"lastname" => "Appleseed",
	"email" => "courier.pigeon@mail.com"
];

方法

有关请求和响应负载以及属性的完整描述,请参阅 官方 Courier API 文档

发送 API

  • sendNotification(string $event, string $recipient, string $brand = NULL, object $profile = NULL, object $data = NULL, object $preferences = NULL, object $override = NULL, string $idempotency_key = NULL): object (发送 API)
  • sendEnhancedNotification(object $message, string $idempotency_key = NULL): object (发送 API)
  • sendNotificationToList(string $event, string $list = NULL, string $pattern = NULL, string $brand = NULL, object $data = NULL, object $override = NULL, string $idempotency_key = NULL): object (发送列表 API)

消息 API

  • cancelMessage(string $message_id): object [?]
  • getMessages(string $cursor = NULL, string $event = NULL, string $list = NULL, string $message_id = NULL, string $notification = NULL, string $recipient = NULL): object [?]
  • getMessage(string $message_id): object [?]
  • getMessageHistory(string $message_id, string $type = NULL): object [?]

列表 API

  • getLists(string $cursor = NULL, string $pattern = NULL): object [?]
  • getList(string $list_id): object [?]
  • putList(string $list_id, string $name): object [?]
  • deleteList(string $list_id): object [?]
  • restoreList(string $list_id): object [?]
  • getListSubscriptions(string $list_id, string $cursor = NULL): object [?]
  • subscribeMultipleRecipientsToList(string $list_id, array $recipients): object [?]
  • subscribeRecipientToList(string $list_id, string $recipient_id): object [?]
  • deleteListSubscription(string $list_id, string $recipient_id): object [?]

品牌 API

  • getBrands(string $cursor = NULL): object [?]
  • createBrand(string $id = NULL, string $name, object $settings, object $snippets = NULL, string $idempotency_key = NULL): object [?]
  • getBrand(string $brand_id): object [?]
  • replaceBrand(string $brand_id, string $name, object $settings, object $snippets = NULL): object [?]
  • deleteBrand(string $brand_id): object [?]

事件 API

  • getEvents(): object [?]
  • getEvent(string $event_id): object [?]
  • putEvent(string $event_id, string $id, string $type): object [?]

配置文件 API

  • getProfile(string $recipient_id): object [?]
  • upsertProfile(string $recipient_id, object $profile): object [?]
  • patchProfile(string $recipient_id, array $patch): object [?]
  • replaceProfile(string $recipient_id, object $profile): object [?]
  • getProfileLists(string $recipient_id, string $cursor = NULL): object [?]

偏好 API

  • getPreferences(string $recipient_id, string $preferred_channel): object [?]
  • updatePreferences(string $recipient_id, string $preferred_channel): object [?]

通知 API

  • listNotifications(string $cursor = NULL): object
  • getNotificationContent(string $id): object
  • getNotificationDraftContent(string $id): object
  • postNotificationVariations(string $id, array $blocks, array $channels = NULL): object
  • postNotificationDraftVariations(string $id, array $blocks, array $channels = NULL): object
  • getNotificationSubmissionChecks(string $id, string $submissionId): object
  • putNotificationSubmissionChecks(string $id, string $submissionId, array $checks): object
  • deleteNotificationSubmission(string $id, string $submissionId): object

自动化 API

  • invokeAutomation(object $automation, string $brand = NULL, string $template = NULL, string $recipient = NULL, object $data = NULL, object $profile = NULL): object [?]
  • 从模板调用自动化(string $templateId, string $brand = NULL, object $data = NULL, object $profile = NULL, string $recipient = NULL, string $template = NULL): object [?]
  • 获取自动化运行状态(string $runId): object

批量 API

受众 API

令牌管理 API

审计事件 API

账户API(仅在v1.12.0版本中)

租户API(v2.0.0+版本)

用户 API

错误

所有不成功的(非2xx)响应都会抛出 CourierRequestException 异常。可以通过 getResponse() 方法获取完整的响应对象。