sut/pmapi

此包的最新版本(1.0.0)没有提供许可信息。

Sign-Up.to 授权营销 API 的 PHP 客户端库。

1.0.0 2016-02-01 10:09 UTC

This package is not auto-updated.

Last update: 2024-09-23 06:30:25 UTC


README

PMAPI logo

PMAPIClient

PHP 客户端库,用于 Sign-Up.to 的授权营销 API (PMAPI)

Composer 安装

composer require sut/pmapi

示例

有关 Sign-Up.to 授权营销 API 的完整文档,请参阅 开发网站

示例 1:添加新订阅者和发送确认邮件

以下示例演示了如何使用订阅者辅助类创建新订阅者并发送确认邮件。

require_once __DIR__ . '/vendor/autoload.php';

define('CID', 1); // Company ID
define('UID', 1); // User ID
define('HASH', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); // API access hash

$request = new SuT\PMAPI\Client\Core\Request(new SuT\PMAPI\Client\Core\AuthHash(UID, CID, HASH));

// Define the id of the list we want to add the subscriber to
$listID = 12345;

// Use the Subscriber helper class to create a new subscriber
$subscriber            = new SuT\PMAPI\Client\Helpers\Subscriber($request);
$subscriber->firstname = "John";
$subscriber->lastname  = "Smith";
$subscriber->email     = "example@example.com";
$subscriber->confirmed = false;
$subscriber->list_id   = $listID;
$subscriber->save();
$subscriber->sendOptInEmail($listID);
// Or you can pass a confirmation URL
$subscriber->sendOptInEmail($listID, 'https://your-domain.com/thanks-for-signing-up');

示例 2:返回最新列表

以下示例演示了如何使用请求类获取最新列表。

require_once __DIR__ . '/vendor/autoload.php';

// Define your authentication details, if you don't have any then follow the instructions here: 
// https://dev.sign-up.to/documentation/reference/latest/guides/get-started/
define('CID', 1); // Company ID
define('UID', 1); // User ID
define('HASH', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); // API access hash

// Create a request object based on the hash authentication method.
// Note: authentication will not occur until an API call is made using the PMAPIRequest object.
$request = new SuT\PMAPI\Client\Core\Request(new SuT\PMAPI\Client\Core\AuthHash(UID, CID,HASH));

// Get the most recently created list.
$args = array(
    'sort'    => 'cdate',
    'reverse' => true,
    'count'   => 1,
);

$response = $request->list->get($args);

if ($response->isError)
{
    die("Failed to obtain a collection of lists: {$response->error}\n");
}

$listID           = $response->data[0]['id'];
$listName         = $response->data[0]['name'];
$createdTimestamp = $response->data[0]['cdate']; // All dates are returned as timestamps
$createdDate      = date('r', $createdTimestamp); 

echo "List '$listName' has id '$listID' and was created on $createdDate\n";

示例 3:令牌认证

以下示例演示了令牌认证。

require_once __DIR__ . '/vendor/autoload.php';

// Define your authentication details, if you don't have any then follow the instructions here: 
// https://dev.sign-up.to/documentation/reference/latest/guides/get-started/
define("USERNAME", "xxxxxxxxxxx"); // Your Sign-Up.to username
define("PASSWORD", "xxxxxxxxxxx"); // Your Sign-Up.to password

// Create a token
$request = new SuT\PMAPI\Client\Core\Request(new SuT\PMAPI\Client\Core\AuthNone());
$response = $request->token->post(array('username' => USERNAME,
                                        'password' => PASSWORD));

if ($response->isError)
{
    die ("ERROR: Authentication failed: {$response->error}\n");
}

// The authentication token
$token = $response->data['token'];

// The token expiry 
$expiry = $response->data['expiry'];

// You can then use this token to make requests
$request = new SuT\PMAPI\Client\Core\Request(new SuT\PMAPI\Client\Core\AuthToken($token));

// Get the most recently created list.
$args = array(
    'sort'    => 'cdate',
    'reverse' => true,
    'count'   => 1,
);

$response = $request->list->get($args);

if ($response->isError)
{
    die("Failed to obtain a collection of lists: {$response->error}\n");
}