cicerbro / sendy-php-api
Sendy PHP API 包装器:完整的 API 接口。
6.0.3
2024-03-23 11:06 UTC
Requires
- guzzlehttp/guzzle: ^7.0
This package is auto-updated.
Last update: 2024-09-08 15:25:21 UTC
README
🚀 Sendy PHP API 包装器:完整的 API 接口。
📨 SENDY API
由原作者 fork:cicerbro/Sendy-PHP-API
使用此 Sendy PHP API 包装器
您可以执行以下操作
入门
入门非常简单。以下是操作步骤。您还可以查看 example.php 文件。显然,您需要将包装器下载到您的当前环境中。有几种方法可以做到这一点。
#1 手动安装
使用 Git 克隆此仓库,并在您的项目中包含 ./src/API.php
。
#2 COMPOSER 安装
COMPOSER 安装是首选方法。
composer require ahmadawais/sendy-php-api
步骤 0. 需求包装器
// New way using PSR4 Standard autoloader. Recommended require_once . '/vendor/autoload.php'; // Old way of requiring all files manually. Not recommended. require_once( 'API.php' );
步骤 1. 配置它
// 2. Configuration. $config = [ 'sendyUrl' => 'https://send_installation_url.com', // Your Sendy installation URL (without trailing slash). 'apiKey' => 'XXXXXXXXXXXXXXXX', // Your API key. Available in Sendy Settings. 'listId' => 'XXXXXXXXXXXXXXXX', ];
步骤 2. 初始化
use AhmadAwais\Sendy\API as Sendy; $sendy = new Sendy( $config );
API 密钥方法
- 方法:
subscribe()
。 - 方法:
unsubscribe()
。 - 方法:
subStatus()
。 - 方法:
delete()
。 - 方法:
subCount()
。 - 方法:
campaign()
。
方法 #1:订阅
// Method #1: Subscribe. $responseArray = $sendy->subscribe( [ 'email' => 'your@email.com', // This is the only field required by sendy. 'name' => 'Name', // User name (optional). 'custom' => 'Field Value', // You can custom fields as well (optional). 'country' => 'US', // User 2 letter country code (optional). 'ipaddress' => 'XX.XX.XX.XXX', // User IP address (optional). 'referrer' => 'https://AhmadAwais.com/', // URL where the user signed up from (optional). 'gdpr' => true, // GDPR compliant? Set this to "true" (optional). ] );
方法 #2:取消订阅
$responseArray = $sendy->unsubscribe( 'your@email.com' );
方法 #3:订阅者状态
$responseArray = $sendy->subStatus( 'your@email.com' );
方法 #4:删除订阅者
$responseArray = $sendy->delete( 'your@email.com' );
方法 #5:列表中的订阅者数量
$responseArray = $sendy->subCount();
方法 #6:活动 — 草稿和/或发送
// Method #6: Campaign — Draft And/Or Send as well. $responseArray = $sendy->campaign( array( 'from_name' => 'Your Name', 'from_email' => 'your@email.com', 'reply_to' => 'your@email.com', 'title' => 'Title', // the title of your campaign. 'subject' => 'Your Subject', 'plain_text' => 'An Amazing campaign', // Optional. 'html_text' => '<h1>Amazing campaign</h1>', 'brand_id' => 1, // Required only if you are creating a 'Draft' campaign. That is `send_campaign` set to 0. 'send_campaign' => 0, // SET: Draft = 0 and Send = 1 for the campaign. // Required only if you set send_campaign to 1 and no `segment_ids` are passed in.. List IDs should be single or comma-separated. 'list_ids' => 'XXXXXXXX, XXXXXXXX', // Required only if you set send_campaign to 1 and no `list_ids` are passed in. Segment IDs should be single or comma-separated. 'segment_ids' => '1', // Lists to exclude. List IDs should be single or comma-separated. (optional). 'exclude_list_ids' => '', // Segments to exclude. Segment IDs should be single or comma-separated. (optional). 'exclude_segments_ids' => '', 'query_string' => 'XXXXXXXX', // Eg. Google Analytics tags. ) );
方法 #7:设置列表 ID
// Method #7: Change the `XXXXXXX` you are referring to at any point. $sendy->setListId( 'XXXXXXX' );
方法 #8:获取列表 ID
// Method #7: Get the `XXXXXXX` you are referring to at any point. $sendy->getListId();
响应
此 PHP 包装器的响应是自定义构建的。目前,它总是返回一个 PHP 数组。此数组包含您的操作 status
和响应中的适当 message
。
status
是true
或false
。message
基于正在执行的操作类型
// E.g. SUCCESS response. [ 'status' => true, 'message' => 'Already Subscribed' ]; // E.g. FAIL response. [ 'status' => false, 'message' => 'Some fields are missing.' ];
变更日志
关键字: 📦 NEW
、👌 IMPROVE
、🐛 FIX
、📖 DOC
、🚀 RELEASE
和 ✅ TEST
我使用 Emoji-log,您应该尝试一下,简化您的 git 提交。
许可 & 行为
- MIT © Ahmad Awais
- 行为准则
- 感谢 Jacob Bennett 对该库的初始工作。
- 至少需要 PHP 5.3.0(否则请删除命名空间)。
连接
(follow) 获取 #OneDevMinute 每日热提示 & 调侃
(subscribe) 订阅技术讲座 & #OneDevMinute 视频
赞助商
我(Ahmad Awais)和我令人难以置信的妻子(Maedah Batool)是两位对开源软件和彼此都深深着迷的工程师。您可以在这里了解更多关于我的信息。如果您或您的公司使用了我的任何项目或者喜欢我所做的事情,那么请考虑支持我。我致力于长期发展。一名开源开发者倡导者。