1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > php手机短信接口发送验证码

php手机短信接口发送验证码

时间:2023-07-12 08:19:00

相关推荐

php手机短信接口发送验证码

的短信接口

发送验证码

HTML index.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>短信模块</title><style type="text/css"><!--body,td,th {font-size: 12px;font-family: 微软雅黑;}.number{ height:22px; line-height:22px;font-family: 微软雅黑;}--></style></head><body><!--以下功能是根据需要调用 A--><script language="JavaScript" type="text/javascript" src="js_yz.js"></script><form id="feedbackform" name="feedbackform" action="" method="post" ><table width="501" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC" style="margin-top:50px;"><tr><td width="133" height="45" bgcolor="#FAFAFA" style="padding-left:10px;">获取短信验证码:</td><td width="365" height="45" bgcolor="#FAFAFA" style="padding-left:10px;"><input name="scms_gettel" id="scms_gettel" class="number" type="text" value="18810306233" /><input name="right_yzcode" id="right_yzcode" type="hidden" value="" /> <input name="Submitbfs" type="button" value="获取验证码" class="btn submit" id="Submitbfs" onclick="giveduanxin(document.getElementById('scms_gettel').value)" style="height:28px;"/></td></tr><tr><td height="45" bgcolor="#FAFAFA" style="padding-left:10px;">您收到的验证码:</td><td height="45" bgcolor="#FAFAFA" style="padding-left:10px;"><input type="text" name="scms_yzcode" id="scms_yzcode" class="number" value="" maxlength="6" onblur="giveyz(document.getElementById('scms_yzcode').value)" style="float:left" /><div id="show_statu" style=" float:left;font-size:12px; text-align:left; border:1px solid #FFCC00; line-height:25px; background:#FFFFCC; color:#333333; display:none; height:25px; padding-left:10px; margin-left:8px;"></div></td></tr></table></form><!--以下功能是根据需要调用 B--></body></html>

* yz.js*

function qingkong(){//清空提示函数updateinfo();}var wait = 90; //停留时间function updateinfo(){if(wait == 0){document.getElementById('Submitbfs').value = "获取验证码";document.getElementById('Submitbfs').disabled="";document.getElementById("show_statu").style.display='none';//document.getElementById("show_statu").innerHTML="<span style=color:blue>如果您没有收到短信校验码,您现在可以重新获取!</span>";wait=90 //还原重发时的初始值}else{document.getElementById('Submitbfs').disabled="disabled"; //防止关闭层后,又激活了document.getElementById('Submitbfs').value = "等待 "+wait+" 秒";wait--;setTimeout("updateinfo()",1000);}}//------------------------------------------------------------function giveyz(scms_yzcode){var chk=true;var divid=document.getElementById("show_statu");var regex=/[0-9]$/ divid.style.display='block';if (scms_yzcode=="" ){divid.innerHTML="<span style='color:red'>请填写您收到的短信校验码!</span>";}else if ( document.getElementById('right_yzcode').value!=scms_yzcode ){divid.innerHTML="<span style='color:red'>您填写的短信校验码不正确!</span>";}else if ( document.getElementById('right_yzcode').value==scms_yzcode ){divid.innerHTML="<span style='color:green'>验证成功!</span>";//divid.style.display='none';}}var xmlHttpfunction giveduanxin(tel){var chk=true;var divid=document.getElementById("show_statu");var regex=/^(?:13\d|15\d|18[123456789])-?\d{5}(\d{3}|\*{3})$/;divid.style.display='';if (tel=="" ){divid.innerHTML="<span style='color:red'>请填写手机号码!</span>";}else if ( !regex.exec(tel) ){divid.innerHTML="<span style='color:red'>手机号码格式不正确!</span>";}else{xmlHttp=GetXmlHttpObject()if (xmlHttp==null){alert ("抱歉,浏览器不支持")return} var url="http://localhost/mcode/yz_send.php"url=url+"?action=chk&tel="+telurl=url+"&sid="+Math.random()xmlHttp.onreadystatechange=stateChangedxmlHttp.open("GET",url,true)xmlHttp.send(null)} function stateChanged() {if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){var give_strs= new Array(); //定义一数组give_strs=xmlHttp.responseText.split("|"); //字符分割 if (give_strs[0]=="right"){//document.getElementById('Submitbfs').style.visibility='hidden';//closeWindow();divid.innerHTML="<span style='color:green'>验证码已发送,请查收!</span>";//document.getElementById('codeshows').innerHTML=yzm;document.getElementById('Submitbfs').disabled="disabled";//立即失效,并开始提示下面是2秒后换提示内容并开始倒数document.getElementById('right_yzcode').value=give_strs[1];//回传发到短信的校验码setTimeout("qingkong()",2000);//1秒后提示,重新发送}else{divid.innerHTML=xmlHttp.responseText;}}}//document.getElementById('Submitbfs').disabled="disabled";}function GetXmlHttpObject(){var xmlHttp=null;try{// Firefox, Opera 8.0+, SafarixmlHttp=new XMLHttpRequest();}catch (e){// Internet Explorertry{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}catch (e){xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}}return xmlHttp;}

yz_send.php

<?php$action=$_REQUEST['action'];$tel=$_REQUEST['tel'];$yzm=$_REQUEST['yzm'];function randomkeys($length){$pattern='1234567890'; //字符池for($i=0;$i<$length;$i++){$key.=$pattern{mt_rand(0,9)};//生成php随机数}return $key;}function give_ms($yzm,$tel){//发送短信 短信开关,帐号,密码,内容,手机呈file_get_contents("/mt/?uid=xxxxx&pwd=".md5(xxxxxxx)."&mobile=".$tel."&mobileids=&content=".$msg."");}$yzm=randomkeys(6);if ($action=="chk"){if ($tel=="" || $yzm=="" ){$instrs = "短信验证码发送失败!";$outstrs = iconv('GBK','UTF-8',$instrs);echo $outstrs;exit;}//查询号码是否预约过if($tel == true){//查询数据库 leave_tell$db = require('../caches/configs/database.php');$con_arr = $db['default'];$conn=mysql_connect($con_arr['hostname'],$con_arr['username'],$con_arr['password']) or die("error connecting") ; //连接数据库mysql_query("set names 'utf8'"); mysql_select_db($con_arr['database']);$tablename = $con_arr['tablepre'].'guestbook';$sql ="select * from $tablename where leave_tell = ".$tel; $result = mysql_query($sql,$conn); $res = mysql_fetch_row($result);if(!empty($res) && $res == true){$instr = "您的手机号已经注册过!";$outstr = iconv('GBK','UTF-8',$instr);echo $outstr;exit;}}give_ms($yzm,$tel);echo "right|".$yzm;//echo "right|666666";exit;}?>

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。