コード例 #1
0
 public function sendSMS($tel)
 {
     //>>1. 随机生成一个数字
     $randomNumber = String::randString(6, 1);
     session('SMS_CODE', $randomNumber);
     //为了和用户输入的短信验证码进行验证码
     //>>2.将该数字发送到$tel手机号D:\thinkphp\ThinkPHP\Library\Vendor\SMS
     vendor('SMS.TopSdk');
     $c = new \TopClient();
     date_default_timezone_set('Asia/Shanghai');
     //设置时区
     $c->appkey = '23268864';
     //创建应用上面的appkey
     $c->secretKey = '69f0728011dec573eb02f3f57583cb80';
     //创建应用上面的secretKey
     $req = new \AlibabaAliqinFcSmsNumSendRequest();
     // $req->setExtend("123456");
     $req->setSmsType("normal");
     //不改变
     $req->setSmsFreeSignName("注册验证");
     //用来验证
     $req->setSmsParam("{'code':'{$randomNumber}','product':'源代码商城'}");
     $req->setRecNum($tel);
     //接收的电话
     $req->setSmsTemplateCode("SMS_2345004");
     //模板id
     $resp = $c->execute($req);
     //判定发送的状态
     //        return ((string)$resp->result->success)==='true';
     return $resp->result->success;
 }
コード例 #2
0
 public function addAction()
 {
     $randToken = \Org\Util\String::randString(10, 5);
     $callbackUrl = 'http://' . $_SERVER['SERVER_NAME'] . '/index.php/api/' . $randToken;
     $this->assign('token', $randToken);
     $this->assign('callbackUrl', $callbackUrl);
     $this->display();
 }
コード例 #3
0
ファイル: UserModel.class.php プロジェクト: torry999/lingshi
 /**
  * 获取或生成用户salt
  *
  * @param number $uid
  */
 public function salt($uid = 0)
 {
     if ($uid) {
         return $this->where('uid=' . intval($uid))->getField('salt');
     } else {
         return \Org\Util\String::randString(6);
     }
 }
コード例 #4
0
 /**
  * 生成JSSDK签名
  * @retrun array $data JSSDK签名所需参数
  */
 public function JSSDKSignature()
 {
     $string = new String();
     $jsapi_ticket = M('token')->where(['type' => 'js_ticket'])->getField('token');
     $data['jsapi_ticket'] = $jsapi_ticket;
     $data['noncestr'] = $string->randString();
     $data['timestamp'] = time();
     $data['url'] = 'http://' . $_SERVER['HTTP_HOST'] . __SELF__;
     //生成当前页面url
     $data['signature'] = sha1($this->ToUrlParams($data));
     return $data;
 }
コード例 #5
0
 public function saveAutoLogin($admin_id)
 {
     //>>1.生成一个随机的字符串,作为auto_key的值, 并且保存到数据库中
     $auto_key = String::randString();
     $adminModel = M('Admin');
     $adminModel->save(array('auto_key' => $auto_key, 'id' => $admin_id));
     //>>2. 将auto_key进行加密之后和  admin_id 保存到cookie中
     $salt = $adminModel->getFieldById($admin_id, 'salt');
     $auto_key = md5($auto_key . $salt);
     //让cookie的值在浏览器中保存一个星期
     cookie('admin_id', $admin_id, 60 * 60 * 24 * 7);
     cookie('auto_key', $auto_key, 60 * 60 * 24 * 7);
 }
コード例 #6
0
 /**
  * @param $admin_id
  * 保存auto_key到数据库,并将auto_key,和id保存到cookie中
  */
 public function saveAutoInfo($admin_id)
 {
     //>>1.随机生成一个auto_key,并将auto_key保存到登录用户记录的数据库中
     $auto_key = String::randString();
     $result = M('admin')->where(array('id' => $admin_id))->save(array('auto_key' => $auto_key));
     if ($result === false) {
         return false;
     }
     //>>2.将auto_key以及用户的id一起保存到缓存中
     $arr = array();
     $arr['auto_key'] = $auto_key;
     $arr['id'] = $admin_id;
     saveAutoLogin($arr);
 }
コード例 #7
0
 public function saveService($id)
 {
     //生成字符串
     $auto_key = String::randString();
     $adminModel = M('Admin');
     $result = $adminModel->save(array('atuo_key' => $auto_key, 'id' => $id));
     if ($result) {
         //把$auto_key加密后和$id保存到cookie
         $salt = $adminModel->getFieldById($id, 'salt');
         $auto_key = md5($auto_key . $salt);
         //让cookie的值在浏览器中保存一个星期
         cookie('admin_id', $id, 60 * 60 * 24 * 7);
         cookie('auto_key', $auto_key, 60 * 60 * 24 * 7);
     }
 }
コード例 #8
0
 public function register()
 {
     if (!IS_POST) {
         $this->error('405 method not allow');
     }
     $data = I('post.');
     $csrf_token = session('csrf_token');
     if ($csrf_token !== $data['csrf_token']) {
         $this->error('csrf');
     }
     if ($data['email'] == '' || $data['username'] == '' || $data['nickname'] == '') {
         $this->error('所有数据都要填...');
     }
     if (mb_strlen($data['username']) > 30 || mb_strlen($data['nickname']) > 30) {
         $this->error('参数过长');
     }
     if ($data['password'] !== $data['password_verify']) {
         $this->error('输入的两次密码不一致');
     }
     $num = M('user_member')->where(array('email' => $data['email'] . '@cqupt.edu.cn'))->count();
     if ($num != 0) {
         $this->error('你已注册, 如忘记密码请联系红岩网校工作站重置密码');
     }
     $str = new String();
     $salt = $str->randString(6);
     $verify_code = md5(sha1(time() + 1024) . $data['email']);
     $password = md5(md5($data['password']) . $salt);
     $row = array('time' => time(), 'salt' => $salt, 'stu_num' => $data['username'], 'email' => $data['email'] . '@cqupt.edu.cn', 'type_id' => 1, 'nickname' => $data['nickname'], 'verify_code' => $verify_code, 'password' => $password, 'gender' => $data['gender'], 'status' => 1);
     $post_data['subject'] = '=?UTF-8?B?' . base64_encode('认证邮件') . '?=';
     $url = 'http://' . $_SERVER['HTTP_HOST'] . U('TeacherRegister/emailVerify') . "?code=" . $verify_code;
     $post_data['content'] = "Account verify link: \r\n{$url}";
     $post_data['email'] = $data['email'] . '@cqupt.edu.cn';
     $post_data['string'] = '4bbb67';
     $post_data['secret'] = sha1('redrock' . md5($post_data['string']));
     $return = $this->curl_api('hongyan.cqupt.edu.cn/phpmail/test.php', $post_data);
     //        array('subject' => $subject, 'content' => $content, 'email' => $email)
     if ($return->status == 200) {
         M('email_verify')->add($row);
         $this->success('注册成功, 请在12小时内前往学校教师邮箱激活账号~', 'http://mail.cqupt.edu.cn/', 10);
         return;
     }
     $this->error('好像出了点小问题...');
 }
コード例 #9
0
 /**
  * @param $tel
  * 根据电话号码
  * 发送手机短信验证码
  */
 public function sendSMS($tel)
 {
     //随机生成一个6位数字的验证码
     $phoneverify = String::randString(6, 1);
     //将验证码存到session中
     session('PHONE_VERIFY', $phoneverify);
     //发送验证码给此手机用户
     vendor('SMS.TopSdk');
     date_default_timezone_set('Asia/Shanghai');
     $c = new \TopClient();
     $c->appkey = '23269098';
     $c->secretKey = '8f1dd873ef3e792eab786e8d2845f60d';
     $req = new \AlibabaAliqinFcSmsNumSendRequest();
     // $req->setExtend("123456");
     $req->setSmsType("normal");
     $req->setSmsFreeSignName("注册验证");
     $req->setSmsParam("{'code':'{$phoneverify}','product':'e商城'}");
     $req->setRecNum("{$tel}");
     $req->setSmsTemplateCode("SMS_2370004");
     $resp = $c->execute($req);
     return (string) $resp->result->success === 'true';
 }
コード例 #10
0
 /**
  * 裁剪图片
  * @author jry <*****@*****.**>
  */
 public function crop($data = null)
 {
     $image = new \Think\Image();
     $image->open($data['src']);
     $type = $image->type();
     if ($image) {
         $file = './Runtime/Temp/crop' . \Org\Util\String::randString(12, 1) . '.' . $type;
         $url = U(MODULE_MARK . "/Upload/upload", null, true, true);
         // 图片缩放计算
         $sw = $sh = 1;
         if ($data['vw']) {
             $sw = $image->width() / $data['vw'];
         }
         if ($data['vh']) {
             $sh = $image->height() / $data['vh'];
         }
         // 裁剪并保存
         $image->crop($data['w'] * $sw, $data['h'] * $sh, $data['x'] * $sh, $data['y'] * $sh)->save($file);
         $result = $this->curlUploadFile($url, $file);
         return json_decode($result, true);
     }
 }
コード例 #11
0
ファイル: MemberModel.class.php プロジェクト: dower-d/shop
 /**
  * 得到随机的6位盐
  * @return string
  */
 protected function randString()
 {
     $strObj = new String();
     return $strObj->randString();
 }
コード例 #12
0
 private function mail($email, $stunum)
 {
     $str = new String();
     $salt = $str->randString(6);
     $verify_code = md5(sha1(time() + 1024) . $email);
     $row = array('time' => time(), 'salt' => $salt, 'stu_num' => $stunum, 'email' => '', 'type_id' => 2, 'nickname' => '', 'verify_code' => $verify_code, 'password' => '', 'gender' => '', 'status' => 1);
     $data['subject'] = '=?UTF-8?B?' . base64_encode('重置密码') . '?=';
     $url = 'http://' . $_SERVER['HTTP_HOST'] . U('ForgetPassword/reset') . "?code=" . $verify_code;
     $data['content'] = "link: \r\n{$url}";
     $data['email'] = $email;
     $data['string'] = 'er4g7d';
     $data['secret'] = sha1('redrock' . md5($data['string']));
     $return = $this->curl_api('http://hongyan.cqupt.edu.cn/phpmail/test.php', $data);
     //array('subject' => $subject, 'content' => $content, 'email' => $email)
     if ($return->status == 200) {
         M('email_verify')->add($row);
         return true;
     } else {
         return false;
     }
 }
コード例 #13
0
 public function signature()
 {
     $url = "http://Hongyan.cqupt.edu.cn/MagicLoop/index.php?s=/addon/Api/Api/apiJsTicket";
     $timestamp = time();
     $string = "";
     $arr = "abcdefghijklmnopqistuvwxyz0123456789ABCDEFGHIGKLMNOPQISTUVWXYZ";
     for ($i = 0; $i < 16; $i++) {
         $y = rand(0, 41);
         $string .= $arr[$y];
     }
     $secret = sha1(sha1($timestamp) . md5($string) . 'redrock');
     $post_data = array("timestamp" => $timestamp, "string" => $string, "secret" => $secret, "token" => "gh_68f0a1ffc303");
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     // post数据
     curl_setopt($ch, CURLOPT_POST, 1);
     // post的变量
     curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
     $output = curl_exec($ch);
     curl_close($ch);
     //打印获得的数据
     $rel = json_decode($output);
     $string = new String();
     $jsapi_ticket = $rel->data;
     $data['jsapi_ticket'] = $jsapi_ticket;
     $data['noncestr'] = $string->randString();
     $data['timestamp'] = time();
     $data['url'] = 'http://' . $_SERVER['HTTP_HOST'] . __SELF__;
     //生成当前页面url
     $data['signature'] = sha1($this->ToUrlParams($data));
     return $data;
 }
コード例 #14
0
    public function step4()
    {
        session('error', false);
        $this->assign('meta_title', "step4");
        $this->display();
        //连接数据库
        $db_config = session('db_config');
        $db_instance = Db::getInstance($db_config);
        //创建数据表
        create_tables($db_instance, $db_config['DB_PREFIX']);
        //生成加密字符串
        $add_chars .= '`~!@#$%^&*()_+-=[]{};:"|,.<>/?';
        $auth = \Org\Util\String::randString(64, '', $add_chars);
        //生成随机数
        //创建配置文件
        $conf = write_config($db_config, $auth);
        //根据加密字符串更新admin密码的加密结果
        $new_admin_password = user_md5('admin', $auth);
        $sql = <<<SQL
        UPDATE `{$db_config["DB_PREFIX"]}system_config` SET `value`='{$auth}' WHERE `name` = 'AUTH_KEY';
        UPDATE `{$db_config["DB_PREFIX"]}user` SET `password`='{$new_admin_password}' WHERE `id` = 1;
SQL;
        $result = $db_instance->execute($sql);
        if (!$result) {
            $this->error('写入系统加密KEY或管理员新密码出错!');
        }
        if (session('error')) {
            $this->error('安装出错', 'index');
        } else {
            session('step', 4);
            $this->redirect('complete');
        }
    }
コード例 #15
0
ファイル: UserController.class.php プロジェクト: imbzd/sessdw
 public function usersave()
 {
     $userid = $this->_getUserid();
     $password = $this->_getPassword();
     if ($userid) {
         if ($password && !Filter::F_Password($password)) {
             $this->ajaxReturn(1, '请填写正确的密码!');
         }
     } else {
         if (!Filter::F_Password($password)) {
             $this->ajaxReturn(1, '请填写正确的密码!');
         }
     }
     $status = $this->_getStatus();
     $username = $this->_getUsername();
     $department = $this->_getDepartment();
     $position = $this->_getPosition();
     $dangzhibu = $this->_getDangzhibu();
     if ($password) {
         $ukey = String::randString(6, 3, '');
         $password = D('User')->passwordEncrypt($password, $ukey);
     }
     if ($userid) {
         $data = array('username' => $username, 'department' => $department, 'position' => $position, 'dangzhibu' => $dangzhibu, 'updatetime' => TIMESTAMP);
         if ($password) {
             $data['password'] = $password;
             $data['ukey'] = $ukey;
         }
         $userid = D('User')->usersave($userid, $data);
     } else {
         $account = $this->_getAccount();
         //查询account是否已存在
         $flag = M('user')->where(array('account' => $account))->count();
         if ($flag) {
             $this->ajaxReturn(1, '账号已存在!');
         }
         $data = array('account' => $account, 'password' => $password, 'username' => $username, 'department' => $department, 'position' => $position, 'dangzhibu' => $dangzhibu, 'ukey' => $ukey, 'status' => $status, 'loginnum' => 0, 'createtime' => TIMESTAMP, 'updatetime' => TIMESTAMP);
         $userid = D('User')->usersave(null, $data);
     }
     if ($userid) {
         $this->ajaxReturn(0, '党员账号保存成功!');
     } else {
         $this->ajaxReturn(1, '党员账号保存失败!');
     }
 }
コード例 #16
0
 public function managersave()
 {
     $managerid = $this->_getManagerID();
     $password = $this->_getPassword();
     if (!Filter::F_Password($password)) {
         $this->ajaxReturn(1, '请填写正确的密码!');
     }
     $mkey = String::randString(6, 3, '');
     $password = D('User')->passwordEncrypt($password, $mkey);
     $status = $this->_getStatus();
     if ($managerid) {
         $data = array('password' => $password, 'mkey' => $mkey, 'updatetime' => TIMESTAMP);
         $managerid = D('Manager')->saveManager($managerid, $data);
     } else {
         $account = $this->_getAccount();
         if (!Filter::F_Account($account)) {
             $this->ajaxReturn(1, '请填写正确的账号!');
         }
         //查询account是否已存在
         $flag = M('manager')->where(array('account' => $account))->count();
         if ($flag) {
             $this->ajaxReturn(1, '账号已存在!');
         }
         $data = array('account' => $account, 'password' => $password, 'mkey' => $mkey, 'status' => $status, 'supre' => 0, 'createtime' => TIMESTAMP, 'updatetime' => TIMESTAMP, 'createip' => get_client_ip(0, true), 'lastlogintime' => 0, 'loginnum' => 0, 'isdelete' => 0);
         $managerid = D('Manager')->saveManager(null, $data);
     }
     if ($managerid) {
         $this->ajaxReturn(0, '保存成功!');
     } else {
         $this->ajaxReturn(1, '保存失败!');
     }
 }
コード例 #17
0
 /**
  * 短信验证码,用于注册
  * @author jry <*****@*****.**>
  */
 public function sendMobileVerify()
 {
     $receiver = I('post.mobile');
     $user_object = D('User');
     $result = $user_object->create($_POST, 5);
     //调用自动验证
     if (!$result) {
         $this->error($user_object->getError());
     }
     $reg_verify = \Org\Util\String::randString(6, 1);
     //生成验证码
     session('reg_verify', user_md5($reg_verify, $receiver));
     $body = $title . '验证码:' . $reg_verify;
     if (send_mobile_message($receiver, $title, $body)) {
         $this->success('发送成功,请查收!');
     } else {
         $this->error('发送失败!');
     }
 }
コード例 #18
0
 /**
  * 短信验证码,用于注册
  * @author jry <*****@*****.**>
  */
 public function sendMobileVerify()
 {
     // 生成验证码
     $reg_verify = \Org\Util\String::randString(6, 1);
     session('reg_verify', user_md5($reg_verify, I('post.mobile')));
     // 构造短信数据
     $msg_data['receiver'] = I('post.mobile');
     $msg_data['message'] = '短信验证码:' . $reg_verify;
     $result = D('Addons://Message/Message')->sendMessage($msg_data);
     if ($result) {
         $this->success('发送成功,请查收!');
     } else {
         $this->error('发送失败!');
     }
 }
コード例 #19
0
 public function step4()
 {
     $this->assign('meta_title', "step4");
     $this->display();
     //连接数据库
     $db_config = session('db_config');
     $db_instance = Db::getInstance($db_config);
     //创建数据表
     create_tables($db_instance, $db_config['DB_PREFIX']);
     //生成加密字符串
     $add_chars .= '`~!@#$%^&*()_+-=[]{};:"|,.<>/?';
     $auth = \Org\Util\String::randString(64, '', $add_chars);
     //生成随机数
     //创建配置文件
     $conf = write_config($db_config, $auth);
     //根据加密字符串更新admin密码的加密结果
     $sql = 'UPDATE `' . $db_config["DB_PREFIX"] . 'user` SET `password`="' . user_md5('admin', $auth) . '" WHERE `id` = 1';
     $result = $db_instance->execute($sql);
     if (!$result) {
         $this->error('写入加密后密码出错!');
     }
     if (session('error')) {
         $this->error('安装出错', 'step1');
     } else {
         session('step', 4);
         $this->redirect('complete');
     }
 }
コード例 #20
0
 /**
  * 短信验证码,用于注册
  * @author jry <*****@*****.**>
  */
 public function sendMobileVerify()
 {
     $user_object = D('User');
     $result = $user_object->create($_POST, 5);
     //调用自动验证
     if (!$result) {
         $this->error($user_object->getError());
     }
     //生成验证码
     $reg_verify = \Org\Util\String::randString(6, 1);
     session('reg_verify', user_md5($reg_verify, I('post.mobile')));
     //构造短信数据
     $msg_data['receiver'] = I('post.mobile');
     $msg_data['message'] = '短信验证码:' . $reg_verify;
     if (send_mobile_message($msg_data)) {
         $this->success('发送成功,请查收!');
     } else {
         $this->error('发送失败!');
     }
 }
コード例 #21
0
 public function changePass()
 {
     $old_pass = I('post.old_pass');
     $new_pass = I('post.new_pass');
     $conf_pass = I('post.conf_pass');
     $where['stu_num'] = session('stunum');
     $user = M('user_member')->where($where)->find();
     if (!$user['password']) {
         //password字段为空,说明没有修改过,密码仍是后5,6位
         if (substr($user['stu_idcard'], -6) == strtolower($old_pass) || substr($user['stu_idcard'], -5) == strtolower($old_pass)) {
             if ($new_pass == $conf_pass) {
                 $str = new String();
                 $save['salt'] = $str->randString(6);
                 $save['password'] = md5(md5($new_pass) . $save['salt']);
                 M('user_member')->where($where)->save($save);
                 $this->ajaxReturn(true);
             }
         } else {
             $this->ajaxReturn(false);
         }
         //原密码错误
     } else {
         if ($user['password'] == md5(md5($old_pass) . $user['salt'])) {
             if ($new_pass == $conf_pass) {
                 $save['password'] = md5(md5($new_pass) . $user['salt']);
                 M('user_member')->where($where)->save($save);
                 $this->ajaxReturn(true);
             }
         } else {
             $this->ajaxReturn(false);
         }
         //原密码错误
     }
 }