runGopher / simplesms
此库提供了一种方便的方式与Rungopher SimpleSms API进行交互
1.0.5
2017-10-12 02:59 UTC
Requires
- php: >=5.6
This package is not auto-updated.
Last update: 2024-09-29 04:36:49 UTC
README
此库提供了一种方便的方式与Rungopher SimpleSms API进行交互。
安装
通过packagist分发。建议的安装方法是使用composer
composer require "rungopher/simplesms:~1.0.0"
用法
发送短信
注意:此示例使用cURL,需要cURL PHP扩展。要使用自定义请求者,请参阅下方的 使用自定义请求者 。
use Rungopher\SimpleSms\CurlRequester; use Rungopher\SimpleSms\SimpleSmsClient; $requester = new CurlRequester(); $client = new SimpleSmsClient($requester, "username", "password", "from"); try { $response = $client->sendSms("to", "message"); } catch(SimpleSmsErrorException $e) { log($e->getMessage()); }
错误:会抛出包含错误信息的SimpleSmsErrorException。
成功: $client->sendSms()返回一个具有以下方法的SimpleSmsOutbound实例
接收投递回执
use Rungopher\SimpleSms\Messages\SimpleSmsDeliveryReceipt; $deliveryReceipt = SimpleSmsDeliveryReceipt::fromRequestBody($requestBody);
SimpleSmsDeliveryReceipt
接收入站短信
use Rungopher\SimpleSms\Messages\SimpleSmsInbound; $inboundSms = SimpleSmsInbound::fromRequestBody($requestBody);
SimpleSmsInbound
使用自定义请求者
自定义请求者必须实现RequesterInterface
/** returns: SimpleSmsResponse */ public function newRequest(SimpleSmsRequest $request);
SimpleSmsRequest
SimpleSmsResponse
return new SimpleSmsResponse($statusCode, $response);