intis/sdk

短信发送和API信息获取的SDK

1.0.1 2018-05-11 10:59 UTC

This package is not auto-updated.

Last update: 2024-09-18 01:46:32 UTC


README

Intis电信网关允许您通过其API向全球发送短信。此程序发送HTTP(s)请求并以JSON和/或XML格式接收信息作为响应。我们API的主要功能包括

  • 发送短信(包括计划选项);
  • 接收关于已发送短信的状态报告;
  • 请求授权发送者名单;
  • 请求传入短信列表;
  • 请求当前余额状态;
  • 请求数据库列表;
  • 请求特定联系列表中的号码列表;
  • 在阻止列表中搜索特定号码;
  • 请求模板列表;
  • 添加新模板;
  • 请求月度统计信息;
  • 发起HLR请求;
  • HLR查询
  • 接收HLR请求统计信息;
  • 通过电话号码请求运营商名称;

要开始使用我们的API,请在我们的网站上申请账户,在那里您可以获取登录名和API密钥。

安装

composer require "intis/sdk: ~1.0.0"

用法

class IntisClient - 用于短信发送和获取API信息的主体类

您必须提供以下三个必填参数以初始化构造函数。它们是

  • $login - 用户登录名
  • $apiKey - 用户API密钥
  • $apiHost - API地址
<?php

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

use Intis\SDK\IntisClient;

$client = new IntisClient($login, $apiKey, $apiHost);

此类包括以下方法

使用getBalance()方法请求您的余额状态

$balance = $client->getBalance();

$amount = $balance->getAmount();     // Getting amount of money
$currency = $balance->getCurrency(); // Getting name of currency

要获取您所有联系数据库的列表,请使用函数getPhoneBases()

$phoneBases = $client->getPhoneBases();

foreach($phoneBases as $oneBase){
    $oneBase->getBaseId();                               // Getting list ID
    $oneBase->getTitle();                                // Getting list name
    $oneBase->getCount();                                // Getting number of contacts in list
    $oneBase->getPages();                                // Getting number of pages in list

    $birthday = $oneBase->getBirthdayGreetingSettings(); // Getting settings of birthday greetings
    $birthday->getEnabled();                             // Getting key that is responsible for sending greetings, 0 - do not send, 1 - send
    $birthday->getDaysBefore();                          // Getting the number of days to send greetings before
    $birthday->getOriginator();                          // Getting name of sender for greeting SMS
    $birthday->getTimeToSend();                          // Getting time for sending greetings. All SMS will be sent at this time.
    $birthday->getUseLocalTime();                        // Getting variable that indicates using of local time while SMS sending.
    $birthday->getTemplate();                            // Getting text template that will be used in the messages
}

我们的网关支持无限发送者名称的选项。要查看所有发送者名称的列表,请使用方法getOriginators()

$originators = $client->getOriginators();

foreach($originators as $originator){
    $originator->getOriginator(); // Getting sender name
    $originator->getState();      // Getting sender status
}

要获取某个联系列表中的电话号码列表,您需要使用getPhoneBaseItems($baseId, $page)方法。为了方便起见,整个列表被分成单独的页面。参数是:$baseId - 特定数据库的ID(必需),以及$page - 特定数据库中的页面编号(可选)。

$items = $client->getPhoneBaseItems($baseId, $page);

foreach($items as $item){
    $item->getPhone();      // Getting subscriber number
    $item->getFirstName();  // Getting subscriber first name
    $item->getMiddleName(); // Getting subscriber middle name
    $item->getLastName();   // Getting subscriber last name
    $item->getBirthDay();   // Getting subscriber birthday
    $item->getGender();     // Getting gender of subscriber
    $item->getNetwork();    // Getting operator of subscriber
    $item->getArea();       // Getting region of subscriber
    $item->getNote1();      // Getting subscriber note 1
    $item->getNote2();      // Getting subscriber note 2
}

要接收您已发送的短信的状态信息,请使用函数getDeliveryStatus($messageId),其中$messageId - 是发送消息ID的数组。

$deliveryStatus = $client->getDeliveryStatus($messageId);

foreach($deliveryStatus as $message){
    $message->getMessageId();     // Getting message ID
    $message->getMessageStatus(); // Getting a message status
    $message->getCreatedAt();     // Getting a time of message
}

要发送消息(向一个或多个收件人发送),请使用函数sendMessage($phone, $originator, $text),其中$phone - 是您发送消息的号码集合,$originator是发送者名称,$text代表消息内容。数组包括MessageSendingSuccess(如果消息成功发送)或MessageSendingError(如果失败)。

$messages = $client->sendMessage($phone, $originator, $text);

foreach($messages as $one){
    if($one->isOk()) {            // A flag of successful dispatch of a message
        $one->getPhone();         // Getting phone number
        $one->getMessageId();     // Getting message ID
        $one->getCost();          // Getting price for message
        $one->getCurrency();      // Getting name of currency
        $one->getMessagesCount(); // Getting number of message parts
    }
    else{
        $one->getPhone();         // Getting phone number
        $one->getMessage();       // Getting error message
        $one->getCode();          // Getting code error in SMS sending
    }

}

要将号码添加到阻止列表中,请运行addToStopList($phone),其中$phone是单个电话号码。

$id = $client->addToStopList($phone); // return ID in stop list

要检查特定电话号码是否在阻止列表中,请使用函数checkStopList($phone),其中$phone是单个电话号码。

$stopList = $client->checkStopList($phone);

$stopList->getId();          // Getting ID in stop list
$stopList->getDescription(); // Getting reason of adding to stop list
$stopList->getTimeAddedAt(); // Getting time of adding to stop list

我们的网关支持创建多个短信模板的选项。要获取模板列表,请使用函数getTemplates()。作为响应,您将获得一定登录名设置的 所有消息的列表。

$templates = $client->getTemplates();

foreach ($templates as $template) {
    $template->getId();        // Getting template ID
    $template->getTitle();     // Getting template name
    $template->getTemplate();  // Getting text of template
    $template->getCreatedAt(); // Getting the date and time when a particular template was created
}

要将新模板添加到系统中,请运行函数 addTemplate($title, $template),其中 $title 是模板的名称,$template 是模板的文本内容。

$templteId = $client->addTemplate($title, $text); // return ID user template

要获取特定月份发送的消息的统计数据,请使用函数 getDailyStatsByMonth($year, $month),其中 $year$month 是您需要统计数据的特定日期。

$result = $client->getDailyStatsByMonth($year, $month);

foreach($result as $one){
    $one->getDay();            // Getting day of month

    $stats = $one->getStats(); // Getting daily statistics
    foreach($stats as $i){
        $i->getState();        // Getting status of message
        $i->getCost();         // Getting prices of message
        $i->getCurrency();     // Getting name of currency
        $i->getCount();        // Getting number of message parts
    }
}

HLR(本地位置寄存器)是一个集中式数据库,它提供了有关每个移动用户的GSM移动网络的详细信息。HLR请求让您检查单个电话号码或号码列表的可用性,以便从联系人列表中清理不可用号码。要执行HLR请求,我们的系统支持函数 makeHLRRequest($phone),其中 $phone 是电话号码数组。

$result = $client->makeHLRRequest($phone);

foreach ($result as $hlr) {
    $hlr->getId();                    // Getting ID
    $hlr->getDestination();           // Getting recipient
    $hlr->getIMSI();                  // Getting IMSI
    $hlr->getMCC();                   // Getting MCC of subscriber
    $hlr->getMNC();                   // Getting MNC of subscriber
    $hlr->getOriginalCountryName();   // Getting the original name of the subscriber's country
    $hlr->getOriginalCountryCode();   // Getting the original code of the subscriber's country
    $hlr->getOriginalNetworkName();   // Getting the original name of the subscriber's operator
    $hlr->getOriginalNetworkPrefix(); // Getting the original prefix of the subscriber's operator
    $hlr->getPortedCountryName();     // Getting name of country if subscriber's phone number is ported
    $hlr->getPortedCountryPrefix();   // Getting prefix of country if subscriber's phone number is ported
    $hlr->getPortedNetworkName();     // Getting name of operator if subscriber's phone number is ported
    $hlr->getPortedNetworkPrefix();   // Getting prefix of operator if subscriber's phone number is ported
    $hlr->getRoamingCountryName();    // Getting name of country if the subscriber is in roaming
    $hlr->getRoamingCountryPrefix();  // Getting prefix of country if the subscriber is in roaming
    $hlr->getRoamingNetworkName();    // Getting name of operator if the subscriber is in roaming
    $hlr->getRoamingNetworkPrefix();  // Getting prefix of operator if the subscriber is in roaming
    $hlr->getStatus();                // Getting status of subscriber
    $hlr->getPricePerMessage();       // Getting price for message
    $hlr->isInRoaming();              // Determining if the subscriber is in roaming
    $hlr->isPorted();                 // Identification of ported number
}

此外,您还可以获取特定时间范围内的HLR请求统计信息。为此,请使用函数 getHlrStats($from, $to),其中 $from$to 是时间段的开始和结束。

$result = $client->getHlrStats($from, $to);

foreach($result as $hlr){
        $hlr->getId();                    // Getting ID
        $hlr->getPhone();                 // Getting phone number
        $hlr->getMessageId();             // Getting message ID
        $hlr->getTotalPrice();            // Getting final price of request
        $hlr->getDestination();           // Getting recipient
        $hlr->getIMSI();                  // Getting IMSI
        $hlr->getMCC();                   // Getting MCC of subscriber
        $hlr->getMNC();                   // Getting MNC of subscriber
        $hlr->getOriginalCountryName();   // Getting the original name of the subscriber's country
        $hlr->getOriginalCountryCode();   // Getting the original code of the subscriber's country
        $hlr->getOriginalNetworkName();   // Getting the original name of the subscriber's operator
        $hlr->getOriginalNetworkPrefix(); // Getting the original prefix of the subscriber's operator
        $hlr->getPortedCountryName();     // Getting name of country if subscriber's phone number is ported
        $hlr->getPortedCountryPrefix();   // Getting prefix of country if subscriber's phone number is ported
        $hlr->getPortedNetworkName();     // Getting name of operator if subscriber's phone number is ported
        $hlr->getPortedNetworkPrefix();   // Getting prefix of operator if subscriber's phone number is ported
        $hlr->getRoamingCountryName();    // Getting name of country if the subscriber is in roaming
        $hlr->getRoamingCountryPrefix();  // Getting prefix of country if the subscriber is in roaming
        $hlr->getRoamingNetworkName();    // Getting name of operator if the subscriber is in roaming
        $hlr->getRoamingNetworkPrefix();  // Getting prefix of operator if the subscriber is in roaming
        $hlr->getStatus();                // Getting status of subscriber
        $hlr->getPricePerMessage();       // Getting price for message
        $hlr->isInRoaming();              // Determining if the subscriber is in roaming
        $hlr->isPorted();                 // Identification of ported number
        $hlr->getRequestId();             // Getting request ID
        $hlr->getRequestTime();           // Getting time of request
    }

要获取有关特定电话号码属于哪个移动网络的信息,请使用函数 getNetworkByPhone($phone),其中 $phone 是电话号码。

$network = $client->getNetworkByPhone($phone);

$network->getTitle(); // Getting operator of subscriber

请注意,此方法比HLR请求的准确性低,因为它使用我们的内部数据库来检查电话号码属于哪个移动运营商。

要获取特定日期的收件人消息列表,请使用函数 getIncomingMessages($date),其中 $date 表示YYYY-mm-dd格式的特定日期。

$result = $client->getIncomingMessages($date);

foreach($result as $one){
    $one->getMessageId();  // Getting message ID
    $one->getOriginator(); // Getting sender name of the incoming message
    $one->getPrefix();     // Getting prefix of the incoming message
    $one->getReceivedAt(); // Getting date of the incoming message
    $one->getText();       // Getting text of the incoming message
}

示例