예제 #1
0
 /**
  *id
  *根据id查看用户信息,
  * 支持操作get,put
  *@return json,xml
  *		查询返回,详细信息列表
  *		修改,返回操作结果msg
  *		出错返回err
  */
 public function id()
 {
     $info = auth();
     $id = I('id', null, 'int');
     if ($info && $id) {
         switch ($info['type']) {
             case C('STUDENT_API'):
             case C('STUDENT'):
                 if ($info['id'] != $id) {
                     $data['err'] = '只允许查看自己的信息';
                 }
                 break;
             case C('PRINTER'):
             case C('PRINTER_WEB'):
                 $file['file.pri_id'] = $info['id'];
                 $file['file.use_id'] = $id;
                 $file['file.status'] = array('gt', 0);
                 if (!M('file')->where($file)->getField('id')) {
                     $data['err'] = '只允许查看当前在此打印的用户信息';
                 }
                 break;
             default:
                 $data['err'] = 'unkown user type';
                 break;
         }
         if (!isset($data)) {
             $where['user.id'] = $id;
             $where['user.status'] = array('gt', 0);
             $data = M('User')->where($where)->field('id,name,sch_id,student_number,gender,phone,email,status')->find();
             if ($data) {
                 import('Common.Encrypt', COMMON_PATH, '.php');
                 if ($data['email']) {
                     decrypt_email($data['email']);
                 }
                 if ($data['phone']) {
                     decrypt_phone($data['phone'], $data['student_number'], $id);
                 }
             } else {
                 $data['err'] = '查询用户不存';
             }
         }
     } else {
         $data['err'] = 'unauthored';
     }
     $type = $this->_type == 'xml' ? 'xml' : 'json';
     $this->response($data, $type);
 }
예제 #2
0
 /**
  * 找回密码
  * @param way    找回方式
  * @param number 学号
  * @param phone  手机号
  * @param email  邮箱
  */
 public function findPwd()
 {
     $number = I('number', false, C('REGEX_NUMBER'));
     if (!$number) {
         $this->error('学号无效!');
     }
     switch (I('way')) {
         case 'phone':
             $phone = I('post.phone', false, C('REGEX_PHONE'));
             if (!$phone) {
                 $this->error('手机号无效!');
             }
             $user = M('User')->Field('id,phone')->getByStudentNumber($number);
             if (!empty($user['phone'])) {
                 import('Common.Encrypt', COMMON_PATH, '.php');
                 decrypt_phone($user['phone'], $number, $user['id']);
                 if ($phone != $user['phone']) {
                     $this->error('学号与手机号不匹配!');
                 }
             } else {
                 $this->error('学号未注册或未绑定手机!');
             }
             $result = send_sms_code($phone, 'findPwd');
             //发送短信
             if (true == $result) {
                 session('find_pwd_number', $number);
                 session('find_pwd_phone', $phone);
                 $this->success('发送成功');
             } elseif (0 === $result) {
                 $this->error('发送次数过多');
             } else {
                 $this->error('发送失败');
             }
             break;
         case 'email':
             $email = I('post.email', false, C('REGEX_EMAIL'));
             if (!$email) {
                 $this->error('邮箱地址无效!');
             }
             $user = M('User')->Field('name,id,email')->getByStudentNumber($number);
             if (!empty($user['email'])) {
                 import('Common.Encrypt', COMMON_PATH, '.php');
                 decrypt_email($user['email']);
                 if ($email != $user['email']) {
                     $this->error('学号与邮箱不匹配!');
                 }
             } else {
                 $this->error('学号未登录过或未绑定邮箱!');
             }
             $data['use_id'] = $user['id'];
             $data['type'] = 2;
             //密码找回类型为2
             $Code = M('code');
             $Code->where($data)->delete();
             $data['code'] = random(32);
             $data['content'] = $number;
             $cid = $Code->add($data);
             if ($cid) {
                 $url = U('User/checkEmailCode', 'id=' . $cid . '&code=' . $data['code'], '', true);
                 if (send_mail($user, L('MAIL_FINDPWD', array('link' => $url)), C('MAIL_VERIFY'))) {
                     $this->success('验证邮件已发送到' . $email . '请及时到邮箱查收!注意垃圾箱哦o(^▽^)o', '/', 5);
                 } else {
                     $this->error('验证邮件发送失败!');
                 }
             } else {
                 $this->error('信息生成失败!');
             }
             break;
         default:
             $this->error('类型未知!');
     }
 }
예제 #3
0
 /**
  * find()
  * 核实信息
  * @param number 学号
  * @param name   姓名
  */
 public function find()
 {
     $uid = use_id();
     $number = I('number', false, C('REGEX_NUMBER'));
     $name = I('name', false, 'trim');
     $User = M('User');
     $Card = M('Card');
     $send_user = $uid ? $User->field('id,sch_id,student_number,name,phone,email')->getById($uid) : false;
     if (!$send_user) {
         $this->error('请登录!', '/');
     } elseif (!$send_user['phone']) {
         $this->error('尚未绑定手机', '/User/index');
     } elseif ($send_user['student_number'] == $number) {
         $this->error('不要用自己的做实验哦!');
     } elseif ($Card->cache(true)->getFieldById($uid, 'blocked')) {
         $this->error('由于恶意使用,您的此功能已被禁用', '/Card/help');
     } elseif (!$name && !$number) {
         $this->error('信息不足');
     } else {
         /*尝试 验证 匹配 通知*/
         $School = M('School');
         $recv_user = $User->field('id,name,student_number AS number,sch_id,phone,email')->getByStudentNumber($number);
         if (!$recv_user) {
             /* 判断学校*/
             if (preg_match(C('REGEX_NUMBER_NKU'), $number)) {
                 $this->_saveReceiver($name, $number, 1, false);
             } elseif (preg_match(C('REGEX_NUMBER_TJU'), $number)) {
                 $this->_saveReceiver($name, $number, 2, false);
             } else {
                 $this->error('对不起,目前平台仅对南开大学和天津大学在校生开放,其他需求或者学校请联系我们!');
             }
             $this->error($name . "({$number})尚未加入,你可以在此广播到社交网络", '/Card/broadcast');
         } elseif ($name !== $recv_user['name']) {
             $this->error('失主信息核对失败!');
         } elseif ($recv_off = $Card->cache(120)->getFieldById($recv_user['id'], 'off')) {
             $this->error('对方关闭了此功能,不希望你打扰TA,我们爱莫能助╮(╯-╰)╭');
         } elseif (!($recv_user['phone'] || $recv_user['email'])) {
             $this->_saveReceiver($recv_user['name'], $recv_user['number'], $recv_user['sch_id'], $recv_user['id']);
             $this->error($name . "({$number})尚未绑定联系方式,你可以在此广播到社交网络", '/Card/broadcast');
         } else {
             /*验证成功 ,手机或者邮箱存在 通知并记录*/
             if ($recv_off === null) {
                 //该同学不在card记录之中,则先创建
                 $Card->add(array('id' => $recv_user['id']));
             }
             $msg = '';
             //提示消息
             $success = false;
             import('Common.Encrypt', COMMON_PATH, '.php');
             $send_phone = decrypt_phone($send_user['phone'], $send_user['student_number'], $send_user['id']);
             if ($recv_user['phone']) {
                 /*发送短信通知*/
                 $recv_phone = decrypt_phone($recv_user['phone'], $recv_user['number'], $recv_user['id']);
                 $SMS = new \Vendor\Sms();
                 $info = array('send_phone' => $send_phone, 'send_name' => $send_user['name'], 'recv_name' => $recv_user['name']);
                 $sms_result = $SMS->findCard($recv_phone, $info);
                 $success |= $sms_result;
                 if ($sms_result) {
                     $msg = '短信已发送!<br/>';
                 } else {
                     $msg = '短信发送失败!<br/>';
                 }
             }
             if ($recv_user['email']) {
                 /*发送邮件通知*/
                 $recv_email = decrypt_email($recv_user['email']);
                 $send_user['school'] = $School->cache(true)->getFieldById($send_user['sch_id'], 'name');
                 if ($send_user['email']) {
                     $send_user['email'] = decrypt_email($send_user['email']);
                 }
                 /*拼装邮件*/
                 $mail_msg = L('MAIL_CARD', array('name' => $recv_user['name'], 'school' => $send_user['school'], 'sender_name' => $send_user['name'], 'phone' => $send_user['phone'], 'email' => $send_user['email']));
                 $mail_result = send_mail($recv_user, $mail_msg, C('MAIL_NOTIFY'));
                 $success |= $mail_result;
                 if ($mail_result) {
                     $msg .= '邮件已发送!<br/>';
                 } else {
                     $msg .= '邮件发送失败!';
                 }
             }
             if (!$success) {
                 $this->_saveReceiver($recv_user['name'], $recv_user['number'], $recv_user['sch_id'], $recv_user['id']);
                 $this->error('消息发送失败!请重试或者交由第三方平台!', '/Card/broadcast');
             } else {
                 /*记录招领信息*/
                 $log = array('find_id' => $send_user['id'], 'lost_id' => $recv_user['id']);
                 if (!M('Cardlog')->add($log)) {
                     $this->error('记录失败!!!<br/>' . $msg);
                 } else {
                     $this->success($msg);
                 }
             }
         }
     }
 }
예제 #4
0
파일: function.php 프로젝트: noikiy/print
/**
 * 根据id查找用户
 * @method get_phone_by_id($id)
 * @param  $id    电话号码
 * @return string 返回号码
 */
function get_phone_by_id($id)
{
    if (!$id) {
        return false;
    }
    $user = M('User')->field('student_number,phone')->getById($id);
    if ($user) {
        import('Common.Encrypt', COMMON_PATH, '.php');
        return decrypt_phone($user['phone'], $user['student_number'], $id);
    }
    return false;
}
예제 #5
0
 public function notifyUsers()
 {
     //identify
     $verify_key = I('get.key');
     if ($verify_key != C('VERIFY_KEY')) {
         return;
     }
     $condition['_string'] = '(file.status=2 AND copies=0) OR file.status=4';
     $condition['time'] = array('lt', date('Y-m-d h:i:s', time() - 3600 * 24));
     $NotifyUser = D('NotifyUser');
     $result = array();
     $result1 = $NotifyUser->field('user_id,stu_num,phone,use_name,file_name,count("use_name") as count,$status')->where($condition)->group('use_name')->select();
     $result3 = $NotifyUser->field('user_id,stu_num,phone,use_name,file_name,status')->where($condition)->select();
     for ($i = 0; $i < count($result1); $i++) {
         $item1 = $result1[$i];
         if ($item1['count'] == 1) {
             array_push($result, array($item1['phone'], $item1['use_name'], $item1['file_name'], "已经下载", $item1['user_id'], $item1['stu_num']));
         } else {
             if ($item1['count'] > 1) {
                 $count = 0;
                 $info = "";
                 for ($k = 0; $k < count($result3); $k++) {
                     $item3 = $result3[$k];
                     if ($item3['user_id'] == $item1['user_id']) {
                         $count++;
                         $info = $info . substr($item3['file_name'], 0, 8) . "..";
                         if ($count == 2) {
                             break;
                         } else {
                             $info = $info . "、";
                         }
                     }
                 }
                 $info = $info . "等" . $item1['count'] . "个文件";
                 array_push($result, array($item1['phone'], $item1['use_name'], $info, "已经下载", $item1['user_id'], $item1['stu_num']));
             }
         }
     }
     echo "<meta http-equiv='Content-Type'' content='text/html; charset=utf-8'>";
     $SMS = new \Vendor\Sms();
     for ($i = 0; $i < count($result); $i++) {
         $item = $result[$i];
         import('Common.Encrypt', COMMON_PATH, '.php');
         $phone = decrypt_phone($item[0], $item[5], $item[4]);
         echo $phone;
         if (!empty($phone)) {
             $msgInfo = array("user_name" => $item[1], "info" => $item[2], "status" => $item[3]);
             if ($SMS->noticeUser($phone, $msgInfo)) {
                 echo "提醒信息已经发送";
             } else {
                 echo "发送不成功";
             }
             echo $phone . "\t\t" . $msgInfo["user_name"] . "\t\t" . $msgInfo["info"] . "\t\t" . $msgInfo["status"];
         }
     }
 }