where('create_time','>',date('Y-m-d H:i:s',time()-60)) ->where('mobile',$mobile) ->order('id desc') ->find(); if($sms_record){ return Tools::set_fail('发送太频繁,请稍后再试'); } //查询记录,10分钟内超过10次禁止发送 $count = Db::table(TabConf::$fa_sms) ->where('create_time','>',date('Y-m-d H:i:s',time()-600)) ->where('mobile',$mobile) ->count(); if($count>=10){ return Tools::set_fail('发送次数过多,请稍后再试'); } $config = config('sms_config'); $code = Tools::rand_str(6,3); Tools::log_to_write_txt(['发送短信,开始','mobile'=>$mobile,'code'=>$code,'$config'=>$config]); $res = (new AliSms($config,$config['sms_sign_name'],$config['sms_template_code'])) ->send($mobile,json_encode(['code'=>$code])); Tools::log_to_write_txt(['发送短信,结束',$res]); //写入发送记录 $sms_data = [ 'event'=>input('event'), 'mobile'=>$mobile, 'code'=>$code, 'times'=>0, 'ip'=>request()->ip(), ]; Db::table(TabConf::$fa_sms)->insert($sms_data); return Tools::set_ok('操作成功',$res); }); } }