silinternational / email-service-php-client
PHP 客户端,用于与我们的 Email Service API 交互:https://github.com/silinternational/email-service
2.4.2
2024-02-28 19:11 UTC
Requires
- php: >=7.0
- guzzlehttp/guzzle-services: ^1.1
- mlocati/ip-lib: ^1.14
- roave/security-advisories: dev-master
Requires (Dev)
- ext-json: *
- behat/behat: ^3.3
- webmozart/assert: ^1.10
README
PHP 客户端,用于与我们的 Email Service API 交互。
此客户端基于 Guzzle PHP HTTP 客户端构建。Guzzle 提供了一种简单的方法来创建 API 客户端,通过使用类似于 Swagger 的格式描述 API,无需自己实现每个方法。因此,支持更多 API 相对简单。
安装
使用 Composer 安装很简单。
$ composer require silinternational/email-service-php-client
用法
示例
<?php use Sil\EmailService\Client\EmailServiceClient; $emailServiceClient = new EmailServiceClient( 'https://api.example.com/', // The base URI for the API. 'DummyAccessToken', // Your HTTP header authorization bearer token. [ 'http_client_options' => [ 'timeout' => 10, // An (optional) custom HTTP timeout, in seconds. ], ] ); $email = $emailServiceClient->email([ "to_address" => "test@domain.com", "cc_address" => "other@domain.com", // optional "bcc_address" => "bcc@domain.com", // optional "subject" => "Test Subject", "text_body" => "this is text", // either text_body or html_body is required, but both can be provided "html_body" => "<b>this is html</b>", ]);
要发送延迟一定时间的邮件:`
$email = $emailServiceClient->email([ "to_address" => "test@domain.com", "subject" => "Test Subject", "html_body" => "<b>this is html</b>", "delay_seconds" => "3600", ]);
或者要安排发送邮件,请使用 send_after
和 Unix 时间戳
$email = $emailServiceClient->email([ "to_address" => "test@domain.com", "subject" => "Test Subject", "html_body" => "<b>this is html</b>", "send_after" => "1556825944", ]);
测试
要运行此单元测试,请运行 make test
。
Guzzle 服务客户端说明
- 使用 Guzzle Web Services 开发 API 客户端的教程
http://www.phillipshipley.com/2015/04/creating-a-php-nexmo-api-client-using-guzzle-web-service-client-part-1/ - Jeremy Lindblom 的演讲
https://speakerdeck.com/jeremeamia/building-web-service-clients-with-guzzle-1 - Jeremy Lindblom 的示例
https://github.com/jeremeamia/sunshinephp-guzzle-examples - 源代码注释中的参数文档
https://github.com/guzzle/guzzle-services/blob/master/src/Parameter.php - Guzzle 3 服务描述文档(至少大部分仍然相关)
https://guzzle3.readthedocs.org/webservice-client/guzzle-service-descriptions.html