micovi/laravel-sendy

PHP Laravel 5+ 的 Sendy API 服务提供者

dev-master 2019-03-24 13:01 UTC

This package is auto-updated.

Last update: 2024-09-15 18:57:15 UTC


README

Github Packagist Packagist downloads

包描述:Laravel 简单集成 Sendy API,用于订阅/退订用户到列表。

安装

通过 composer 安装

composer require micovi/laravel-sendy

注册服务提供者

注意!如果您使用 laravel >= 5.5 并启用了包自动发现功能,则此步骤是可选的。

将服务提供者添加到 config/app.php 文件的 providers 部分

Micovi\LaravelSendy\ServiceProvider::class,

注册门面

config/app.php 文件的 aliases 部分注册包门面

'LaravelSendy' => Micovi\LaravelSendy\Facades\LaravelSendy::class,

添加环境变量

SENDY_API_KEY=your-api-key
SENDY_URL=your-sendy-url
SENDY_LIST_ID=your-list-id

列表 ID 可在“查看所有列表”部分 ID 列中找到,已加密和散列。

自定义或扩展

发布配置文件

您可以将配置文件发布出来进行编辑,以防您不想使用 ENV。文件将发布在 /config/larave-sendy.php

php artisan vendor:publish --provider="Micovi\LaravelSendy\ServiceProvider" --tag="config"

发布翻译

您可以将翻译发布出来进行编辑。文件将发布在 /resources/lang/vendor/laravel-sendy

注意:您可以通过在 /resources/lang/vendor/laravel-sendy/{lang}/messages.php 中创建一个新文件来扩展翻译,格式与 en 语言文件相同。

使用示例

在任意使用之前,请添加命名空间到文件。

use Micovi\LaravelSendy\LaravelSendy;

订阅

将新电子邮件订阅到列表。这可以用来编辑已订阅的用户。(例如更改姓名)

// initialize LaravelSendy
$sendy = new LaravelSendy();

// Simple email subscribe
$subscribe = $sendy->subscribe('email@example.com');

// Add subscriber with email and name
$subscribe = $sendy->subscribe('email@example.com', 'John Doe');

// Full subscribe method
$subscribe = $sendy->subscribe($email, $name = null, $listId = null, $json = false, $customFields = []);

// Response example
$subscribe = [
  "success" => true
  "message" => "You have been subscribed."
]

退订示例

将电子邮件标记为已从列表中退订。

// initialize LaravelSendy
$sendy = new LaravelSendy();

// Simple unsubscribe
$unsubscribe = $sendy->unsubscribe('email@example.com');

// Full unsubscribe method
$unsubscribe = $sendy->unsubscribe($email, $listId = null, $json = false);

// Response example
$unsubscribe = [
  "success" => true
  "message" => "You have been unsubscribed."
]

删除示例

从列表中删除电子邮件。该操作是确定的。

// initialize LaravelSendy
$sendy = new LaravelSendy();

// Simple delete
$delete = $sendy->delete('email@example.com');

// Full unsubscribe method
$delete = $sendy->delete($email, $listId = null, $json = false);

// Response example
$delete = [
  "success" => true
  "message" => "You have been deleted from the list."
]

安全性

如果您发现任何安全相关的问题,请通过电子邮件联系,而不是使用问题跟踪器。

贡献

如果您想为您的语言贡献翻译,可以将从 enresources/lang/en/messages.php 复制的语言文件提交为 PR 请求。