コード例 #1
0
 /**
  * @see ISmsService::sendTemplateMessage()
  */
 public function sendTemplateMessage($mobiles, $tempKey, $sendTime = '')
 {
     //获取模板内容
     $templateService = Beans::get('admin.messageTemplate.service');
     $template = $templateService->getItem("type='message' AND tkey='{$tempKey}'");
     if (!$template) {
         return false;
     }
     //获取当前登录用户
     $userService = Beans::get('user.user.service');
     $loginUser = $userService->getLoginUser();
     //替换标签
     $replacements = array('{username}' => $loginUser['username'], '{mobile}' => $loginUser['mobile'], '{email}' => $loginUser['email'], '{nickname}' => $loginUser['nickname']);
     $content = str_replace(array_keys($replacements), $replacements, $template['content']);
     //去除html标签
     $content = strip_tags($content);
     //发送校验码
     if (strpos($content, '{authcode}') !== false) {
         $authCode = mt_rand(100000, 999999);
         //缓存校验码
         $factor = $mobiles;
         if (!is_numeric($mobiles)) {
             $factor = getHashCode($mobiles);
         }
         $CACHER = CacheFactory::create('file');
         $CACHER->baseKey('authcode')->ftype('mobile')->factor($factor);
         $CACHER->set(null, $authCode);
         $content = str_replace('{authcode}', $authCode, $content);
     }
     return $this->sendMessage($mobiles, strip_tags($content), $sendTime);
 }
コード例 #2
0
 /**
  * 登陆验证
  * @param HttpRequest $request
  */
 public function signin(HttpRequest $request)
 {
     $username = $request->getParameter('username');
     $password = $request->getParameter('password');
     $adminService = Beans::get('admin.admin.service');
     $CACHER = CacheFactory::create('file');
     $cacheKey = 'admin_loginTime_' . $username;
     $maxLoginTime = intval($CACHER->get($cacheKey, 0));
     //        if ( $maxLoginTime >= self::$LOGIN_FAIL_TIME ) {
     //            AjaxResult::ajaxResult(1, '您登录已经连续'.self::$LOGIN_FAIL_TIME.'次登录失败,帐号已被锁定,请联系管理员!');
     //        }
     $login = $adminService->login($username, $password);
     if ($login) {
         //登录成功,清空登录失败的记录
         $CACHER->set($cacheKey, 0);
         if ($login['status'] == 0) {
             AjaxResult::ajaxResult(1, '您的帐号已经被锁定,请联系管理员!');
         }
         AjaxResult::ajaxResult(0, '登录成功!');
     } else {
         //登录失败,记录用户登录失败次数
         $CACHER->set($cacheKey, $maxLoginTime + 1);
         if ($maxLoginTime + 1 >= 10) {
             //登录错误10次锁定帐号
             $adminService->sets('status', 0, array('username' => $username));
         }
         AjaxResult::ajaxResult(1, '登录失败,您还有' . (self::$LOGIN_FAIL_TIME - $maxLoginTime - 1) . '次登录机会!');
     }
 }
コード例 #3
0
 /**
  * 登陆验证
  * @param HttpRequest $request
  */
 public function signin(HttpRequest $request)
 {
     $username = $request->getParameter('username', 'addslashes|trim');
     $password = $request->getParameter('password', 'addslashes|trim');
     $userService = Beans::get('user.user.service');
     $CACHER = CacheFactory::create('file');
     $cacheKey = 'user_loginTime_' . $username;
     $maxLoginTime = intval($CACHER->get($cacheKey, 0));
     if ($maxLoginTime >= self::$LOGIN_FAIL_TIME) {
         AjaxResult::ajaxResult('error', '您登录已经连续' . self::$LOGIN_FAIL_TIME . '次登录失败,帐号已被锁定,请联系管理员!');
     }
     $errorMsg = null;
     $login = $userService->login($username, $password, $errorMsg);
     if ($login) {
         //登录成功,清空登录失败的记录
         $CACHER->set($cacheKey, 0);
         if ($login['ischeck'] == 2) {
             AjaxResult::ajaxResult('error', '您的帐号被封号,请联系管理员!');
         }
         if ($login['mobile'] == '' && $login['email_check'] == 0) {
             AjaxResult::ajaxResult('not_active', $login['email']);
         }
         $userService->setLoginUser($login);
         AjaxResult::ajaxResult('ok', '登录成功!');
     } else {
         //登录失败,记录用户登录失败次数
         $CACHER->set($cacheKey, $maxLoginTime + 1);
         if ($maxLoginTime + 1 >= 10) {
             //登录错误10次锁定帐号
             $adminService = Beans::get('admin.admin.service');
             $adminService->sets('status', 0, array('username' => $username));
         }
         AjaxResult::ajaxResult('error', '登录失败,' . $errorMsg . ',您还有' . (self::$LOGIN_FAIL_TIME - $maxLoginTime - 1) . '次登录机会!');
     }
 }
コード例 #4
0
 /**
  * 推荐算法:
  * 1. 如果有标签,则找出含有相关标签的文章
  * 2. 如果没有标签,则找出当前频道的最热门的文章
  * @see \article\service\interfaces\IArticleService::getAlikeArticles
  */
 public function getAlikeArticles($id, $num, $field = null)
 {
     //首先获取缓存,默认缓存有效期为30分钟
     $CACHER = CacheFactory::create('file');
     $CACHER->baseKey('article')->ftype('alike')->factor($id);
     $items = $CACHER->get(null, 1800);
     if ($items) {
         return $items;
     }
     $item = $this->getModelDao()->getItem($id);
     if (!$field) {
         $field = 'id,title,thumb';
     }
     $conditions = array('chanel_id' => $item['chanel_id'], 'ischeck' => 1, 'id' => '#NI ' . $item['id']);
     if ($item['tags'] != '') {
         $service = Beans::get('article.view.service');
         $__conditions = array('tagid' => '#IN ' . $item['tags'], 'id' => '#NI ' . $item['id']);
         $items = $service->getItems($__conditions, $field, "id DESC", 1, $num, 'id');
         if (!$items) {
             $items = $this->getItems($conditions, $field, "id DESC", 1, $num);
         }
     } else {
         $items = $this->getItems($conditions, $field, "hits DESC", 1, $num);
     }
     //添加缓存
     $CACHER->set(null, $items);
     return $items;
 }
コード例 #5
0
 /**
  * @param HttpRequest $request
  */
 public function index(HttpRequest $request)
 {
     $CACHER = CacheFactory::create('file');
     $key = 'admin.menu.data';
     //$CACHER->set($key, '测试缓存,f**k it');
     __print($CACHER->get($key, 0));
     die;
 }
コード例 #6
0
 /**
  * @see \admin\service\interfaces\IChanelService::delete
  */
 public function delete($id)
 {
     $resullt = parent::delete($id);
     if ($resullt) {
         //删除缓存,以便前台重新生成
         $CACHE = CacheFactory::create('file');
         $CACHE->delete(self::CHANEL_ITEMS_KEY);
     }
     return $resullt;
 }
コード例 #7
0
ファイル: functions.php プロジェクト: jifangshiyanshi/tuonews
/**
 * 获取手机授权码, 默认30分钟有效
 * @param string $mobile
 * @param int $expr 授权码的有效期, 默认为30分钟
 * @return mixed
 */
function getMobileCode($mobile, $expr = 1800)
{
    //缓存校验码
    $factor = $mobile;
    if (!is_numeric($mobile)) {
        $factor = getHashCode($mobile);
    }
    $CACHER = \herosphp\cache\CacheFactory::create('file');
    $CACHER->baseKey('authcode')->ftype('mobile')->factor($factor);
    return $CACHER->get(null, $expr);
}
コード例 #8
0
 /**
  * 自动保存
  * @param HttpRequest $request
  */
 public function autoSave(HttpRequest $request)
 {
     $userid = $request->getParameter('userid', 'intval');
     $data = $request->getParameter('data');
     $cacheKey = $request->getParameter('cache_key', 'trim');
     $CACHER = CacheFactory::create('file');
     $cacheKey = md5($cacheKey . $userid);
     if ($CACHER->set($cacheKey, $data)) {
         AjaxResult::ajaxSuccessResult();
     } else {
         AjaxResult::ajaxFailtureResult();
     }
 }
コード例 #9
0
 /**
  * 添加模板操作
  * @param HttpRequest $request
  */
 public function insert(HttpRequest $request)
 {
     $data = $request->getParameter('data');
     $data['add_time'] = time();
     $data['update_time'] = time();
     //检验模板key是否唯一
     $this->checkField('tkey', $data['tkey']);
     $service = Beans::get($this->getServiceBean());
     if ($service->add($data)) {
         //清除自动保存草稿
         $CACHER = CacheFactory::create('file');
         $key = md5(self::$AUTO_SAVE_KEY . $this->loginUser['id']);
         $CACHER->delete($key);
         AjaxResult::ajaxSuccessResult();
     } else {
         AjaxResult::ajaxFailtureResult();
     }
 }
コード例 #10
0
 /**
  * @see \admin\service\interfaces\IMenuService::updateMenuCache
  */
 public function updateMenuCache()
 {
     //获取菜单分组
     $groupService = Beans::get('admin.menuGroup.service');
     $groups = $groupService->getItems(null, 'tkey');
     //获取所有的菜单
     $menus = $this->getItems('ishow=1', 'id,groupkey,name,url,pid');
     $menuData = array();
     foreach ($groups as $values) {
         //获取当前分组的一级菜单
         $conditions = array('pid' => 0, 'groupkey' => $values['tkey'], 'ishow' => 1);
         $topMemus = $this->getItems($conditions, 'id,groupkey,name,url,pid', 'sort_num ASC');
         foreach ($topMemus as $key => $val) {
             $topMemus[$key]['sub'] = ArrayUtils::filterArrayByKey('pid', $val['id'], $menus);
         }
         $menuData[$values['tkey']] = $topMemus;
     }
     $CACHER = CacheFactory::create('file');
     return $CACHER->set(self::$CACHE_KEY, $menuData);
 }
コード例 #11
0
 /**
  * @see \common\service\interfaces\IEmailService::sendTemplateEmail
  */
 public function sendTemplateEmail($to, $templateKey, $params = null)
 {
     //获取模板内容
     $templateService = Beans::get('admin.messageTemplate.service');
     $template = $templateService->getItem("type='email' AND tkey='{$templateKey}'");
     if (!$template) {
         return false;
     }
     //获取当前登录用户
     $userService = Beans::get('user.user.service');
     $mediaService = Beans::get('media.media.service');
     $loginUser = $userService->getLoginUser();
     $loginMedia = $mediaService->getLoginMedia();
     $CACHER = CacheFactory::create('file');
     if (!$loginUser) {
         $key = 'register_' . $to;
         $loginUser = $CACHER->get($key, 0);
         //删除缓存
         //$CACHER->delete($key);
     }
     //替换标签
     $replacements = array('{username}' => $loginUser['username'], '{userid}' => $loginUser['id'], '{site_url}' => getConfig('site_url'), '{mobile}' => $loginUser['mobile'], '{email}' => $loginUser['email'], '{nickname}' => $loginUser['nickname'], '{media_name}' => $loginMedia['name'], '{media_id}' => $loginMedia['id']);
     $content = str_replace(array_keys($replacements), $replacements, $template['content']);
     //如果有传入自定义参数则惊醒自定义参数替换
     if (is_array($params)) {
         $content = str_replace(array_keys($params), $params, $content);
     }
     //发送校验码
     if (strpos($content, '{authcode}') !== false) {
         $authCode = mt_rand(100000, 999999);
         //缓存校验码
         $factor = getHashCode($to);
         $CACHER->baseKey('authcode')->ftype('email')->factor($factor);
         $CACHER->set(null, $authCode);
         $content = str_replace('{authcode}', $authCode, $content);
     }
     return $this->sendEmail($to, $template['name'], $content, 'html');
 }
コード例 #12
0
ファイル: CacheAction.class.php プロジェクト: cqmyg/herosphp2
 public function memory(HttpRequest $request)
 {
     $CACHER = CacheFactory::create('memo');
     $key = 'test.data';
     $data = $CACHER->get($key);
     if (!$data) {
         $CACHER->set($key, "测试 Memcache 缓存数据!");
     }
     __print($data);
     die;
 }
コード例 #13
0
 /**
  * @see \media\service\interfaces\IMediaService::getRecommendMedia
  */
 public function getRecommendMedia($rows, $position, $fields = null)
 {
     //首先获取缓存,默认缓存有效期为2小时
     $CACHER = CacheFactory::create('file');
     $CACHER->baseKey('media')->ftype($position)->factor($rows);
     $items = $CACHER->get(null, 7200);
     if ($items) {
         return $items;
     }
     //获取媒体推荐位
     if ($fields == null) {
         $fields = 'id,name,logo';
     }
     $mediaRecService = Beans::get('media.rec.service');
     $item = $mediaRecService->getItem(array('position' => $position), 'media_ids');
     //获取媒体
     if ($item) {
         $medias = $this->getItems("id in({$item['media_ids']})", $fields, null, 1, $rows);
         //添加缓存
         $CACHER->set(null, $medias);
     }
     return $medias;
 }
コード例 #14
0
 /**
  * @see \admin\service\interfaces\IFriendLinkService::deleteFootLinkCache
  */
 public function deleteFootLinkCache()
 {
     $CACHER = CacheFactory::create('file');
     $CACHER->delete(self::FOOT_LINK_CACHE);
 }
コード例 #15
0
 public function redis(HttpRequest $request)
 {
     $CACHER = CacheFactory::create('redis');
     $CACHER->set("test_key", "this is the test data", 10);
     var_dump($CACHER->get("test_key"));
     die;
 }
コード例 #16
0
 /**
  * 删除媒体单文章缓存
  * @param $mediaId
  */
 public function deleteMediaArtcache($mediaId)
 {
     $CACHER = CacheFactory::create('file');
     $CACHER->baseKey('media')->ftype('artone')->factor($mediaId);
     $CACHER->delete(null);
 }
コード例 #17
0
 /**
  * 更新菜单分组缓存
  */
 protected function updateCache()
 {
     $items = $this->getItems();
     $CACHER = CacheFactory::create('file');
     return $CACHER->set(self::$CACHE_KEY, $items);
 }
コード例 #18
0
 /**
  * 邮箱激活界面
  * @param HttpRequest $request
  */
 public function emailActive(HttpRequest $request)
 {
     //接收邮箱地址
     $email = $request->getParameter('email', 'trim');
     $userService = Beans::get('user.user.service');
     $user = $userService->getItem("email='{$email}'");
     //缓存需要发送邮件的信息
     $CACHER = CacheFactory::create('file');
     $key = 'register_' . trim($email);
     $CACHER->set($key, $user);
     $this->assign('email', $email);
     $this->assign('template', 'register_email_active');
     $this->setView('email_active');
 }
コード例 #19
0
 /**
  * 清除媒体友情链接缓存
  * @param $mediaId
  */
 public function deleteMediaFLCache($mediaId)
 {
     $CACHER = CacheFactory::create('file');
     $CACHER->baseKey('media')->ftype('friendlink')->factor($mediaId);
     $CACHER->delete(null);
 }
コード例 #20
0
 /**
  * 点赞文章
  * @param HttpRequest $request
  */
 public function zan(HttpRequest $request)
 {
     $id = $request->getParameter('id', 'intval');
     if ($id <= 0) {
         AjaxResult::ajaxFailtureResult();
     }
     $userService = Beans::get('user.user.service');
     $articleService = Beans::get('article.article.service');
     $loginUser = $userService->getLoginUser();
     if ($loginUser) {
         if ($articleService->increase('zan_times', 1, $id)) {
             $CACHER = CacheFactory::create('file');
             $key = md5($loginUser['id'] . $id);
             $CACHER->set($key, 1);
             AjaxResult::ajaxResult(1, 'success');
         } else {
             AjaxResult::ajaxResult(0, 'error');
         }
     } else {
         AjaxResult::ajaxResult(0, 'login');
     }
 }