trycourier / courier
Courier API 的 PHP 实现,作为 SDK,支持 Laravel 5.8+
v2.0.0
2023-08-09 18:42 UTC
Requires
- php: >=7.4
- ext-json: *
- php-http/discovery: ^1.0
- php-http/httplug: ^2.0
- php-http/message-factory: ^1.0
- psr/http-client-implementation: ^1.0
- psr/http-message: ^1.0
Requires (Dev)
- guzzlehttp/psr7: ^2.1
- illuminate/support: >=6.0
- php-coveralls/php-coveralls: ^2.1
- php-http/message: ^1.0
- php-http/mock-client: ^1.0
- phpunit/phpunit: ^8.1
- symfony/var-dumper: ^4.2
- vimeo/psalm: ^3.3
- dev-main
- v2.0.0
- v1.12.0
- v1.10.0
- v1.9.0
- v1.8.0
- v1.7.0
- v1.6.0
- v1.5.0
- v1.4.0
- v1.3.0
- v1.2.1
- v1.2.0
- v1.1.0
- v1.0.0
- dev-C-10109/php-sdk-accounts-tenants
- dev-user-account-api
- dev-chris/c-9805-update-php-sdk
- dev-i18n1.1
- dev-C-6481
- dev-drew/c-6187-add-support-for-token-management-to-php
- dev-v2-support
- dev-C-4964
- dev-drew/c-3969-php-sdk-automations-api
- dev-more-endpoints
- dev-C-3747-notifications-api
- dev-add-template
This package is auto-updated.
Last update: 2024-09-09 21:13:40 UTC
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
创建批量任务(object $message): object
(创建批量任务)导入批量任务用户(string $jobId, array $users): object
(导入批量任务用户)运行批量任务(string $jobId): object
(运行批量任务)获取批量任务(string $jobId): object
(获取批量任务)获取批量任务用户(string $jobId): object
(获取批量任务用户)
受众 API
添加受众(object $audience): object
(创建受众)获取受众(string $audienceId): object
(获取受众)获取受众成员列表(string $audienceId): object
(获取受众成员列表)获取所有受众列表():object
(获取所有受众列表)
令牌管理 API
添加用户令牌(string $user_id, array $tokens): object
(添加用户令牌)添加单个用户令牌(string $user_id, array $token): object
(添加单个用户令牌)修改用户令牌(string $user_id, string $token, array $patch): object
(修改用户令牌)获取用户令牌(string $user_id, string $token): object
(获取用户令牌)获取所有用户令牌(string $user_id): object
(获取所有用户令牌)
审计事件 API
获取审计事件(string $audit_event_id): object
(获取审计事件)列出审计事件列表(string $cursor = NULL): object
(列出审计事件列表)
账户API(仅在v1.12.0版本中)
获取账户信息():object
(获取账户)列出账户信息列表(string $cursor = NULL): object
(列出账户)添加或替换账户(string $account_id, object $account): object
(添加或替换账户)删除账户(string $account_id): object
(删除账户)
租户API(v2.0.0+版本)
获取租户信息():object
(获取租户)列出租户信息列表(string $cursor = NULL): object
(列出租户)添加或替换租户(string $tenant_id, object $tenant): object
(添加或替换租户)删除租户(string $tenant_id): object
(删除租户)
用户 API
添加用户信息():object
(添加用户)添加用户租户关联信息():object
(添加用户租户关联信息)
错误
所有不成功的(非2xx)响应都会抛出 CourierRequestException
异常。可以通过 getResponse()
方法获取完整的响应对象。