php对接短信宝,thinkphp短信宝发送短信

1、先去短信宝注册,购买5元起的短信http://www.smsbao.com/

2、控制器代码实例

~~~

//生日祝福

public function shengrizhufu(){

$xingming = input('param.xingming');//接受表单传过来的姓名

$shouji = input('param.shouji');//接受表单传过来手机

$statusStr = array(

"0" => "短信发送成功",

"-1" => "参数不全",

"-2" => "服务器空间不支持,请确认支持curl或者fsocket,联系您的空间商解决或者更换空间!",

"30" => "密码错误",

"40" => "账号不存在",

"41" => "余额不足",

"42" => "帐户已过期",

"43" => "IP地址限制",

"50" => "内容含有敏感词"

);

$smsapi = "http://api.smsbao.com/";

$user = "*******"; //短信宝平台你的帐号

$pass = md5("*******"); //短信宝平台你的登录密码

$content="[品牌名]亲爱的学员".$xingming.",全体老师祝你生日快乐,一生幸福!";//要发送的短信内容

$phone = $shouji;//要发送短信的手机号码

$sendurl = $smsapi."sms?u=".$user."&p=".$pass."&m=".$phone."&c=".urlencode($content);

$result =file_get_contents($sendurl) ;

//echo $statusStr[$result];

$this->success($statusStr[$result]);exit;

}

~~~

3、发送验证码与上面差不多

~~~

A、用$randcode = rand(1000,9999);随机产生一个4位随机数

B、用$_SESSION把这个随机数存储起来

C、用短信把这个随机数发给用户

D、最后判断用户输入的值与SESSION对比就好了

~~~

html参考

~~~

手机号码

验证码

if("undefined" != typeof pep.sendevent)clearInterval(pep.sendevent);

pep.sendstatus = true;

$('#sendregphonecode').click(function(){

var _this = $(this);

if(pep.sendstatus)

{

$.getJSON('index.php?core-api-index-sendsms&action=reg&phonenumber='+$('#regphonenumber').val()+'&userhash='+Math.random(),function(data){

if(parseInt(data.statusCode) == 200)

{

_this.html('120秒重发');

pep.sendstatus = false;

sendtime = 120;

sendevent = setInterval(function(){

if(sendtime > 0)

{

sendtime--;

_this.html(sendtime+'秒重发');

}

else

{

pep.sendstatus = true;

_this.html('发送验证码');

clearInterval(sendevent);

}

},1000);

}

else

{

pep.mask.show('ajax',data);

}

});

}

});

~~~

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值