@@ -0,0 +1,132 @@ | |||
<?php | |||
/** | |||
* Created by PhpStorm. | |||
* User: Steven | |||
* Date: 2016/10/12 | |||
* Time: 10:56 | |||
*/ | |||
require_once ROOT_PATH . '/ZZBS/Utils/util.class.php'; | |||
defined('DOMAIN') or define('DOMAIN', 'zhizhuchuxing.com'); | |||
defined('CS_DOMAIN') or define('CS_DOMAIN', 'cs.'. DOMAIN); | |||
defined('CS1_DOMAIN') or define('CS1_DOMAIN', 'cs1.'. DOMAIN); | |||
class DataBaseConfig | |||
{ | |||
//正式数据库 | |||
private $MYSQL_HOST = "180.168.4.58"; | |||
private $MYSQL_USER = "root"; | |||
private $MYSQL_PASSWORD = "123456"; | |||
private $MYSQL_DB = "ctsdata"; | |||
private $MYSQL_PORT = "8090"; | |||
//测试数据库 | |||
private $MYSQL_HOST1 = "180.168.4.58"; | |||
private $MYSQL_USER1 = "root"; | |||
private $MYSQL_PASSWORD1 = "123456"; | |||
private $MYSQL_DB1 = "ctsdata_test"; | |||
private $MYSQL_PORT1 = "8090"; | |||
/*//原waice数据库 | |||
private $MYSQL_HOST2 = "180.168.4.58"; | |||
private $MYSQL_USER2 = "spider"; | |||
private $MYSQL_PASSWORD2 = "PjGPWNUgOYe6i1Ef"; | |||
private $MYSQL_DB2 = "waice"; | |||
private $MYSQL_PORT2 = "8090";*/ | |||
//新waice数据库【迁移到新服务器的主数据库】 | |||
private $MYSQL_HOST2 = "106.14.56.77"; | |||
private $MYSQL_USER2 = "spider"; | |||
private $MYSQL_PASSWORD2 = "PjGPWNUgOYe6i1Ef"; | |||
private $MYSQL_DB2 = "ctsdata"; | |||
private $MYSQL_PORT2 = "3306"; | |||
//Memcache配置 | |||
private $MEMCACHE_HOST = "139.224.30.29"; | |||
private $MEMCACHE_PORT = "11211"; | |||
private $MEMCACHE_USER = "memcached"; | |||
private $API_GPS_ACCOUNT = "15618818219"; | |||
private $API_GPS_PASSWORD = "123456"; | |||
/** | |||
* 链接正式数据库 | |||
* @return PDO | |||
*/ | |||
function conn() | |||
{ | |||
try { | |||
$pdo = new PDO("mysql:host=" . $this->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; | |||
} | |||
} |
@@ -0,0 +1 @@ | |||
核心配置文件:例如:数据库配置文件 |
@@ -0,0 +1 @@ | |||
公共资源文件:例如公用的js、images、css |
@@ -0,0 +1,98 @@ | |||
<?php | |||
/** | |||
* Created by PhpStorm. | |||
* User: Steven | |||
* Date: 2016/10/12 | |||
* Time: 11:19 | |||
*/ | |||
require_once 'util.class.php'; | |||
class sinaUtils | |||
{ | |||
private $SINA_APPKEY = "31641035";//Sina App_Key | |||
//获取请求结果 | |||
function curlQuery($url) | |||
{ | |||
//设置附加HTTP头 | |||
$addHead = array( | |||
"Content-type: application/json" | |||
); | |||
//初始化curl,当然,你也可以用fsockopen代替 | |||
$curl_obj = curl_init(); | |||
//设置网址 | |||
curl_setopt($curl_obj, CURLOPT_URL, $url); | |||
//附加Head内容 | |||
curl_setopt($curl_obj, CURLOPT_HTTPHEADER, $addHead); | |||
//是否输出返回头信息 | |||
curl_setopt($curl_obj, CURLOPT_HEADER, 0); | |||
//将curl_exec的结果返回 | |||
curl_setopt($curl_obj, CURLOPT_RETURNTRANSFER, 1); | |||
//设置超时时间 | |||
curl_setopt($curl_obj, CURLOPT_TIMEOUT, 15); | |||
//执行 | |||
$result = curl_exec($curl_obj); | |||
//关闭curl回话 | |||
curl_close($curl_obj); | |||
return $result; | |||
} | |||
//简单处理下url,sina对于没有协议(http://)开头的和不规范的地址会返回错误 | |||
function filterUrl($url = '') | |||
{ | |||
$url = trim(strtolower($url)); | |||
$url = trim(preg_replace('/^http:\//', '', $url)); | |||
if ($url == '') | |||
return false; | |||
else | |||
return urlencode('http://' . $url); | |||
} | |||
//根据长网址获取短网址 | |||
function sinaShortenUrl($long_url) | |||
{ | |||
$access_url = "https://api-ssl.bitly.com/v3/shorten?access_token=" . BITACCESSTOKEN . "&longUrl=" . $long_url; | |||
$result = utils::httpRequest($access_url); | |||
$return_result = json_decode($result, true); | |||
if ($return_result["status_code"] == 200) { | |||
$url = $return_result["data"]["url"]; | |||
$return_url = str_replace("http://", "https://", $url); | |||
return $return_url; | |||
} else { | |||
return false; | |||
} | |||
//拼接请求地址,此地址你可以在官方的文档中查看到 | |||
$url = 'http://api.t.sina.com.cn/short_url/shorten.json?source=' . $this->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; | |||
} | |||
} |
@@ -0,0 +1,102 @@ | |||
<?php | |||
/** | |||
* Created by PhpStorm. | |||
* User: Steven | |||
* Date: 2016/10/8 | |||
* Time: 17:01 | |||
* | |||
* Class utils 公共工具类 | |||
*/ | |||
class utils | |||
{ | |||
/** | |||
*创建日记类 | |||
* @param $log log内容 | |||
*/ | |||
/* static function writeLog($log) | |||
{ | |||
$dir = __DIR__ . "/../Log/"; | |||
if (!is_dir($dir)) { | |||
mkdir($dir); | |||
} | |||
$filename = $dir . date("Y-m-d") . ".log"; | |||
file_put_contents($filename, date("Y-m-d H:i:s") . "\t" . $log . PHP_EOL, FILE_APPEND); | |||
}*/ | |||
static function httpRequest($url, $data = null) | |||
{ | |||
$ch = curl_init(); | |||
curl_setopt($ch, CURLOPT_URL, $url); | |||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); | |||
if (!empty($data)) { | |||
curl_setopt($ch, CURLOPT_POST, 1); | |||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); | |||
} | |||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |||
$output = curl_exec($ch); | |||
curl_close($ch); | |||
return $output; | |||
} | |||
/** | |||
* 发送HTTP请求 | |||
* @param $url | |||
* @param array $param | |||
* @return mixed | |||
* @throws Exception | |||
*/ | |||
static function httpsPost($url, $param = array()) | |||
{ | |||
$ch = curl_init(); // 初始化一个 cURL 对象 | |||
curl_setopt($ch, CURLOPT_URL, $url); // 设置需要抓取的URL | |||
curl_setopt($ch, CURLOPT_HEADER, 0); // // 设置header | |||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // 设置cURL 参数,要求结果保存到字符串中还是输出到屏幕上。 | |||
// 如果你想PHP去做一个正规的HTTP POST,设置这个选项为一个非零值。这个POST是普通的 application/x-www-from-urlencoded 类型,多数被HTML表单使用。 | |||
curl_setopt($ch, CURLOPT_POST, 1); | |||
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($param)); // 传递一个作为HTTP “POST”操作的所有数据的字符串。//http_build_query:生成 URL-encode 之后的请求字符串 | |||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); | |||
curl_setopt($ch, CURLOPT_HTTPHEADER, array( | |||
'Content-type:application/x-www-form-urlencoded;charset=utf-8' | |||
)); | |||
$rtn = curl_exec($ch); // 运行cURL,请求网页 | |||
if ($errno = curl_errno($ch)) { | |||
throw new Exception ('Curl Error(' . $errno . '):' . curl_error($ch)); | |||
} | |||
curl_close($ch); // 关闭URL请求 | |||
return $rtn; // 返回获取的数据 | |||
} | |||
/** | |||
* 发送短信 | |||
* @param $phones 电话号码 | |||
* @param $user_name 用户名称 | |||
* @param $content 短信内容 | |||
* @param $order_id 订单号 | |||
* @return array|mixed | |||
*/ | |||
static function sendTelMessage($phones, $user_name, $content, $order_id) | |||
{ | |||
$send_data = array(); | |||
$send_data["cdkey"] = "8SDK-EMY-6699-RISUM"; | |||
$send_data["password"] = "175348"; | |||
$send_data["phone"] = $phones; | |||
$send_data["message"] = '【蜘蛛行】' . $content; | |||
if (SEND_MESSAGE == true) { | |||
//$url='http://www.mxtong.net.cn/GateWay/Services.asmx/DirectSend?UserID=995596&Account=alert&Password=zzcx8888&Phones='.$phones.'&Content='.$content.'【蜘蛛行】&SendTime=&SendType=1&PostFixNumber='; | |||
$url = 'http://hprpt2.eucp.b2m.cn:8080/sdkproxy/sendsms.action'; | |||
//echo $url; | |||
$response = httpRequest($url, $send_data); | |||
// echo $response;die(); | |||
writeLog('url' . $url . "返回值" . $response); | |||
} else { | |||
return array("未开启短信通知"); | |||
} | |||
return $response; | |||
} | |||
} |
@@ -0,0 +1 @@ | |||
该目录为核心公共函数 |