arcturial / clickatell
独立PHP库,用于与Clickatell短信网关集成
3.0.0
2017-03-10 09:48 UTC
Requires
- php: >=5.3.3
Requires (Dev)
- phpunit/phpunit: 4.3.*
This package is not auto-updated.
Last update: 2024-09-14 12:13:57 UTC
README
此库允许与新的Clickatell网站集成。
请注意:在旧central.clickatell.com注册的账户应使用仓库的标记发布版或dev分支进行版本2,版本3及以上适用于新平台,旧账户将无法使用此版本。
用法
新API只支持通过RESTful接口发送消息和接收消息的webhooks调用。
use Clickatell\Rest; use Clickatell\ClickatellException; $clickatell = new \Clickatell\Rest('token'); // Full list of support parameters can be found at https://www.clickatell.com/developers/api-documentation/rest-api-request-parameters/ try { $result = $clickatell->sendMessage(['to' => ['27111111111'], 'content' => 'Message Content']); foreach ($result['messages'] as $message) { var_dump($message); /* [ 'apiMsgId' => null|string, 'accepted' => boolean, 'to' => string, 'error' => null|string ] */ } } catch (ClickatellException $e) { // Any API call error will be thrown and should be handled appropriately. // The API does not return error codes, so it's best to rely on error descriptions. var_dump($e->getMessage()); }
状态/回复回调
在开发门户内部配置您的webhooks/callbacks后,您可以使用静态回调方法监听来自Clickatell的web请求。这些回调将从请求体中提取支持的字段。
use Clickatell\Rest; use Clickatell\ClickatellException; // Outgoing traffic callbacks (MT callbacks) Rest::parseStatusCallback(function ($result) { var_dump($result); // This will execute if the request to the web page contains all the values // specified by Clickatell. Requests that omit these values will be ignored. }); // Incoming traffic callbacks (MO/Two Way callbacks) Rest::parseReplyCallback(function ($result) { var_dump($result); // This will execute if the request to the web page contains all the values // specified by Clickatell. Requests that omit these values will be ignored. });