php接口,免认证的短信接口,每天单个号码140条以上
admin
2023-02-17 10:40:07
0

下面介绍一下kewail平台的短信php接口。官网链接:www.kewail.com

// 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 = "https://live.kewail.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 $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": "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 = "https://live.kewail.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": "Kewail",
"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);
}
}

更多,欢迎关注云服务-Kewail科技
官网:https://www.kewail.com/
免认证专用注册: https://www.kewail.com/register.html?uid=1542971565991

相关内容

热门资讯

单向空间杭州旗舰店8年后谢幕,... 去年12月,单向空间杭州乐堤港店员工回应闭店谣言,称“没有收到任何闭店通知”。不到一年,停止营业的消...
带娃家长刷不到下铺,算法不该把... 据新华社的报道,一位宝妈带4岁娃要从昭通去杭州南,在12306上购票时反复被分到上铺,一天内取消三次...
安徽一高标准农田电机出水异常,... 近日,安徽省淮北市濉溪县百善镇丁楼村村民向《都市现场》爆料称:村里2023年建成的高标准农田配套电机...
河北一演唱会音响“翻车”,人声... 近日,来自北京的庞女士向都市现场记者反映,她7月11日在河北唐山观看“青春超燃巨星演唱会”时遭遇了极...
尺素金声|中国经济“失速论”站... 一季度GDP同比增长5.0%、二季度增长4.3%、上半年增长4.7%,2026年中国经济半年报发布后...
NVIDIA最深的护城河要凉!... 7月24日消息,AMD在Advancing AI预简报会上表示,CUDA已不再是外界想象中的那条护城...
廖杰远:三大智能体协同闭环,A... 中国日报网7月24日电 7月22日,在2026年世界互联网大会数字丝路发展论坛数智健康分论坛上,微医...
AI时代构筑超级底座 维谛技术... 文/本报记者 当前,人工智能产业竞争持续向产业链上游延伸,算力竞争早已不再局限于计算芯片性能比拼。具...
刚签核协议不到24小时,美国突... 美国东部时间7月22日下午,美国宣布与沙特阿拉伯签署了一项民用核能协议。据美国有线电视新闻网(CNN...
中国信通院牵头,数据编织国际标... IT之家 7 月 24 日消息,中国信通院今日发文称,国际电信联盟第 21 研究组(ITU-T SG...