php短信验证接口代码,秒滴短信验证码发送PHP接口实例代码,很精简

登陆秒滴官网后可以获得相关信息

1530362522786480.png

看精简的发送代码,就两个函数实现发送date_default_timezone_set("Asia/Shanghai");

//http post

function curl_post($postUrl,$data,$header = array()){

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,$postUrl);

curl_setopt($ch, CURLOPT_HEADER, 0);

curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);

curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

if(strpos($postUrl,"https") !== false){

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

}

if(count($header)>0){

curl_setopt($ch, CURLOPT_HTTPHEADER, $header);

}

$data = curl_exec($ch);

curl_close($ch);

return $data;

}

//发送用户注册的验证码

function sendsmscode($tel,$code){

$sms = array(

"url"=> "https://api.miaodiyun.com/20150822/industrySMS/sendSMS",//固定、无需修改

"sid"=> "53c412f78a7143a585014578a4000000", //对应官网后台的 ACCOUNT SID

"token"=> "8b7c4094d39c4141aa41a91fd8000000", //对应官网后台的 AUTH TOKEN

);

$timespan = date("YmdHis");

$sign = md5("{$sms['sid']}{$sms['token']}{$timespan}");

$data = array(

"accountSid"=>$sms['sid'],

"templateid"=>"318247587",

"param"=>"{$code},2",//验证码、时长(分)

"to"=>$tel,

"timestamp"=>$timespan,

"sig"=>$sign,

"respDataType"=>"JSON",

);

$fields_string = "";

foreach ($data as $key => $value) {

$fields_string .= $key . '=' . $value . '&';

}

rtrim($fields_string, '&');

$header = array(

"Content-type: application/x-www-form-urlencoded",

"Accept: application/json"

);

$json = curl_post($sms['url'],$fields_string,$header);

if(strpos($json,"{")!==false){

$json = substr($json,strpos($json,"{"));

}

return json_decode($json,true);

}

$x = sendsmscode("18221228706","8652");

header("Content-type:text/html;charset=utf-8");

var_dump($x);

正确后返回array(5) { ["respCode"]=> string(5) "00000" ["respDesc"]=> string(15) "请求成功。" ["failCount"]=> string(1) "0" ["failList"]=> array(0) { } ["smsId"]=> string(32) "a395adf8c1874ef59baa0959637845d0" }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值