承接 unisender/unigo-php 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

unisender/unigo-php

Composer 安装命令:

composer require unisender/unigo-php

包简介

The UniGo SDK package what provide methods to interact with Unisender Go API.

README 文档

README

Latest Stable Version Total Downloads

This SDK contains methods for easily interacting with the Unisender Go API: https://godocs.unisender.ru/web-api-ref#web-api

Installation

Use Composer to install the package:

composer require unisender/unigo-php

Usage

Send email:

  $client = new Unisender\UniGoClient('YOUR-API-KEY', 'YOUR-HOST-NAME');
  // Example for GO1 server.
  $client = new Unisender\UniGoClient('YOUR-API-KEY', 'go1.unisender.ru');

  $recipients = [
    [
      "email" => 'john@example.com',
      "substitutions" => [
        "to_name" => "John Smith"
      ],
    ],
    [
      "email" => 'liza@example.com',
      "substitutions" => [
        "to_name" => "Liza Frank"
      ],
    ]
  ];

  $body = [
    "html" => "<b>Test mail, {{to_name}}</b>",
    "plaintext" => "Hello, {{to_name}}",
    "amp" => "<!doctype html><html amp4email><head> <meta charset=\"utf-8\"><script async src=\"https://cdn.ampproject.org/v0.js\"></script> <style amp4email-boilerplate>body[visibility:hidden]</style></head><body> Hello, AMP4EMAIL world.</body></html>"
  ];

  // You can use email object can be used to prepare the message array.
  // But the email send method accepts an array, that can be composed without
  // SDK utils.
  $mail = new Unisender\Model\Email($recipients, $body);
  $mail->setFromEmail('user@example.com');
  $mail->setSubject('test letter');
  $response = $client->emails()->send($mail->toArray());

See API documentation for more details.

See template engine documentation for substitutions details.

Send subscribe email:

  $client = new Unisender\UniGoClient('YOUR-API-KEY', 'YOUR-HOST-NAME');

  $params = [
    "from_email" => "john@example.com",
    "from_name" => "John Smith",
    "to_email" => "user@example.com"
  ];
  $response = $client->emails()->subscribe($params);

API documentation.

Set template:

  $client = new Unisender\UniGoClient('YOUR-API-KEY', 'YOUR-HOST-NAME');

  $params = [
    "template" => [
      "name" => "First template",
      "body" => [
        "html" => "<b>Hello, {{to_name}}</b>",
        "plaintext" => "Hello, {{to_name}}",
        "amp" => "<!doctype html><html amp4email><head> <meta charset=\"utf-8\"><script async src=\"https://cdn.ampproject.org/v0.js\"></script> <style amp4email-boilerplate>body[visibility:hidden]</style></head><body> Hello, AMP4EMAIL world.</body></html>"
      ],
      "subject" => "Test template mail",
      "from_email" => "test@example.com",
      "from_name" => "Example From",
    ]
  ];
  $response = $client->templates()->set($params);

API documentation.

Get template:

  $client = new Unisender\UniGoClient('YOUR-API-KEY', 'YOUR-HOST-NAME');
  $response = $client->templates()->get('YOUR-TEMPLATE-ID');

API documentation.

Get templates list:

  $client = new Unisender\UniGoClient('YOUR-API-KEY', 'YOUR-HOST-NAME');

  $params = [
    "limit" => 50,
    "offset" => 0
  ];
  $response = $client->templates()->list($params);

API documentation.

Delete template:

  $client = new Unisender\UniGoClient('YOUR-API-KEY', 'YOUR-HOST-NAME');
  $response = $client->templates()->delete('YOUR-TEMPLATE-ID');

API documentation.

Set webhook:

  $client = new Unisender\UniGoClient('YOUR-API-KEY', 'YOUR-HOST-NAME');

  $params = [
    "url" => "https://yourhost.example.com/unigo-webhook",
    "events" => [
      "email_status" => [
        "delivered",
        "opened",
        "clicked",
        "unsubscribed",
        "soft_bounced",
        "hard_bounced",
        "spam"
      ]
    ]
  ];
  $response = $client->webhooks()->set($params);

API documentation.

The specified URL will receive a request from Unisender Go. See more information about request data in API documentation.

This is how you can check the message integrity in your callback handler:


$client = new Unisender\UniGoClient('YOUR-API-KEY', 'YOUR-HOST-NAME');
// $body contains a callback request body.
if ($client->webhooks()->verify($body) === TRUE) {
  // The webhook is confirmed, result can be processed.
}

Get webhook:

  $client = new Unisender\UniGoClient('YOUR-API-KEY', 'YOUR-HOST-NAME');
  $response = $client->webhooks()->get('YOUR-WEBHOOK-URL');

API documentation.

Get list all or some webhooks:

  $client = new Unisender\UniGoClient('YOUR-API-KEY', 'YOUR-HOST-NAME');
  $response = $client->webhooks()->list();

API documentation.

Delete webhook:

  $client = new Unisender\UniGoClient('YOUR-API-KEY', 'YOUR-HOST-NAME');
  $response = $client->webhooks()->delete('YOUR-WEBHOOK-URL');

API documentation.

Additional information

Generic API method

For API methods, that are not implemented in SDK yet, you can use UniGoClient::httpRequest(). Here is an example for "set" suppression method:

  $client = new Unisender\UniGoClient('YOUR-API-KEY', 'YOUR-HOST-NAME');
  $response = $client->httpRequest('suppression/set.json', ["email" => "user@example.com", "cause" => "unsubscribed"]);

Set Guzzle HTTP client config

Unisender Go client accepts an array with Guzzle configuration as a third argument. When creating a client, you can pass some additional options (i.e. connect_timeout) to apply this to all requests.

Here is a more advanced example of adding a history handler to save outcoming requests and responses.

  $container = [];
  $history = Middleware::history($container);
  $handlerStack = HandlerStack::create();
  $handlerStack->push($history);
  $config = ['handler' => $handlerStack];
  $client = new Unisender\UniGoClient('YOUR-API-KEY', 'YOUR-HOST-NAME', $config);

See Guzzle documentation.

unisender/unigo-php 适用场景与选型建议

unisender/unigo-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 24.22k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 11 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 unisender/unigo-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 unisender/unigo-php 我们能提供哪些服务?
定制开发 / 二次开发

基于 unisender/unigo-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 24.22k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-11-23