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);
}
});
}
});
~~~