| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 | 
							- <?php
 
- namespace Passport\Src\Lib;
 
- use Dever;
 
- use Dever\Img\Handle;
 
- use Dever\Routing\Uri;
 
- use Dever\Session\Oper as Save;
 
- use Dever\String\Encrypt;
 
- class Base
 
- {
 
-     const NAME = 'dever';
 
-     const CODE = 'dever_code';
 
-     const MCODE = 'dever_mcode';
 
-     protected $save;
 
-     public function __construct()
 
-     {
 
-         $this->save = new Save(false, 'cookie');
 
-     }
 
-     protected function info()
 
-     {
 
-         return $this->save->get(self::NAME);
 
-     }
 
-     protected function code($code = false)
 
-     {
 
-         if ($code) {
 
-             $save = $this->save->get(self::CODE);
 
-             return $code == $save;
 
-         }
 
-         $code = new Code();
 
-         $code->create();
 
-         $this->save->add(self::CODE, $code->code, 600);
 
-     }
 
-     protected function mcode($mobile, $code = false)
 
-     {
 
-         if ($code) {
 
-             $save = $this->save->get(self::MCODE);
 
-             return $mobile . '_' . $code == $save;
 
-         }
 
-         $day = date('Ymd', time());
 
-         # 检测当前手机号最新一次发送时间,不允许一分钟之内发送
 
-         $param['option_day'] = $day;
 
-         $param['option_mobile'] = $mobile;
 
-         # 检测当前手机号今天已经发送多少验证码了
 
-         $info = Dever::load('passport/code-total', $param);
 
-         if ($info >= 1) {
 
-             $check = Dever::load('passport/code-check', $param);
 
-             if ($check) {
 
-                 if (time() - $check['cdate'] < Dever::config('base', 'passport')->mobileCode['time']) {
 
-                     Dever::alert('请不要在一分钟之内申请多次验证码,请您稍后再试');
 
-                 }
 
-             }
 
-         }
 
-         $total = Dever::config('base', 'passport')->mobileCode['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);
 
-         # 发送验证码到手机上
 
-         //$text = '您好,您的验证码为' . $code->mcode . ',十分钟之内有效。';
 
-         $text = str_replace('{code}', $code->mcode, Dever::config('base', 'passport')->mobileCode['msg']);
 
-         # 启动发送
 
-         $this->send($mobile, $text, $id);
 
-         $this->save->add(self::MCODE, $mobile . '_' . $code->mcode, 600);
 
-         return $code->mcode;
 
-     }
 
-     private function send($mobile, $content, $id)
 
-     {
 
-         $url = Dever::config('base', 'passport')->mobileCode['url'];
 
-         if (Dever::config('base', 'passport')->mobileCode['signType'] == 1) {
 
-             $content = Dever::config('base', 'passport')->mobileCode['sign'] . $content;
 
-         } else {
 
-             $content .= Dever::config('base', 'passport')->mobileCode['sign'];
 
-         }
 
-         $param['phone'] = $mobile;
 
-         $param['message'] = $content;
 
-         $param['seqid'] = $id + 1000;
 
-         $param['smspriority'] = 1;
 
-         $url .= http_build_query($param);
 
-         Dever::curl($url);
 
-     }
 
-     protected function refer()
 
-     {
 
-         $refer = Dever::input('refer');
 
-         $project = 'main';
 
-         if ($refer) {
 
-             $url = parse_url(Encrypt::decode($refer));
 
-             $url['path'] = preg_replace('/^\//', '', $url['path']);
 
-             if (!isset($url['query'])) {
 
-                 $url['query'] = '';
 
-             }
 
-             if (Uri::$type == '?') {
 
-                 $refer = Dever::url(str_replace($url['path'] . Uri::$type, '', $url['query']), $project);
 
-             } else {
 
-                 $refer = Dever::url($url['path'] . '?' . $url['query'], $project);
 
-             }
 
-             Dever::out($refer);
 
-         } else {
 
-             Dever::out(Dever::url('home', $project));
 
-         }
 
-     }
 
-     protected function save($user)
 
-     {
 
-         if (is_numeric($user)) {
 
-             $user = Dever::load('service/company-one', $user);
 
-         }
 
-         if ($user && is_array($user)) {
 
-             if (Dever::mobile()) {
 
-                 $time = 30;
 
-             } else {
 
-                 $time = 7;
 
-             }
 
-             $this->save->add(self::NAME, $user, 3600 * 24 * $time);
 
-             $user['signature'] = Dever::login($user['id']);
 
-             return $user;
 
-         }
 
-     }
 
-     public function createRefer()
 
-     {
 
-         return 'refer=' . Encrypt::encode(Dever::url());
 
-     }
 
-     protected function saveAvatar($value)
 
-     {
 
-         $base = DEVER_PATH . 'data/upload/';
 
-         $date = explode('-', date("Y-m-d"));
 
-         if (is_array($value)) {
 
-             $user = $value[1];
 
-             $value = $value[0];
 
-             if (is_array($value)) {
 
-                 $name = md5($value['tmp_name'] . rand(0, 100) . microtime());
 
-                 $path = 'avatar/' . $date[0] . '/' . $date[1] . '/' . $date[2] . '/';
 
-                 $ext = '.jpg';
 
-                 $temp = Dever::path($base, $path . $name . $ext);
 
-                 move_uploaded_file($value['tmp_name'], $temp);
 
-                 $value = $temp;
 
-             }
 
-         }
 
-         $result = Dever::$global['host']['img'] . 'chead.jpg';
 
-         if ($value) {
 
-             # 裁图
 
-             $handle = new Handle();
 
-             $size = '200_200_2';
 
-             $user = isset($user) && $user ? $user : $this->init();
 
-             if ($user && isset($user['id']) && $user['id']) {
 
-                 $name = md5($user['id']);
 
-             } else {
 
-                 $name = md5($value . rand(0, 100) . microtime());
 
-             }
 
-             $path = 'avatar/' . $date[0] . '/' . $date[1] . '/' . $date[2] . '/';
 
-             $ext = '.jpg';
 
-             $file = Dever::path($base, $path . $name . $ext);
 
-             $temp = $file . '.temp.jpg';
 
-             //$value = Dever::curl($value);
 
-             //file_put_contents($temp, file_get_contents($value));
 
-             $file = $handle->thumb($value, $size, true, $file);
 
-             //print_r($file);die;
 
-             if ($file) {
 
-                 $result = Dever::$global['host']['image'] . $path . $name . $ext;
 
-             } else {
 
-                 $result = $value;
 
-             }
 
-         }
 
-         return $result;
 
-     }
 
- }
 
 
  |