摩杜雲通用免認證的短信接口,天天單個號碼100條以上

下面介紹一下摩杜雲平臺的短信php接口。demo下載:https://www.mordula.com/experience.html#anchor-1php

// Works well with php5.3 and php5.6.
namespace Moduyun\Sms;
require_once('SmsSenderUtil.php');
class SmsSingleSender {
var $url;
var $accesskey;
var $secretkey;
var $util;
function __construct($accesskey, $secretkey) {
$this->url = "https://live.moduyun.com/sms/v1/sendsinglesms";
$this->accesskey = $accesskey;
$this->secretkey = $secretkey;
$this->util = new SmsSenderUtil();
}
/**html

  • 普通單發,明確指定內容,若是有多個簽名,請在內容中以【】的方式添加到信息內容中,不然系統將使用默認簽名
  • @param int $type 短信類型,0 爲普通短信,1 營銷短信
  • @param string $nationCode 國家碼,如 86 爲中國
  • @param string $phoneNumber 不帶國家碼的手機號
  • @param string $msg 信息內容,必須與申請的模板格式一致,不然將返回錯誤
  • @param string $extend 擴展碼,可填空串
  • @param string $ext 服務端原樣返回的參數,可填空串
  • @return string json string { "result": xxxxx, "errmsg": "xxxxxx" ... },被省略的內容參見協議文檔
    /
    function send($type, $nationCode, $phoneNumber, $msg, $extend = "", $ext = "") {
    /

    請求包體
    "tel": {
    "nationcode": "86",
    "mobile": "13788888888"
    },
    "type": 0,
    "msg": "你的驗證碼是1234",
    "sig": "fdba654e05bc0d15796713a1a1a2318c",
    "time": 1479888540,
    "extend": "",
    "ext": ""
    應答包體
    "result": 0,
    "errmsg": "OK",
    "ext": "",
    "sid": "xxxxxxx",
    "fee": 1
    */
    $random = $this->util->getRandom();
    $curTime = time();
    $wholeUrl = $this->url . "?accesskey=" . $this->accesskey . "&random=" . $random;
    // 按照協議組織 post 包體
    $data = new \stdClass();
    $tel = new \stdClass();
    $tel->nationcode = "".$nationCode;
    $tel->mobile = "".$phoneNumber;
    $data->tel = $tel;
    $data->type = (int)$type;
    $data->msg = $msg;
    $data->sig = hash("sha256",
    "secretkey=".$this->secretkey."&random=".$random."&time=".$curTime."&mobile=".$phoneNumber, FALSE);
    $data->time = $curTime;
    $data->extend = $extend;
    $data->ext = $ext;
    return $this->util->sendCurlPost($wholeUrl, $data);
    }
    /**
  • 指定模板單發
  • @param string $nationCode 國家碼,如 86 爲中國
  • @param string $phoneNumber 不帶國家碼的手機號
  • @param int $templId 模板 id
  • @param array $params 模板參數列表,如模板 {1}...{2}...{3},那麼須要帶三個參數
  • @param string $sign 簽名,若是填空串,系統會使用默認簽名
  • @param string $extend 擴展碼,可填空串
  • @param string $ext 服務端原樣返回的參數,可填空串
  • @return string json string { "result": xxxxx, "errmsg": "xxxxxx" ... },被省略的內容參見協議文檔
    /
    function sendWithParam($nationCode, $phoneNumber, $templId = 0, $params, $sign = "", $extend = "", $ext = "") {
    /

    請求包體
    "tel": {
    "nationcode": "86",
    "mobile": "13788888888"
    },
    "sign": "Moduyun",
    "tpl_id": 19,
    "params": [
    "驗證碼",
    "1234",
    "4"
    ],
    "sig": "fdba654e05bc0d15796713a1a1a2318c",
    "time": 1479888540,
    "extend": "",
    "ext": ""
    應答包體
    "result": 0,
    "errmsg": "OK",
    "ext": "",
    "sid": "xxxxxxx",
    "fee": 1
    */
    $random = $this->util->getRandom();
    $curTime = time();
    $wholeUrl = $this->url . "?sdkaccesskey=" . $this->accesskey . "&random=" . $random;
    // 按照協議組織 post 包體
    $data = new \stdClass();
    $tel = new \stdClass();
    $tel->nationcode = "".$nationCode;
    $tel->mobile = "".$phoneNumber;
    $data->tel = $tel;
    $data->sig = $this->util->calculateSigForTempl($this->secretkey, $random, $curTime, $phoneNumber);
    $data->tpl_id = $templId;
    $data->params = $params;
    $data->sign = $sign;
    $data->time = $curTime;
    $data->extend = $extend;
    $data->ext = $ext;
    return $this->util->sendCurlPost($wholeUrl, $data);
    }
    class SmsMultiSender {
    var $url;
    var $accesskey;
    var $secretkey;
    var $util;
    function __construct($accesskey, $secretkey) {
    $this->url = "https://live.moduyun.com/sms/v1/sendsinglesms";
    $this->accesskey = $accesskey;
    $this->secretkey = $secretkey;
    $this->util = new SmsSenderUtil();
    }
    /**
  • 普通羣發,明確指定內容,若是有多個簽名,請在內容中以【】的方式添加到信息內容中,不然系統將使用默認簽名
  • 【注意】海外短信無羣發功能
  • @param int $type 短信類型,0 爲普通短信,1 營銷短信
  • @param string $nationCode 國家碼,如 86 爲中國
  • @param string $phoneNumbers 不帶國家碼的手機號列表
  • @param string $msg 信息內容,必須與申請的模板格式一致,不然將返回錯誤
  • @param string $extend 擴展碼,可填空串
  • @param string $ext 服務端原樣返回的參數,可填空串
  • @return string json string { "result": xxxxx, "errmsg": "xxxxxx" ... },被省略的內容參見協議文檔
    /
    function send($type, $nationCode, $phoneNumbers, $msg, $extend = "", $ext = "") {
    /

    請求包體
    "tel": [
    {
    "nationcode": "86",
    "mobile": "13788888888"
    },
    {
    "nationcode": "86",
    "mobile": "13788888889"
    }
    ],
    "type": 0,
    "msg": "你的驗證碼是1234",
    "sig": "fdba654e05bc0d15796713a1a1a2318c",
    "time": 1479888540,
    "extend": "",
    "ext": ""
    應答包體
    "result": 0,
    "errmsg": "OK",
    "ext": "",
    "detail": [
    {
    "result": 0,
    "errmsg": "OK",
    "mobile": "13788888888",
    "nationcode": "86",
    "sid": "xxxxxxx",
    "fee": 1
    },
    {
    "result": 0,
    "errmsg": "OK",
    "mobile": "13788888889",
    "nationcode": "86",
    "sid": "xxxxxxx",
    "fee": 1
    }
    ]
    */
    $random = $this->util->getRandom();
    $curTime = time();
    $wholeUrl = $this->url . "?accesskey=" . $this->accesskey . "&random=" . $random;
    $data = new \stdClass();
    $data->tel = $this->util->phoneNumbersToArray($nationCode, $phoneNumbers);
    $data->type = $type;
    $data->msg = $msg;
    $data->sig = $this->util->calculateSig($this->secretkey, $random, $curTime, $phoneNumbers);
    $data->time = $curTime;
    $data->extend = $extend;
    $data->ext = $ext;
    return $this->util->sendCurlPost($wholeUrl, $data);
    }
    /**
  • 指定模板羣發
  • 【注意】海外短信無羣發功能
  • @param string $nationCode 國家碼,如 86 爲中國
  • @param array $phoneNumbers 不帶國家碼的手機號列表
  • @param int $templId 模板 id
  • @param array $params 模板參數列表,如模板 {1}...{2}...{3},那麼須要帶三個參數
  • @param string $sign 簽名,若是填空串,系統會使用默認簽名
  • @param string $extend 擴展碼,可填空串
  • @param string $ext 服務端原樣返回的參數,可填空串
  • @return string json string { "result": xxxxx, "errmsg": "xxxxxx" ... },被省略的內容參見協議文檔
    /
    function sendWithParam($nationCode, $phoneNumbers, $templId, $params, $sign = "", $extend ="", $ext = "") {
    /

    請求包體
    "tel": [
    {
    "nationcode": "86",
    "mobile": "13788888888"
    },
    {
    "nationcode": "86",
    "mobile": "13788888889"
    }
    ],
    "sign": "Moduyun",
    "tpl_id": 19,
    "params": [
    "驗證碼",
    "1234",
    "4"
    ],
    "sig": "fdba654e05bc0d15796713a1a1a2318c",
    "time": 1479888540,
    "extend": "",
    "ext": ""
    應答包體
    "result": 0,
    "errmsg": "OK",
    "ext": "",
    "detail": [
    {
    "result": 0,
    "errmsg": "OK",
    "mobile": "13788888888",
    "nationcode": "86",
    "sid": "xxxxxxx",
    "fee": 1
    },
    {
    "result": 0,
    "errmsg": "OK",
    "mobile": "13788888889",
    "nationcode": "86",
    "sid": "xxxxxxx",
    "fee": 1
    }
    ]
    */
    $random = $this->util->getRandom();
    $curTime = time();
    $wholeUrl = $this->url . "?accesskey=" . $this->accesskey . "&random=" . $random;
    $data = new \stdClass();
    $data->tel = $this->util->phoneNumbersToArray($nationCode, $phoneNumbers);
    $data->sign = $sign;
    $data->tpl_id = $templId;
    $data->params = $params;
    $data->sig = $this->util->calculateSigForTemplAndPhoneNumbers(
    $this->secretkey, $random, $curTime, $phoneNumbers);
    $data->time = $curTime;
    $data->extend = $extend;
    $data->ext = $ext;
    return $this->util->sendCurlPost($wholeUrl, $data);
    }
    更多,歡迎關注雲服務-摩杜雲平臺
相關文章
相關標籤/搜索