本文共 6394 字,大约阅读时间需要 21 分钟。
下面介绍一下kewail平台的短信php接口。官网链接:
// Works well with php5.3 and php5.6.
namespace Kewail\Sms;
require_once('SmsSenderUtil.php');
class SmsSingleSender {
var $url;var $accesskey;var $secretkey;var $util;function __construct($accesskey, $secretkey) {
$this->url = "";$this->accesskey = $accesskey;$this->secretkey = $secretkey;$this->util = new SmsSenderUtil();}/**
@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);}/**
@return string json string { "result": xxxxx, "errmsg": "xxxxxx" ... },被省略的内容参见协议文档
*/function sendWithParam($nationCode, $phoneNumber, $templId = 0, $params, $sign = "", $extend = "", $ext = "") { /请求包体{ "tel": { "nationcode": "86","mobile": "13788888888"},"sign": "Kewail","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 = "";$this->accesskey = $accesskey;$this->secretkey = $secretkey;$this->util = new SmsSenderUtil();}/**
/**
更多,欢迎关注云服务-Kewail科技
官网:免认证专用注册:转载于:https://blog.51cto.com/14328827/2398836