dc/sms_link

通过HTTP(S)实现Link Mobility的通用平台REST API

0.0.1 2016-09-19 13:50 UTC

This package is not auto-updated.

Last update: 2024-09-14 19:47:51 UTC


README

此库使用JSON通过HTTP(s)实现了Link Mobility的SMS网关。目前,仅支持CPA和批量短信消息。

安装

composer require dc/sms_link

或者在 composer.json

"require": {
    "dc/sms_link": "master"
}

发送消息

require_once "vendor/autoload.php";

$configuration = new \DC\SMS\Link\Configuration();
$configuration->username = "username";
$configuration->password = "password";
$configuration->platformId = "platformId";
$configuration->platformPartnerId = "platformPartnerId";
$gateway = new \DC\SMS\Link\Gateway($configuration);

$message = new \DC\SMS\TextMessage("message text", "<msisdn>");

$receipt = $gateway->sendMessage($message);

if ($receipt->wasEnqueued()) {
    echo "Enqueued";
} else {
    echo "Failed";
}

处理投递报告

设置您的投递端点,以便接收Link Mobility发送给您的投递报告。以下是一个示例

// 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();