Exemplo n.º 1
0
	/**
	 * 验证通过后运行数据层
	 */
	protected static function _run()
	{
		$actionName = SuiShiPHPConfig::getAction();
		$method = SuiShiPHPConfig::getMethod();

		define("__ACTION_NAME__", $actionName);
		define("__ACTION_METHOD__", $method);
		define("__APP_GROUP__", SuiShiPHPConfig::getAppGroup());

		if (SuiShiPHPConfig::getAppGroup()) {
			$actionName = SuiShiPHPConfig::getAppGroup() . '.' . $actionName;
		}
		$action = loadAction($actionName);
		
		if (! $action || ! method_exists($action, $method)) {
			if (SuiShiPHPConfig::get('DEBUGGING') === true) {
				Logger::error('_run error: action not exist, action: '.__ACTION_NAME__.', method: '.__ACTION_METHOD__,
				HttpRequest::get());
				throw new Exception('action not exist, action: '.__ACTION_NAME__.', method: '.__ACTION_METHOD__);
			} else {
				Logger::error('_run error: action not exist, action: '.__ACTION_NAME__.', method: '.__ACTION_METHOD__,
				HttpRequest::get());
				myExit(); //TODO () 转向到404 页面
			}
		}
		
		$action->$method(HttpRequest::get());
	}
Exemplo n.º 2
0
	public function __construct($host, $user, $password, $dbname , $connect = false,
			$charset = 'utf8') {
		parent::__construct($host, $user, $password, $dbname , $connect = false,
			$charset = 'utf8');

		$this->logDir = SuiShiPHPConfig::getSqlLogDir();
		$this->logSql = SuiShiPHPConfig::get('ENABLE_SQL_LOG');
		//初始化log file
		$this->iniLogConfig();
	}
Exemplo n.º 3
0
	public static function init () {
		self::setLogDir(SuiShiPHPConfig::getLogDir());
		self::enabled(SuiShiPHPConfig::get('ENABLE_RUN_LOG'));
		self::setLogLevel(SuiShiPHPConfig::get('RUN_LOG_LEVEL'));
		parent::init();
	}
Exemplo n.º 4
0
  /**
  +----------------------------------------------------------
  * 是否AJAX请求
  +----------------------------------------------------------
  * @access protected
  +----------------------------------------------------------
  * @return bool
  +----------------------------------------------------------
  */
 protected function isAjax()
 {
     if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) ) {
         if('xmlhttprequest' == strtolower($_SERVER['HTTP_X_REQUESTED_WITH'])) {
             return true;
         }
     }
     $ajax = trim($this->getParam(SuiShiPHPConfig::get('VAR_AJAX_SUBMIT')));
     if($ajax) {
         // 判断Ajax方式提交
         return true;
     }
     return false;
 }
Exemplo n.º 5
0
/**
 * 获取微信ticket
 *
 * @param string $appId
 * @param string $appSercet
 * @param bool $refresh  如果cache中不存在是否刷新cache
 * @return string
 */
function getJsApiTicket($appId, $appSecret, $type = 'jsapi', $refresh = true) {
	$type = in_array($type, array('jsapi', 'wx_card')) ? $type : 'jsapi';
	if ('jsapi' == $type) {
		$cacherId = SuiShiPHPConfig::get('WX_JS_API_TICKET') . $appId;
	} else {
		$cacherId = SuiShiPHPConfig::get('WX_CARD_API_TICKET') . $appId;
	}

	$cacher = new RedisCache(SuiShiPHPConfig::get('REDIS_HOST_TOKEN'), SuiShiPHPConfig::get('REDIS_PORT_TOKEN'));
	$ticket = $cacher->get ( $cacherId );
	//TODO test
	//$token = '2FsxZXKoX6NAS9eV28UIZQz3YwoPXvBf2Gjr1O8bNl9nzKBpZub7_1zZ4gsWC1_LdzcwAJ7lW9oWLDghMWXvAn3w3Gcj63pX7ljpHprqCUE';
	if (true !== $refresh) {
		return $ticket;
	}
	if (! $ticket) {
		// 引入微信api
		if (! class_exists ( "WeiXinClient" )) {
			include_once dirname ( __FILE__ ) . "/../API/WeiXinApiCore.class.php";
		}
		$token = getToken($appId, $appSecret);
		$weixnApi = WeiXinApiCore::getClient ( $appId, $appSecret, $token);
		$ticket = $weixnApi->getJsApiTicket ($type);
		if ($ticket) {
			$cacher->set ( $cacherId, $ticket, 6600/*一小时50分钟*/);
		}
	}
	return $ticket;
}
Exemplo n.º 6
0
	/**
	 * 获取缓存类
	 * @param string $type
	 * @return FileCache | RedisCache
	 */
	public static function getCacher ($type = '', $model = '') {
		$type or $type = C('DEFAULT_CACHER');
		if (!in_array($type, array('redis', 'file', 'remote'))) {
			$type = 'redis';
		}
		//如果不是正式服务上,不是用redis缓存
		if (false == SuiShiPHPConfig::get('PUBLIC_SERVICE') && 'redis' == $type) {
			$type = 'file';
		}
		$cacheId = $type.$model;
		if (isset(self::$CACHER[$cacheId])) {
			return self::$CACHER[$cacheId];
		}

		switch ($type) {
			case 'file':
				if (!class_exists("FileCache")) {
					include_once SUISHI_PHP_PATH . '/Cache/FileCache.class.php';
				}
				$c = new FileCache(C('RUN_SHELL'));
				$c->setModel($model);
				$c->setPath(SuiShiPHPConfig::getFileCacheDir());
				self::$CACHER[$cacheId] = $c;
				break;
			case 'remote':
				if (!class_exists("FileCache")) {
					include_once SUISHI_PHP_PATH . '/Cache/RemoteCacher.class.php';
				}
				$c = new RemoteCacher(C('REMOTE_CACHE_HOST'), C('REMOTE_CACHE_PORT'), 'weixinapp');
				self::$CACHER[$cacheId] = $c;
				break;
			default:
				if (!class_exists("RedisCache")) {
					include_once SUISHI_PHP_PATH . '/Cache/RedisCache.class.php';
				}
				$c = new RedisCache(SuiShiPHPConfig::get('REDIS_HOST'), SuiShiPHPConfig::get('REDIS_PORT'));
				self::$CACHER[$cacheId] = $c;
				break;
		}
		return self::$CACHER[$cacheId];
	}
Exemplo n.º 7
0
	public static function init() {
		self::$TEMPLATE_PATH = realpath(LIB_PATH . SuiShiPHPConfig::TEMPLATE_DIR . SuiShiPHPConfig::get('APP_GROUP')) . '/';
	}
Exemplo n.º 8
0
	public function getJsApiTicket($type = 'jsapi')
	{
		$type = in_array($type, array('jsapi', 'wx_card')) ? $type : 'jsapi';
		if ('jsapi' == $type) {
			$cacherId = SuiShiPHPConfig::get('WX_JS_API_TICKET') . $this->appId;
		} else {
			$cacherId = SuiShiPHPConfig::get('WX_CARD_API_TICKET') . $this->appId;
		}
		
		$cacher = new RedisCache(SuiShiPHPConfig::get('REDIS_HOST_TOKEN'), SuiShiPHPConfig::get('REDIS_PORT_TOKEN'));
		$ticket = $cacher->get ( $cacherId );
		
		if (! $ticket) {
			$token = $this->_getAccessToken();
			if (! $token) {
				return false;
			}
			// 引入微信api
			if (! class_exists ( "WeiXinClient" )) {
				include_once dirname ( __FILE__ ) . "/../API/WeiXinApiCore.class.php";
			}
			$weixinApi = WeiXinApiCore::getClient ($this->appId, $this->appSecret, $token);
			$ticket = $weixinApi->getJsApiTicket($type);
			if ($ticket) {
				$cacher->set ($cacherId, $ticket, 7000/*一小时56分钟*/);
			}
		}
		return $ticket;
	}