hubtel/

hubtel-sms

该软件包最新版本(v1.0)没有可用的许可证信息。

一个用于集成Hubtel SMS API的PHP开源库

由于官方仓库已消失,该软件包已被冻结。

v1.0 2017-10-07 22:29 UTC

This package is not auto-updated.

Last update: 2024-08-17 02:16:16 UTC


README

概述

这是一个开源的PHP SDK,允许您从PHP应用程序中访问Hubtel REST SMS API。您需要创建一个Hubtel账户才能使用此API。

安装

SDK可以在启用CURL扩展的PHP 5.3及更高版本上平稳运行。可以使用Composer安装Hubtel PHP SDK。运行以下命令:

composer require hubtel/hubtel-sms

您还可以从仓库下载Hubtel文件夹并将其添加到您的项目中。然后您可以通过引用适当的路径来include Hubtel/Api.php文件,例如:

include '/path/to/location/Hubtel/Api.php';

用法

SDK目前围绕四个主要类组织

  • MessagingApi.php:它处理发送和接收消息、NumberPlans、Campaigns、Keywords、Sender IDs和Message Templates的管理。(有关这些术语的更多信息,请参阅我们的开发者网站。)
  • ContactApi.php:它处理所有与联系人相关的任务。
  • AccountApi.php:它处理API账户持有者的数据。
  • SupportApi.php:它帮助开发人员通过其应用程序与我们的支持平台进行交互。
  • ContentApi.php:它处理所有与内容相关的任务。

示例

  • 如何发送消息

要发送消息,只需复制此代码片段并进行必要的修改

require './vendor/autoload.php';

$auth = new BasicAuth("user123", "pass123");
// instance of ApiHost
$apiHost = new ApiHost($auth);
// instance of AccountApi
$accountApi = new AccountApi($apiHost);
// Get the account profile
// Let us try to send some message
$messagingApi = new MessagingApi($apiHost);
try {
    // Send a quick message
    $messageResponse = $messagingApi->sendQuickMessage("DevUniverse", "+233207110652", "Welcome to planet Hubtel!");

    if ($messageResponse instanceof MessageResponse) {
        echo $messageResponse->getStatus();
    } elseif ($messageResponse instanceof HttpResponse) {
        echo "\nServer Response Status : " . $messageResponse->getStatus();
    }
} catch (Exception $ex) {
    echo $ex->getTraceAsString();
}
  • 如何安排消息

要安排消息,只需复制此代码片段并进行必要的修改。但是,请务必参考PHP datetime函数,了解如何设置消息时间,这非常重要。

    require './vendor/autoload.php';

    // Here we assume the user is using the combination of his clientId and clientSecret as credentials
    $auth = new BasicAuth("user233", "password23");

    // instance of ApiHost
    $apiHost = new ApiHost($auth);
    $enableConsoleLog = TRUE;
    $messagingApi = new MessagingApi($apiHost, $enableConsoleLog);
    try {
        // Default Approach
        $mesg = new Message();
        $mesg->setContent("I will see you soon...");
        $mesg->setTo("+233245098456");
        $mesg->setFrom("+233245657867");
        $mesg->setRegisteredDelivery(true);
        $mesg->setTime(date('Y-m-d H:i:s', strtotime('+1 week'))); // Here we are scheduling the message to be sent next week
        $messageResponse = $messagingApi->sendMessage($mesg);
    
        if ($messageResponse instanceof MessageResponse) {
            echo $messageResponse->getStatus();
        } elseif ($messageResponse instanceof HttpResponse) {
            echo "\nServer Response Status : " . $messageResponse->getStatus();
        }
    } catch (Exception $ex) {
        echo $ex->getTraceAsString();
    }

请探索MessagingApi类以获取更多功能。

  • 如何查看账户详情

要发送消息,只需复制此代码片段并进行必要的修改

    require './vendor/autoload.php';

    // Here we assume the user is using the combination of his clientId and clientSecret as credentials
    $auth = new BasicAuth("user233", "password23");

    // instance of ApiHost
    $apiHost = new ApiHost($auth);
    // instance of AccountApi
    $enableConsoleLog = TRUE;
    $accountApi = new AccountApi($apiHost, $enableConsoleLog);
    try {
        // Get the Account Profile
        $profile = $accountApi->getProfile();
        if ($profile instanceof AccountProfile) {
            echo "\n\n" . $profile->getAccountId();
        } else if($profile instanceof HttpResponse){
            echo "\n\n".$profile->getStatus();
        }
    } catch (Exception $ex) {
        echo $ex->getTraceAsString();
    }

请探索AccountApi类以获取更多功能。

注意事项

ContactApi、SupportApi和ContentApi类遵循几乎相同的函数模式,请探索它们以获取其功能。

获取帮助

如果您需要使用库的帮助,请联系Hubtel支持:support@hubtel.com。我们友好的支持人员通常在24小时内回复。