-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
huguijian
committed
Oct 1, 2016
1 parent
1328ca3
commit 054d16e
Showing
20 changed files
with
2,336 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace common; | ||
|
||
|
||
class ERROR | ||
{ | ||
const PARAM_ERROR = 1; //参数错误 | ||
const TOKEN_ERROR = 2; //token错误 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: mac | ||
* Date: 13-12-6 | ||
* Time: 下午3:26 | ||
*/ | ||
|
||
namespace common; | ||
use ZPHP\Core\Config as ZConfig, | ||
ZPHP\Cache\Factory as ZCache, | ||
ZPHP\Common\Route as ZRoute, | ||
ZPHP\Conn\Factory as ZConn; | ||
use ZPHP\Protocol\Request; | ||
|
||
|
||
class Utils | ||
{ | ||
|
||
public static function checkToken($uid, $token,$prefix='fd') | ||
{ | ||
if(empty($uid) || empty($token)) { | ||
return false; | ||
} | ||
$config = ZConfig::getField('cache', 'net'); | ||
$cacheHelper = ZCache::getInstance($config['adapter'], $config); | ||
$key = "{$prefix}_{$uid}_" . ZConfig::getField('connection', 'prefix'); | ||
$tokenJson = $cacheHelper->get($key); | ||
$tokenArr = json_decode($tokenJson,true); | ||
return $tokenArr['token'] === $token; | ||
} | ||
|
||
public static function setToken($uid,$prefix='fd') | ||
{ | ||
$token = uniqid(); | ||
$config = ZConfig::getField('cache', 'net'); | ||
$cacheHelper = ZCache::getInstance($config['adapter'], $config); | ||
$key = "{$prefix}_{$uid}_" . ZConfig::getField('connection', 'prefix'); | ||
$data = array( | ||
'token' => $token | ||
); | ||
if ($cacheHelper->set($key, json_encode($data))) { | ||
return $token; | ||
} | ||
throw new \Exception("token set error", ERROR::TOKEN_ERROR); | ||
} | ||
|
||
public static function getViewMode() | ||
{ | ||
if(Request::isLongServer()) { | ||
return ZConfig::getField('project', 'view_mode', 'Json'); | ||
} | ||
if(\ZPHP\Common\Utils::isAjax()) { | ||
return 'Json'; | ||
} | ||
return 'Php'; | ||
} | ||
|
||
public static function jump($action, $method, $params) | ||
{ | ||
$url = ZRoute::makeUrl($action, $method, $params); | ||
self::redirect($url); | ||
|
||
} | ||
|
||
public static function makeUrl($action, $method, $params="") | ||
{ | ||
return ZRoute::makeUrl($action, $method, $params); | ||
} | ||
|
||
public static function showMsg($msg) | ||
{ | ||
return array( | ||
'_view_mode'=>self::getViewMode(), | ||
'_tpl_file'=>'error.php', | ||
'msg'=>$msg, | ||
'static_url'=>ZConfig::getField('project', 'static_url'), | ||
); | ||
} | ||
|
||
public static function online($channel='ALL') | ||
{ | ||
|
||
$config = ZConfig::get('connection'); | ||
$connection = ZConn::getInstance($config['adapter'], $config); | ||
return $connection->getChannel($channel); | ||
} | ||
|
||
|
||
public static function redirect($url) | ||
{ | ||
$url = preg_match('/^(https?:|\/)/', $url) ? $url:''; | ||
header('Location: ' . $url, true, 301); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace common; | ||
|
||
|
||
class chat | ||
{ | ||
const SINGLE_CHAT = 1; | ||
const GROUP_CHAT = 2; | ||
const JOIN_FRIEND = 3; | ||
const JOIN_SWARM = 4; | ||
const REMOVE_FRIEND = 5; | ||
const QUIT_SWARM = 6; | ||
const LOGIN_OUT = 7; | ||
const REMOVE_GROUP = 8; | ||
const ADD_GROUP = 9; | ||
const SEND_CHECK_MSG = 10; | ||
const CREATE_SWARM = 11; | ||
const DELETE_SWARM = 12; | ||
const REMOVE_FRIEND_FOR_SWARM = 13; | ||
const ADD_FRIEND_MSG_TYPE = 1; | ||
const REMOVED_SWARM_MSG_TYPE = 2; | ||
const JOIN_SWARM_MSG_TYPE = 3; | ||
const JOIN_SWARM_SUCCESS = 14; | ||
const DEFAULT_GROUP_NAME = "我的好友"; | ||
const ON_LINE = 'online'; | ||
const OFF_LINE = 'hide'; | ||
const CHANGE_LINE = 15; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace common; | ||
|
||
use ZPHP\Core\Factory; | ||
|
||
/** | ||
* 获取class实例的工具类 | ||
* | ||
* @package service | ||
* | ||
*/ | ||
class loadClass | ||
{ | ||
|
||
public static function getService($service) | ||
{ | ||
return Factory::getInstance("service\\{$service}"); | ||
} | ||
|
||
public static function getDao($dao) | ||
{ | ||
return Factory::getInstance("dao\\{$dao}"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
|
||
namespace ctrl\main; | ||
|
||
use ZPHP\Controller\IController, | ||
common, | ||
ZPHP\Protocol\Request; | ||
|
||
|
||
class Base implements IController | ||
{ | ||
protected $server; | ||
protected $params = array(); | ||
|
||
public function _before() | ||
{ | ||
$this->params = Request::getParams(); | ||
return true; | ||
} | ||
|
||
public function _after() | ||
{ | ||
//common\loadClass::getDao('User')->closeDb(); | ||
} | ||
|
||
protected function getInteger(array $params, $key, $default = null, $abs = true, $notEmpty = false) | ||
{ | ||
|
||
if (!isset($params[$key])) { | ||
if ($default !== null) { | ||
return $default; | ||
} | ||
throw new \Exception("no params {$key}", common\ERROR::PARAM_ERROR); | ||
} | ||
|
||
$integer = isset($params[$key]) ? \intval($params[$key]) : 0; | ||
|
||
if ($abs) { | ||
$integer = \abs($integer); | ||
} | ||
|
||
if ($notEmpty && empty($integer)) { | ||
throw new \Exception('params no empty', common\ERROR::PARAM_ERROR); | ||
} | ||
|
||
return $integer; | ||
} | ||
|
||
protected function getString($params, $key, $default = null, $notEmpty = false) | ||
{ | ||
$params = (array)$params; | ||
if (!isset($params[$key])) { | ||
if (null !== $default) { | ||
return $default; | ||
} | ||
throw new \Exception("no params {$key}", common\ERROR::PARAM_ERROR); | ||
} | ||
|
||
$string = \trim($params[$key]); | ||
|
||
if (!empty($notEmpty) && empty($string)) { | ||
throw new \Exception('params no empty', common\ERROR::PARAM_ERROR); | ||
} | ||
|
||
return \addslashes($string); | ||
} | ||
|
||
protected function upload($uploaddir) { | ||
$tmp_name =$_FILES['file']['tmp_name']; // 文件上传后得临时文件名 | ||
$name =$_FILES['file']['name']; // 被上传文件的名称 | ||
$size =$_FILES['file']['size']; // 被上传文件的大小 | ||
$type =$_FILES['file']['type']; // 被上传文件的类型 | ||
$dir = $uploaddir.date("Ym"); | ||
@chmod($dir,0777);//赋予权限 | ||
@is_dir($dir) or mkdir($dir,0777); | ||
//chmod($dir,0777);//赋予权限 | ||
move_uploaded_file($_FILES['file']['tmp_name'],$dir."/".$name); | ||
$type = explode(".",$name); | ||
$type = @$type[1]; | ||
$date = date("YmdHis"); | ||
$rename = @rename($dir."/".$name,$dir."/".$date.".".$type); | ||
if($rename) | ||
{ | ||
return array( | ||
'url' => $dir."/".$date.".".$type, | ||
'name' => $name | ||
); | ||
} | ||
} | ||
} |
Oops, something went wrong.