impalago / t-clickatell
独立的PHP库,用于与Clickatell短信网关集成
dev-master
2017-04-04 12:40 UTC
Requires
- php: >=5.5
Requires (Dev)
- phpunit/phpunit: 4.3.*
This package is not auto-updated.
Last update: 2024-09-29 02:49:29 UTC
README
此库允许与新的Clickatell网站集成。
请注意:在旧central.clickatell.com注册账户的客户应使用标签发布的或dev分支进行仓库的版本2,版本3及以上是针对新平台,旧账户将无法使用此版本。
使用方法
新的API仅支持通过RESTful接口发送和接收消息的sendMessage
调用和webhook。
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()); }
状态/回复回调
在开发者门户内配置您的webhook/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. });
问题/贡献
发现错误或缺少功能?请在此处记录,我们将查看。