<script language="javascript">
    function get_mobile_code(){
        $.post("{{asset('../app/sms.php')}}", {mobile:jQuery.trim($('#mobile').val()),send_code:<?php echo $_SESSION['send_code'];?>}, function(msg) {
            alert(jQuery.trim(unescape(msg)));
            if(msg=='提交成功'){
                RemainTime();
            }
        });
    };
    var iTime = 59;
    var Account;
    function RemainTime(){
        document.getElementById('gcode').disabled = true;
        var iSecond,sSecond="",sTime="";
        if (iTime >= 0){
            iSecond = parseInt(iTime%60);
            iMinute = parseInt(iTime/60)
            if (iSecond >= 0){
                if(iMinute>0){
                    sSecond = iMinute + "分" + iSecond + "秒";
                }else{
                    sSecond = iSecond + "秒";
                }
            }
            sTime=sSecond;
            if(iTime==0){
                clearTimeout(Account);
                sTime='获取手机验证码';
                iTime = 59;
                document.getElementById('gcode').disabled = false;
            }else{
                Account = setTimeout("RemainTime()",1000);
                iTime=iTime-1;
            }
        }else{
            sTime='没有倒计时';
        }
        document.getElementById('gcode').value = sTime;
    }    
</script>

sms.php代码

<?php
session_start();

header("Content-type:text/html; charset=UTF-8");

function Post($curlPost,$url){
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_HEADER, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_NOBODY, true);
        curl_setopt($curl, CURLOPT_POST, true);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $curlPost);
        $return_str = curl_exec($curl);
        curl_close($curl);
        return $return_str;
}
function xml_to_array($xml){
    $reg = "/<(\w+)[^>]*>([\\x00-\\xFF]*)<\\/\\1>/";
    if(preg_match_all($reg, $xml, $matches)){
        $count = count($matches[0]);
        for($i = 0; $i < $count; $i++){
        $subxml= $matches[2][$i];
        $key = $matches[1][$i];
            if(preg_match( $reg, $subxml )){
                $arr[$key] = xml_to_array( $subxml );
            }else{
                $arr[$key] = $subxml;
            }
        }
    }
    return $arr;
}
function random($length = 6 , $numeric = 0) {
    PHP_VERSION < '4.2.0' && mt_srand((double)microtime() * 1000000);
    if($numeric) {
        $hash = sprintf('%0'.$length.'d', mt_rand(0, pow(10, $length) - 1));
    } else {
        $hash = '';
        $chars = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789abcdefghjkmnpqrstuvwxyz';
        $max = strlen($chars) - 1;
        for($i = 0; $i < $length; $i++) {
            $hash .= $chars[mt_rand(0, $max)];
        }
    }
    return $hash;
}
$target = "http://106.ihuyi.cn/webservice/sms.php?method=Submit";
$mobile = $_POST['mobile'];
$send_code = $_POST['send_code'];

$mobile_code = random(4,1);
if(empty($mobile)){
    exit('手机号码不能为空');
}

if(empty($_SESSION['send_code']) or $send_code!=$_SESSION['send_code']){
    //防用户恶意请求
    exit('请求超时,请刷新页面后重试');
}

$post_data = "account=cf_liushuaicai&password=liusweet.&mobile=".$mobile."&content=".rawurlencode("您的验证码是:".$mobile_code."。请不要把验证码泄露给其他人。");
//密码可以使用明文密码或使用32位MD5加密
$gets =  xml_to_array(Post($post_data, $target));
if($gets['SubmitResult']['code']==2){
    $_SESSION['mobile'] = $mobile;
    $_SESSION['mobile_code'] = $mobile_code;
}
echo $gets['SubmitResult']['msg'];
?>

转载于:https://www.cnblogs.com/sweet521/p/5709800.html

JS获取短信验证码60秒相关推荐

  1. vue element-ui实现获取短信验证码 ,60秒倒计时及页面

    cc废话不多说先上效果图  vue页面布局 <el-form-item prop="phoneCode" class="pr"><el-inp ...

  2. 使用Jquery实现获取短信验证码60秒倒计时

    现在使用手机号+验证码的方式注册账号已经成为一种必备功能,当我们输入手机号点击发送验证码按钮后,按钮应该不可被再次点击,并开始倒计时,倒计时结束后才能再次点击.这一个可以借助某些插件实现,但其实使用J ...

  3. 短信验证码60秒倒计时

    html 区域 <el-button :disabled="isClick" @click="doNotRepeatOperation">{{tim ...

  4. java短信验证码 60秒_Rxjava操作符飙车系列(三)验证码倒计时

    现在很多软件都需要获取短信验证码,通常都是60秒在向服务器发送一次请求.那么如果用Rxjava来实现这个倒计时的功能呢? 用到的操作符如下: 1.interval: interval 创建一个按照给定 ...

  5. vue页面实现短信验证码60秒倒计时

    废话不多说,直接上代码. template <div class='single-wrapper fs14'><div class='single-mb'>短信验证</d ...

  6. php短信验证码60秒时间限定

    我们在实际使用短信验证码的时候,经常会因为各种原因,收不到短信,那么用户就会再重新请求一条,但是呢,一般的短信验证肯定是有时间间隔的,这样做,第一是为了防止恶意点击,一直发验证码,导致验证码消耗量巨大 ...

  7. php 短信验证码30分钟,php下发短信验证码60秒简单验证

    下发短信验证码,除了注册就是验证手机号 简单实现原理就是 用手机号和一个键作为key存到缓存里, 用户请求的时候,验证这个手机号是不是已经申请过key*(即已手机号为缓存的key有没有,)如果有,并且 ...

  8. iOS 之倒计时 NSTimer 短信验证码 60秒 60分钟

    - (void)viewDidLoad { [superviewDidLoad]; label = [[UILabelalloc]initWithFrame:CGRectMake(10,120, 12 ...

  9. Js获取短信验证码前段效果

    一:先上效果图: 二:源代码文件:reg.html: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN&quo ...

  10. php读取js验证码,js实现获取短信验证码实例

    本文主要和大家分享js实现获取短信验证码实例,主要以代码的形式和大家分享,希望能帮助到大家.$(".form-data").delegate(".send",& ...

最新文章

  1. 史上最强:numpy实现全部机器学习算法
  2. AI语音算法“个性”强 与芯片端“磨合”挑战多
  3. 【转】WINDOWS消息响应,以及处理分派机制
  4. 《Unity开发实战》——3.9节鼠标悬停时高亮显示材质
  5. 湖南计算机应用专业较好的学校,好的计算机应用专业排名
  6. 2019年第十届蓝桥杯 - 省赛 - C/C++大学A组 - G. 日期问题
  7. Ubuntu设置环境变量并立即生效
  8. 阿里最新面试必备项之Java的String类,持续更新中!
  9. NoSQL数据库程序员应该在2019年学习的5大知识
  10. linux cat 文本颜色,linux文本文件查看、展示命令 :cat head tail grep more less nl
  11. Chrome禁止http自动转为https
  12. 优先队列的优先级设置法
  13. WSL配置C/D盘大小写敏感
  14. STL 关联容器的lower_bound()和upper_bound()
  15. uvalive 3938 Ray, Pass me the dishes! 线段树 区间合并
  16. oracle虚拟机磁盘共享,在虚拟机上VM 添加一块共享磁盘方法 支持Oracle 10g RAC
  17. CTFShow“萌心区“WP题解
  18. 欧姆龙plc的IO存储器区详解
  19. 数据库可视化软件:Navicat系列
  20. 按键精灵引流脚本实操

热门文章

  1. Keil/MDK(0):使用过程中的一些设置
  2. 別人的心得。。。。。學習
  3. 数据结构与算法(一):概论
  4. Python 将时间戳转换为本地时间并进行格式化
  5. linux:如何修改用户的密码
  6. Java for LeetCode 036 Valid Sudoku
  7. 击鼓传花:对比 muduo 与 libevent2 的事件处理效率
  8. 把一个下拉框中的选项添加到另一个中
  9. 动画组件和动画控制器资源介绍、动画状态机
  10. java day24【Stream流、方法引用】