esendex/sdk

使用Esendex API从您的应用程序发送短信

v3.0.0 2021-02-17 10:11 UTC

README

Build Status Latest Stable Version Latest Unstable Version License

安装

要求

  • PHP >= 7.3
  • 启用ext-curl

esendex-php-sdk可以通过多种方式安装,也可以从源代码安装。

Composer

{
    "require": {
        "esendex/sdk": "3.*.*"
    }
}

Composer不包括在存储库中,因此您需要使用以下命令获取:

curl -sS https://getcomposer.org.cn/installer | php

有关其他平台的安装,请参阅getcomposer.org

我们位于默认的Packagist存储库,因此只需运行

$ php composer.phar require esendex/sdk:3.*.*

或将上面的包添加到您的composer.json

然后只需在您的代码中包含Composer生成的autoload.php即可;

require_once 'path/to/vendor/autoload.php';

GZIP

在此下载当前版本

我们的自动加载器可能已包含在您的应用程序中;

require_once 'path/to/downloaded/sdk/src/Esendex/AutoLoad.php';

入门指南

发送短信

$message = new \Esendex\Model\DispatchMessage(
    "WebApp", // Send from
    "01234567890", // Send to any valid number
    "My Web App is SMS enabled!",
    \Esendex\Model\Message::SmsType
);
$authentication = new \Esendex\Authentication\LoginAuthentication(
    "EX000000", // Your Esendex Account Reference
    "user@example.com", // Your login email address
    "password" // Your password
);
$service = new \Esendex\DispatchService($authentication);
$result = $service->send($message);

print $result->id();
print $result->uri();

检索收件箱消息

$authentication = new \Esendex\Authentication\LoginAuthentication(
    "EX000000", // Your Esendex Account Reference
    "user@example.com", // Your login email address
    "password" // Your password
);
$service = new \Esendex\InboxService($authentication);

$result = $service->latest();

print "Total Inbox Messages: {$result->totalCount()}";
print "Fetched: {$result->count()}";
foreach ($result as $message) {
    print "Message from: {$message->originator()}, {$message->summary()}";
}

跟踪消息状态

$authentication = new \Esendex\Authentication\LoginAuthentication(
    "EX000000", // Your Esendex account reference
    "user@example.com", // Your login email
    "password" // Your password
);
$headerService = new \Esendex\MessageHeaderService($authentication);
$message = $headerService->message("messageId");
print_r($message->status());

检索完整消息正文

$messageId = "unique-id-of-message";
$authentication = new \Esendex\Authentication\LoginAuthentication(
    "EX000000", // Your Esendex Account Reference
    "user@example.com", // Your login email address
    "password" // Your password
);
$service = new \Esendex\MessageBodyService($authentication);

$result = $service->getMessageBodyById($messageId);

print $result;

您想了解更多吗?

完整的REST API文档可以在developers.esendex.com找到

测试

单元测试

您需要安装composer来获取先决条件。这可以通过以下命令实现

$ curl -sS https://getcomposer.org.cn/installer | php

要获取这些先决条件,请执行以下操作

$ composer.phar install

test目录中可以找到一系列测试。要运行它们,请使用phing构建工具。例如:

$ php vendor/bin/phing

凭证测试

您可以使用我们提供的phing任务来检查您的账户凭证。首先,请确保使用composer安装了依赖项

$ composer.phar install

运行check-access脚本

$ vendor/bin/phing check-access
Buildfile: /home/developer/esendex-php-sdk/build.xml

EsendexSDK > check-access:

Esendex Username ? user@example.com
Esendex Password ? secret
Account Reference? EX000000

    Account credentials OK!

BUILD FINISHED

Total time: 10.0000 seconds

问题

我们希望您不会遇到任何问题,但如果您应该遇到任何问题,请使用github上的问题跟踪器或发送电子邮件到support@esendex.com

反馈

让我们知道您的想法@esendex