ahmadawais / sendy-php-api
Sendy PHP API 包装器:完整的 API 接口。
6.0.0
2020-04-27 18:53 UTC
Requires
- rmccue/requests: ^1.7
README
🚀 Sendy PHP API 包装器:完整的 API 接口。
📨 SENDY API
使用这个 Sendy PHP API 包装器
你可以执行以下操作
入门指南
入门很简单。下面是如何操作的。你也可以查看 example.php 文件。显然,你必须将包装器下载到你的当前设置中。有几种方法可以做到这一点。
#1 手动安装
使用 Git 克隆此仓库,并在你的项目中包含 ./src/Sendy.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(否则请删除命名空间)。
连接
(关注) 以获取 #OneDevMinute 每日热门提示和恶作剧
(订阅) 以获取技术讲座和 #OneDevMinute 视频
赞助商
我(Ahmad Awais)和我的不可思议的妻子(Maedah Batool)是两个爱上开源,然后爱上彼此的工程师。您可以在这里了解更多关于我的信息。如果您或您的公司使用了我的任何项目或喜欢我所做的事情,请考虑支持我。我致力于长期发展。一个开源开发者倡导者。