IT技术分享

使用织梦做短信接口、实现收发短信、接收验证

摘要:使用织梦做短信接口、实现收发短信、接收验证、短信接口可以去多家平台找、阿里、短信宝等

php代码:

<?php
session_start();
$action=$_REQUEST['act'];
if($action == 'sms'){
    if(isset($_POST)){
        $tel = $_POST['mobile'];
        $code = rand(100000, 999999);
        $_SESSION['smsCode'] = $code;
	    $_SESSION['smsTel'] = $tel;
		$_COOKIE['smsCode'] = $code;

        if(isset($_SESSION['smsTime']) && (time()-$_SESSION['smsTime'])<60 ){
            $ti = (time()-$_SESSION['smsTime']);
            echo json_encode(array(
                'status' => 0,
                'msg' => $ti.'秒后可以再次发送验证码!'
            ));
            exit;
        } else {
            $_SESSION['smsTime'] = time();
        }
        $body = urlencode("感谢您的注册,本次验证码为:".$code."(5分钟内有效),请尽快验证,谢谢。【包容天下】");
	$url='http://api.smsbao.com/sms?u=wsx222&p=a0251983b2cedc4b3fdf5c816eaf9f8e&m='.$_POST['tel'].'&c='.$body.''; 
        $fp = fopen($url, 'r');
        stream_get_meta_data($fp);
        while(!feof($fp)) {
            $result .= fgets($fp, 1024);
        }
        fclose($fp);  return  json_encode(array(
            'status' => 1,
            'msg' => '验证码已发送,请尽快验证!'
        ));
        exit;

    } 


} 

js代码:


<script type="text/javascript">
	$(function () {
   		$("#click-safe").click(function () {
		var codee=$("#codee").val();
		$.ajax({
                type : 'post',
                url : '../addons/jiexi_aaa/inc/mobile/do2.php',
                data : {
                    cod : codee
                },               
                success : function(rtnn){
               		if(rtnn=='1')
				 	 {
						 $("form").submit(); 					
				 	 }else{					  
						  alert('验证码错误!!!');
					  }
                }
            });			
			return false ;		
		});		 
			
		$("#btnCode").click(function () {
				
                //执行获取验证码的操作
                var tel=$("#mobile").val();
				var now = new Date().getTime();
				//alert(tel);
                  if (tel.length !=11 )
					  {
						  alert("请填写正确的手机号码!");
						  document.form.mobile.focus();
						  return false;
					  }
                GetNumber();
		        $.ajax({
                type : 'post',
                url : '../addons/jiexi_aaa/inc/mobile/do.php?act=sms',
                data : {
                    tel : tel,
                    time : now
                },
               
                success : function(rtn){
                    dxT = now;
                    alert(rtn);
                },
				cache : false,
			  error: function(){alert('获取错误');}
            });		
			
            });
        })

        var count = 39;
        function GetNumber() {
			$("#btnCode").attr("disabled", "disabled");
            $("#btnCode").val(count + "秒之后点击获取")
            count--;
            if (count > 0) {
                setTimeout(GetNumber, 1000);
                
            } else {
                $("#btnCode").val("点击获取验证码");
                $("#btnCode").removeAttr("disabled"); 
                count = 39;
            }
        }
</script>


form表单:


<form action="" enctype="multipart/form-data"  method="post">
<input type="text" name="codee" id='codee'  placeholder="短信验证码" >
<input type="button" id="btnCode" value="获取验证码" >
<button type="submit"  id="click-safe">&nbsp; &nbsp; 提交注册 &nbsp; &nbsp;</button>
</form>


版权声明:本文为博主原创文章,未经博主允许不得转载。http://www.westdl.com/dedecourse/sms.html
(0)
打赏 微信扫一扫 微信 扫码打赏
相关技术