Exemple #1
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();
	}
Exemple #2
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();
	}
Exemple #3
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;
 }
Exemple #4
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;
}
Exemple #5
0
	/**
	 * 获取系统日志实例
	 * @return SystemLog
	 */
	public static function getSystemLog () {
		if (!self::$SYS_LOG){
			include_once SUISHI_PHP_PATH . '/Log/SystemLog.class.php';
			$obj = new SystemLog();
			$obj->setLogFormat(SystemLog::FORMAT_JSON);
			$obj->setLogpath(SuiShiPHPConfig::getSysLogDir());
			self::$SYS_LOG = $obj;
		}
		return self::$SYS_LOG;
	}
	public static function init() {
		self::$TEMPLATE_PATH = realpath(LIB_PATH . SuiShiPHPConfig::TEMPLATE_DIR . SuiShiPHPConfig::get('APP_GROUP')) . '/';
	}
	/**
	 * 获取db配置
	 * @param string $dbName
	 * @param string
	 */
	static function setDbConfig($config) {
		if (!$config || !is_array($config)) return;
		self::$DB_CONFIGS = $config;
	}
	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;
	}
	/**
	 * 初始化配置数据
	 * @param  $config
	 */
	public static function init ($config) {
		SuiShiPHPConfig::setArray($config);
		// set php log
		$phpLogDir = SuiShiPHPConfig::getPhpLogDir();
		if ($phpLogDir) {
			if (is_dir ( $phpLogDir)) {
				if (! is_writable ( $phpLogDir )) {
					trigger_error ( "set php log path is not writable: " . $phpLogDir, E_USER_WARNING);
				} else {
					//设置php log 路径文件
					ini_set("error_log",$phpLogDir. date('Y-m-d') . ".log");
				}
			} else {
				if (! @mkdir ( $phpLogDir, 0777, true )) {
					trigger_error ( "create php log path error: " . $phpLogDir, E_USER_WARNING);
				} else {
					//设置php log 路径文件
					ini_set("error_log",$phpLogDir. date('Y-m-d') . ".log");
				}
			}
		}
		HttpRequest::init();
		Logger::init();
		Template::init();
	}