From a98a43cb8ce02da72f372d501ad6883e5356a806 Mon Sep 17 00:00:00 2001 From: v-Brocloni Date: Tue, 10 Aug 2021 17:07:58 +0800 Subject: [PATCH] 1 --- Config/DataBaseConfig.class.php | 132 ++++++++++++++++++++++++++++++++++++++++ Config/目录结构说明.txt | 1 + Public/目录结构说明.txt | 1 + Utils/sinaUtils.class.php | 98 +++++++++++++++++++++++++++++ Utils/util.class.php | 102 +++++++++++++++++++++++++++++++ Utils/目录结构目录.txt | 1 + 6 files changed, 335 insertions(+) create mode 100644 Config/DataBaseConfig.class.php create mode 100644 Config/目录结构说明.txt create mode 100644 Public/目录结构说明.txt create mode 100644 Utils/sinaUtils.class.php create mode 100644 Utils/util.class.php create mode 100644 Utils/目录结构目录.txt diff --git a/Config/DataBaseConfig.class.php b/Config/DataBaseConfig.class.php new file mode 100644 index 0000000..7b07306 --- /dev/null +++ b/Config/DataBaseConfig.class.php @@ -0,0 +1,132 @@ +MYSQL_HOST . ";port=" . $this->MYSQL_PORT . ";dbname=" . $this->MYSQL_DB, $this->MYSQL_USER, $this->MYSQL_PASSWORD, array(PDO::MYSQL_ATTR_INIT_COMMAND => "set names utf8")); + return $pdo; + } catch (PDOException $e) { + zzcsUtils::writeLog('new PDO failed:' . $e->getMessage()); + } + } + + /** + * 链接测试数据库 + * @return PDO + */ + function conn_test() + { + try { + $pdo = new PDO("mysql:host=" . $this->MYSQL_HOST1 . ";port=" . $this->MYSQL_PORT1 . ";dbname=" . $this->MYSQL_DB1, $this->MYSQL_USER1, $this->MYSQL_PASSWORD1, array(PDO::MYSQL_ATTR_INIT_COMMAND => "set names utf8")); + return $pdo; + } catch (PDOException $e) { + zzcsUtils::writeLog('new PDO failed:' . $e->getMessage()); + } + } + + /** + * 链接waice数据库 + * @return PDO + */ + function conn_waice() + { + try { + $pdo = new PDO("mysql:host=" . $this->MYSQL_HOST2 . ";port=" . $this->MYSQL_PORT2 . ";dbname=" . $this->MYSQL_DB2, $this->MYSQL_USER2, $this->MYSQL_PASSWORD2, array(PDO::MYSQL_ATTR_INIT_COMMAND => "set names utf8")); + return $pdo; + } catch (PDOException $e) { + zzcsUtils::writeLog('new PDO failed:' . $e->getMessage()); + } + } + + /** + * 添加缓存 + * @param $key + * @param $value + */ + public function set_memcache($key, $value) + { + $mem = new Memcache; + $mem->connect($this->MEMCACHE_HOST, $this->MEMCACHE_PORT); + $mem->set($key, $value); + } + + /** + * 获取内存中的数据 + * @param $key + * @return array|string + */ + public function get_memcache($key) + { + $mem = new Memcache; + $mem->connect($this->MEMCACHE_HOST, $this->MEMCACHE_PORT); + $value = $mem->get($key); + return $value; + } + + /** + * 删除键值对应的数据 + * @param $key + * @return bool + */ + public function delete_memcache($key) + { + $mem = new Memcache; + $mem->connect($this->MEMCACHE_HOST, $this->MEMCACHE_PORT); + $value = $mem->delete($key); + return $value; + } + +} \ No newline at end of file diff --git a/Config/目录结构说明.txt b/Config/目录结构说明.txt new file mode 100644 index 0000000..59bb21f --- /dev/null +++ b/Config/目录结构说明.txt @@ -0,0 +1 @@ +ļ磺ݿļ \ No newline at end of file diff --git a/Public/目录结构说明.txt b/Public/目录结构说明.txt new file mode 100644 index 0000000..e287864 --- /dev/null +++ b/Public/目录结构说明.txt @@ -0,0 +1 @@ +Դļ繫õjsimagescss \ No newline at end of file diff --git a/Utils/sinaUtils.class.php b/Utils/sinaUtils.class.php new file mode 100644 index 0000000..b5b1ea8 --- /dev/null +++ b/Utils/sinaUtils.class.php @@ -0,0 +1,98 @@ +SINA_APPKEY . '&url_long=' . $long_url; + //获取请求结果 + $result = curlQuery($url); + //下面这行注释用于调试, + //print_r($result);exit(); + //解析json + $json = json_decode($result); + //异常情况返回false + if (isset($json->error) || !isset($json[0]->url_short) || $json[0]->url_short == '') + return false; + else + return $json[0]->url_short; + } + +//根据短网址获取长网址,此函数重用了不少sinaShortenUrl中的代码,以方便你阅读对比,你可以自行合并两个函数 + function sinaExpandUrl($short_url) + { + //拼接请求地址,此地址你可以在官方的文档中查看到 + $url = 'http://api.t.sina.com.cn/short_url/expand.json?source=' . $this->SINA_APPKEY . '&url_short=' . $short_url; + //获取请求结果 + $result = curlQuery($url); + //下面这行注释用于调试 + //print_r($result);exit(); + //解析json + $json = json_decode($result); + //异常情况返回false + if (isset($json->error) || !isset($json[0]->url_long) || $json[0]->url_long == '') + return false; + else + return $json[0]->url_long; + } + +} \ No newline at end of file diff --git a/Utils/util.class.php b/Utils/util.class.php new file mode 100644 index 0000000..6df75a3 --- /dev/null +++ b/Utils/util.class.php @@ -0,0 +1,102 @@ +