mjerwin / clockwork-sms
用于Clockwork SMS API的PHP包装器
0.9.2
2016-04-20 22:40 UTC
Requires
- php: >=5.3
- php-curl-class/php-curl-class: 2.1.*
This package is auto-updated.
Last update: 2024-09-07 07:19:14 UTC
README
一个不依赖框架的PHP包装器,用于clockwork SMS API
要求
- 一个Clockwork账户以及API密钥
##安装 将以下内容添加到您的composer.json
文件中
"require": { "mjerwin/clockwork-sms": "~0.9", },
然后运行
php composer.phar update
或者,运行以下命令
php composer.phar require mjerwin/clockwork-sms:~0.9
##用法
###获取账户余额
const CLOCKWORK_API_KEY = 'abcdefghijklmnopqrstuvwxyz1234567890'; $client = new \MJErwin\Clockwork\ClockworkClient(CLOCKWORK_API_KEY); $balance = $client->getBalance();
###发送消息
const CLOCKWORK_API_KEY = 'abcdefghijklmnopqrstuvwxyz1234567890'; $message = new \MJErwin\Clockwork\Message(); $message->setNumber('07700900123'); $message->setContent('Check out this message!'); $client = new \MJErwin\Clockwork\ClockworkClient(CLOCKWORK_API_KEY); $response = $client->sendMessage($message);
sendMessage()
方法返回一个\MJErwin\Clockwork\MessageResponse()
实例。
您可以使用以下方法从响应中获取信息
getTo()
getMessageId()
getErrorCode()
getErrorDescription()
###选项 在发送消息时,可以提供一些可选参数
// Set the name the message will be from $message->setFromName('MJErwin'); // Set if truncating is enabled. If true, messages that are too big will be truncated $client->setTruncateEnabled(true); // Set the action taken if the message contains invalid chars. $client->setInvalidCharAction(ClockworkClient::INVALID_CHAR_ACTION_RETURN_ERROR);
为setInvalidCharAction()
的值1-3提供了类常量,如下所示
有关更多信息,请参阅http://www.clockworksms.com/doc/clever-stuff/xml-interface/send-sms/#param-invalidcharaction