compile.php
3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
require_once dirname(__FILE__).'/../db/DbMysqli.class.php';
require_once dirname(__FILE__).'/keyword.class.php';
$host = str_replace("www.",'',$_SERVER['HTTP_HOST']);
$urls = array(
'wap'=>'http://wap.'.$host.'/BASE/util/keyword/compile.php',
'android'=>'http://android.'.$host.'BASE/util/keyword/compile.php',
'html5'=>'http://s.'.$host.'/BASE/util/keyword/compile.php',
'iphone'=>'http://iphone.'.$host.'/BASE/util/keyword/compile.php'
);
if(isset($_POST['params']))
{
$params = json_decode($_POST['params'], true);
$actionName = $params['actionName'];
$moduleID = intval($params['moduleID']);
$moduleKey = $params['moduleKey'];
}
else
{
exit();
}
error_log($_POST['params'],3,dirname(__FILE__).'/log.log');
$dictionaryDIR = '';
//模块
switch($actionName)
{
case 'nickName':
$dictionaryDIR = 'nickName';
break;
case 'register':
$dictionaryDIR = 'register';
break;
case 'chat':
$dictionaryDIR = '';
break;
case 'test':
$dictionaryDIR = 'test';
break;
default:
$dictionaryDIR = 'test';
break;
//exit();
}
$dictionaryDIR = dirname(__FILE__).'/cache/'.$dictionaryDIR;
require $dictionaryDIR.'/dictionary.php';
$DBConn = new DbMysqli();
$keyword = new keyword();
$sql =" SELECT module_key FROM oss_module";
$sql.= " WHERE id=".$moduleID;
$dbModuleKey = $DBConn->getOne($sql);
//如果密钥是否相等
if(strcmp($dbModuleKey, $moduleKey)!=0)
{
exit();
}
$updateTime = $keyword->readOver($dictionaryDIR.'/updateTime.txt');
$startPos = 0;
$length = 100;
while(true)
{
$sql = " SELECT keyword, key_type, up_time FROM oss_module_keyword";
$sql.= " WHERE module_id=".$moduleID;
$sql.= " AND up_time>='$updateTime' ";
$sql.=" ORDER BY up_time DESC ";
$sql.=" LIMIT $startPos, $length";
$DBWords = $DBConn->getAll($sql);
if(empty($DBWords))
{
break;
}
else
{
$updateTime = $DBWords[count($DBWords)-1][2];
$startPos+=$length;
}
$words = array();
$adds = array(
PROHIBITION_STATE =>0,
REPLACE_STATE =>0,
CHECK_STATE =>0,
);
foreach($DBWords as $word)
{
$type = intval($word[1]);
$keywordValue = $word[0];
$add = $adds[$type]++;
$words[$type][$add] = $keywordValue;
}
if(!isset($dictionaryWords))
{
$dictionaryWords = array();
}
$dictionaryWords = $keyword->compileWord($words, $dictionaryWords);
$keyword->writeDictionaryFile($dictionaryWords, $dictionaryDIR.'/dictionary.php');
}
$params = array(
'actionName'=> $actionName,
'moduleID'=> $moduleID,
'moduleKey'=> $moduleKey,
'updateTime'=>$updateTime
);
foreach($urls as $key=>$url)
{
$result = connect($url, json_encode($params));
if(intval($result))
{
echo $key;
}
}
$keyword->writeOver($dictionaryDIR.'/updateTime.txt',$updateTime);
//清除key值
$sql = "UPDATE oss_module SET module_key='' where id=".$moduleID;
$DBConn->update($sql);
unset($DBConn);
function connect($url, $params)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);//seconds
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS, 'params='.$params);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
?>