短信频率

static function sms($tel){
    $rand=rand(1111,9999);
    $tel_num=Cache::store('redis')->get($tel.'num');//查看手机号发送标识
    $tomorrow=strtotime('tomorrow');
    $now=strtotime('now');
    $exp=$tomorrow-$now;
    if (!$tel_num){
            Cache::store('redis')->set($tel.'num',1,$exp);
    }
    $tel_nums=Cache::store('redis')->get($tel.'num');
    if ($tel_nums>10){
        return Black::fail(601,'每天最多发送10条短信','');
    }
    $tel_sign=Cache::store('redis')->get($tel.'sign');
    if ($tel_sign){
        return Black::fail(602,'一分钟内请勿重复发送','');

    }
    $smsapi = "http://api.smsbao.com/";
    $user = "*****"; //短信平台帐号 //更换账号
    $pass = md5("*****"); //短信平台密码 //更换密码
    $content="[售后服务]".'欢迎您的选择,拿好您的手牌'.$rand.'里面请';//要发送的短信内容
    $phone = $tel;//要发送短信的手机号码
    $sendurl = $smsapi."sms?u=".$user."&p=".$pass."&m=".$phone."&c=".urlencode($content);
    $result =file_get_contents($sendurl) ;
    if ($result==30){
        Cache::store('redis')->increment($tel.'num',1);//发送成功后,每日次数加一,
        Cache::store('redis')->set($tel.'sign',1,60);//发送成功后,将每分钟限制频率存入
        Cache::store('redis')->set($tel.'code',$rand,300);
        return Black::fail(30,'短信发送成功','');

    }
}
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 3

其实第三方自带限制频率 比如阿里大鱼

1年前 评论

代码样式都不做一下吗

1年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!