fortytwo/php-sdk-advanced-messaging-platform

我们的高级消息平台可以智能地根据您的交付偏好和受众的独特知识通过短信或即时消息路由流量,或者可以根据内容、成本和投递成功率等因素确定最佳消息传递方式。

1.0.4 2017-03-27 15:25 UTC

README

此PHP SDK允许您通过Fortytwo电信的高级消息平台(AMP)服务发送短信或即时消息(例如VIBER)。

AMP允许您向最终用户发送包含文本、按钮和/或图像的即时消息以及短信。系统可以配置为,如果最终用户无法通过即时消息联系,则发送短信作为备用,从而确保最终用户能够收到消息。

创建账户

为了使用高级消息平台,需要使用令牌通过Fortytwo进行身份验证。此令牌可以通过[在此注册](https://www.fortytwo.com/register/)创建。

注册后,请在控制面板中转到"IM" > "令牌"并添加新令牌。上述生成的令牌将用于代码中。

设置

安装Composer

在项目的根路径中,您必须将SDK作为依赖项添加

    composer require fortytwo/php-sdk-advanced-messaging-platform
    composer install

示例

<?php
/**
 * This Example sends an SMS to a phone number
 * NOTE: If you want to test you have to replace <INSERT_TOKEN_HERE> with a valid token and <PHONE_NUMBER> with a mobile phone number including prefix (e.g 356880000001) .
 */
use Fortytwo\SDK\AdvancedMessagingPlatform\AdvancedMessagingPlatform;
use Fortytwo\SDK\AdvancedMessagingPlatform\Entities\DestinationEntity;
use Fortytwo\SDK\AdvancedMessagingPlatform\Entities\SMSContentEntity;
use Fortytwo\SDK\AdvancedMessagingPlatform\Entities\RequestBodyEntity;

// Using the Composer autoload
require dirname(__FILE__) . '/../vendor/autoload.php';

// Declaring some dependencies for the Serializer
$root = dirname(__FILE__);
Doctrine\Common\Annotations\AnnotationRegistry::registerAutoloadNamespace(
    'JMS\Serializer\Annotation',
    $root . "/../vendor/jms/serializer/src"
);

// To change with a correct token and phone number.
const TOKEN = '<INSERT_TOKEN_HERE>';
const NUMBER = '<PHONE_NUMBER>';

try {
    $messaging = new AdvancedMessagingPlatform(TOKEN);

    //Set destination
    $destination = new DestinationEntity();
    $destination->setNumber(NUMBER);

    //SMS Content
    $SMS = new SMSContentEntity();

    $SMS
        ->setMessage('This is a test SMS message from Fortytwo.')
        ->setSenderId('Fortytwo');

    $request = new RequestBodyEntity();

    $request
        ->addDestination($destination)
        ->setSmsContent($SMS);

    $response = $messaging->sendMessage($request);

    echo $response->getResultInfo()->getDescription() ."\n";

} catch (\Exception $e) {
    echo $e->getMessage();
}

有关示例的完整列表,请访问示例文件夹。