短信频率
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,'短信发送成功','');
}
}
其实第三方自带限制频率 比如阿里大鱼
用布隆过滤器
代码样式都不做一下吗