bonlineza / clickatell
用于集成Clickatell短信网关的独立PHP库
v4.0.2
2019-08-08 16:24 UTC
Requires
- php: >=5.5
Requires (Dev)
- phpunit/phpunit: 4.3.*
This package is not auto-updated.
Last update: 2024-09-18 12:40:26 UTC
README
此库允许与新的Clickatell网站集成。
请注意:在旧central.clickatell.com注册账户的客户应使用标签发布版或dev分支的版本2,版本3及以上适用于新平台,旧账户将无法使用此版本。
使用方法
新API仅支持sendMessage
调用和通过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. });