手机短信修改用户的手机号

//手机短信修改用户的手机号

//前端页面发送手机短信验证码代码

$('.fasongyzm').click(function () {

var phone = $('#phones').val();

$.ajax({

url:"{:U('Public/replace_phone')}",

type:"POST",

dataType:"json",

data:{

phone:phone,

},

success:function(data){

var count = 120;

var countdown = setInterval(CountDown, 1000);

function CountDown() {

$(".fasongyzm").attr("disabled", true);

$(".fasongyzm").text(count + "S后重新发送");

if (count == 0) {

$(".fasongyzm").text("重新发送").removeAttr("disabled");

clearInterval(countdown);

}

count--;

}

}

});

})

//点击确定时候ajax验证手机短信验证码

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

var yzm = $('#yzm').val();

$.ajax({

url:"{:U('Public/replace_phone')}",

type:"POST",

dataType:"json",

data:{

yzm:yzm,

},

success:function(data){

alert(data.msg);

if(data.res == 1){

window.location.href="{:(Index/index)}";

}else{

return false;

}

}

});

});

//更换手机号码

public function replace_phone(){

$yzm = I('yzm');

if(!empty($yzm)){

$phone = session('phone');

$re_msg = session('re_msg');

$uid = session('uid');

if($yzm == $re_msg){

$user_model = D('User');

$data['phone']=$phone;

$map['id']=$uid;

$res = $user_model->where($map)->save($data);

if($res){

$return['msg']="手机号已修改为".$phone;

$return['res']=1;

$this->ajaxReturn($return);

}

}else{

$return['msg']='验证码错误';

$return['res']=2;

$this->ajaxReturn($return);

}

}else{

//发送短信

$phone=I('phone');

$msg = rand(1000,9999);

$res = sendSms($phone,$msg);//sendSms封装的发送短信的方法

if($res){

session('phone',$phone);

session('re_msg',$msg);

$this->ajaxReturn($phone);

}

}

}

著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

你可能感兴趣的:(手机短信修改用户的手机号)