count($param); if ($info >= 1) { $check = Dever::db('place/sms_code')->find($param); if ($check) { if (time() - $check['cdate'] < 60) { Dever::alert('请不要在一分钟之内申请多次验证码,请您稍后再试'); } } } $total = 10; if ($info >= $total) { Dever::alert('很抱歉,您已经申请获取验证码超过' . $total . '次,今天您已经无法获取验证码了,请您明天再来'); } $code = $this->createCode(); # 启动发送 $param['mobile'] = $mobile; $param['TemplateCode'] = 'SMS_216755222'; $param['TemplateParam'] = array('code' => $code); $param['log'] = true; if ($state) { $result = Dever::load('account', 'api')->run('aliyun', 'sms_code', $param); } # 记录当前的验证码 $insert = array(); $insert['mobile'] = $mobile; $insert['day'] = $day; $insert['code'] = $code; $insert['status'] = 1; $insert['result'] = Dever::json_encode($result); $id = Dever::db('place/sms_code')->insert($insert); $msg = '验证码已发送至您的手机,请注意查收,十分钟之内有效'; return $code; } public function checkCode($mobile = false, $code = false, $update = 1) { if ($code && $mobile) { $info = Dever::db('place/sms_code')->find(array('mobile' => $mobile), array('order' => 'id desc')); if ($info && $info['status'] == 1 && $code == $info['code']) { if ($update == 1) { Dever::db('place/sms_code')->update($info['id'], array('status' => 2)); } return true; } } return false; } private function createCode() { return \Dever\Helper\Str::rand(4, 0); } }