mp091689/turbosms

基于 SQL 连接的 TurboSms 网关包

v1.0.0 2017-07-15 13:09 UTC

This package is auto-updated.

Last update: 2024-08-26 18:34:53 UTC


README

#安装

打开命令控制台,进入您的项目目录并执行以下命令以下载此包的最新稳定版本

$ composer require mp091689/turbosms

此命令要求您全局安装 Composer,如 Composer 文档中的安装章节所述。

#使用 创建 TurboSms 库的新实例以发送短信,检查状态,接收列表,删除计划中的短信。TurboSms 服务器是 94.249.146.189,数据库 users,表名与网关连接的登录名相同。

new \mp091689\TurboSms\TurboSms($host, $db_name, $user, $password);

##发送

向指定号码发送指定文本的短信。

send(string $number, string $message, string $sign = 'Msg', timestamp $time = null, string $wappush = '', boolean $is_flash = false);

返回包含发送消息参数的对象。

######参数

number - 字符串,仅包含国际格式电话号码的数字 (38050123456789)

message - 字符串,发送消息的文本。 阅读消息编写规则

sign - 字符串,必须是已在服务上注册的字母名称。

time - 时间戳,短信将在设置的时间发送。日期时间格式 'YYYY-MM-DD HH:MM'。

wappush - 字符串,WapPush 链接,包括 http://

is_flash - 布尔值,消息的闪光标志

######响应

返回包含发送消息参数的对象。

object(mp091689\TurboSms\SmsEntity)
  private 'id' => string '856' (length=3)
  private 'msg_id' => null
  private 'number' => string '380501234567' (length=12)
  private 'sign' => string 'Msg' (length=3)
  private 'message' => string 'Hello world!' (length=12)
  private 'wappush' => string '' (length=0)
  private 'is_flash' => string '0' (length=1)
  private 'cost' => null
  private 'balance' => null
  private 'added' => string '2017-07-14 18:42:50' (length=19)
  private 'send_time' => string '2017-07-14 18:45' (length=19)
  private 'sended' => null
  private 'received' => null
  private 'error_code' => null
  private 'status' => null
  • 字段在服务器处理消息后填充。如果字段值指定为 NULL,则表示尚未进行处理。

  • 某些手机型号不支持 WapPush 和闪光消息。

  • 所有日期时间字段的日期格式:YYYY-MM-DD HH:MM,基于连接的时间区域。

######示例

// Create new TurboSms instance
$turbo = new \mp091689\TurboSms\TurboSms('94.249.146.189', 'users', '<LOGIN>', '<PASSWORD>');

// Send sms
$result = $turbo->send('380507095075', 'Hello world!');

// Send sms with specified alpha-name
$result = $turbo->send('380507095075', 'Hello world!', 'Msg');

// Send sms at set time
$result = $turbo->send('380507095075', 'Hello world!', 'Msg', '2017-07-14 18:50');

##检索数据

###通过 id 查找一个短信实例。

findById(integer $id)

返回短信对象。

######参数

id - 整数,所需实例的标识符。

######响应

object(mp091689\TurboSms\SmsEntity)
  private 'id' => string '1' (length=2)
  private 'msg_id' => string '499514b3-56c7-e1f4-5159-e607425c776c' (length=36)
  private 'number' => string '380501234567' (length=12)
  private 'sign' => string 'Msg' (length=10)
  private 'message' => string 'Hello World!' (length=12)
  private 'wappush' => string '' (length=0)
  private 'is_flash' => string '0' (length=1)
  private 'cost' => string '1.00' (length=4)
  private 'balance' => string '139.00' (length=6)
  private 'added' => string '2017-07-14 20:50:08' (length=19)
  private 'send_time' => null
  private 'sended' => string '2016-02-19 20:56:09' (length=19)
  private 'received' => string '2016-02-19 20:56:15' (length=19)
  private 'error_code' => string '0' (length=1)
  private 'status' => string 'DELIVRD' (length=7)

######示例

// Create new TurboSms instance
$turbo = new \mp091689\TurboSms\TurboSms('94.249.146.189', 'users', '<LOGIN>', '<PASSWORD>');

// Find sms by id
$result = $turbo->find(1);

###根据条件查找短信列表。

find(array $conditions = [], array $orderBy = [], integer $limit = null, integer $page = null)

返回对象数组。

######参数

conditions - 数组,关联数组 $key => $value,其中 $key 等于表中的列名,$value 是所需字符串。

orderBy - 数组,关联数组 $key => $value,其中 $key 等于用于排序的表中的列名,$value 是排序方法 ASC/DESC

limit - 整数,根据限制值限制返回的记录数。

page - 整数,分页,仅当指定限制时才起作用。

######响应

[
  ...,
  object(mp091689\TurboSms\SmsEntity),
  ...
]

######示例

<?php

// Create new TurboSms instance
$turbo = new \mp091689\TurboSms\TurboSms('94.249.146.189', 'users', '<LOGIN>', '<PASSWORD>');

// Find all sms
$results = $turbo->find();

// Find list of sms by phone number
$results = $turbo->find(['number' => '380501234567']);

// Find list of sms that were set to specified operator code
$results = $turbo->find(['number LIKE' => '38050%']);

// Find list of sms by phone number and not delivered
$results = $turbo->find(['number' => '380501234567', 'status !=' => 'DELIVRD']);

// Find list of sms by phone number and orderBy error_code
$results = $turbo->find(['number' => '380501234567'], ['error_code']);
// or
$results = $turbo->find(['number' => '380501234567'], ['error_code' => 'DESC']);

// Find list of sms by phone number without ordering
// and set limit to 5 records
$results = $turbo->find(['number' => '380501234567'], [], 5);

// Find list of sms by phone number without ordering
// and set limit to 5 records and set third page
$results = $turbo->find(['number' => '380501234567'], [], 5, 3);

##删除

delete(object $sms)

如果您出于某种原因不想发送计划中的短信,可以简单地将其删除。

######参数

sms - 对象,SmsEntity 实例。

######响应

true - 成功,false - 失败

######示例

<?php

// Create new TurboSms instance
$turbo = new \mp091689\TurboSms\TurboSms('94.249.146.189', 'users', '<LOGIN>', '<PASSWORD>');

// First we need to get the sms
$sms = $turbo->findById(1);

// Now we can delete sms
$result = $turbo->delete($sms);

##状态字段值描述

##错误码字段值描述

#附加信息

  • 使用 SQL 连接操作 TURBOSMS 网关的说明 链接

广播规则