config = Dever::config('base', 'project')->sms; } protected function code($mobile, $code = false) { if ($code) { $save = $this->save->get($this->config['code']); return $mobile . '_' . $code == $save; } $day = date('Ymd', time()); # 检测当前手机号最新一次发送时间,不允许一分钟之内发送 $param['option_day'] = $day; $param['option_mobile'] = $mobile; # 检测当前手机号今天已经发送多少验证码了 $info = Dever::load('sms/code-total', $param); if ($info >= 1) { $check = Dever::load('sms/code-one', $param); if ($check) { if (time() - $check['cdate'] < $this->config['time']) { Dever::alert('请不要在一分钟之内申请多次验证码,请您稍后再试'); } } } $total = $this->config['total']; if ($info >= $total) { Dever::alert('很抱歉,您已经申请获取验证码超过' . $total . '次,今天您已经无法获取验证码了,请您明天再来'); } $code = new Code(); $code->createM(); # 记录当前的验证码 $insert['add_mobile'] = $mobile; $insert['add_day'] = $day; $insert['add_code'] = $code->mcode; $id = Dever::load('passport/code-insert', $insert); # 启动发送 $this->send($mobile, $insert['add_code'], $id); $this->save->add($this->config['code'], $mobile . '_' . $code->mcode, $this->config['timeout']); return $code->mcode; } protected function send($mobile, $code, $id = false) { $url = $this->config['url']; if (!$url) { return; } $content = $this->config['body']; $content = $this->replace($content, $mobile, $code); parse_str($content, $param); $type = $this->config['method']; $json = $this->config['json']; $header = $this->config['header']; return Dever::curl($url, $param, $type, $json, $header); } private function replace($content, $mobile = '', $code = '') { $skin = $this->config['skin']; $skin_key = Dever::input('skin', 1); if (isset($skin[$skin_key])) { $skin = $skin[$skin_key]; } else { $skin = array_shift($skin); } $config = array('{code}', '{mobile}', '{sign}', '{skin}', '{param}'); $replace = array($code, $mobile, $this->config['sign'], $skin); return str_replace($config, $replace, $content); } }