dc / sms_pswincom
通过HTTP(S)实现PSWinCom的XML API
0.1.7
2015-04-15 06:41 UTC
Requires
- dc/sms: 0.1.2
Requires (Dev)
- phpunit/phpunit: 4.0.*
This package is not auto-updated.
Last update: 2024-09-20 21:49:30 UTC
README
此库使用XML通过HTTP(s)实现PSWinCom的短信网关。目前,仅支持CPA和批量短信消息。
安装
composer require dc/sms_pswincom
或在 composer.json
"require": { "dc/sms_pswincom": "master" }
发送消息
require_once "vendor/autoload.php"; $configuration = new \DC\SMS\PSWinCom\Configuration(); $configuration->username = "username"; $configuration->password = "password"; $gateway = new \DC\SMS\PSWinCom\Gateway($configuration); $message = new \DC\SMS\TextMessage("message text", "<msisdn>"); $receipt = $gateway->sendMessage($message); if ($receipt->wasEnqueued()) { echo "Enqueued"; } else { echo "Failed"; }
处理投递报告
设置您的投递端点,以便接收PSWinCom发送给您的XML数据。以下是一个示例
// assuming you have $gateway from above example $report = $gateway->parseDeliveryReport(file_get_contents('php://input')); // by default, use the successful response for the gateway $return = $report->getSuccessfullyProcessedResponse(); if ($report->isSuccess()) { if (!$db->markMessageReceived($report->getMessageIdentifier())) { // we somehow couldn't save the information, so notify the gateway $return = $report->getErrorInProcessingReport(); } } // tell the gateway that we processed (or didn't process) the message http_response_code($return->getHTTPResponseCode()); foreach ($return->getHeaders() as $key => $value) { header(sprintf("%s: %s", $key, $value)); } echo $return->getContent();