-
Notifications
You must be signed in to change notification settings - Fork 0
/
interface.php
104 lines (86 loc) · 2.88 KB
/
interface.php
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
<?php
include dirname(__FILE__).'/interface_define.php';
include dirname(__FILE__).'/src/log/logger.php';
include dirname(__FILE__).'/src/utils/handler_define.php';
include dirname(__FILE__).'/src/utils/error_code.php';
include dirname(__FILE__).'/src/utils/elapsedTime.php';
error_reporting(0);
register_shutdown_function('handleFatalPhpError');
function handleFatalPhpError() {
$last_error = error_get_last();
if($last_error['type'] === E_ERROR) {
logger::error("handleFatalPhpError:".print_r($last_error, true), "php_error");
echo response::format(ERROR_PARAMS, "php fatal error")."\n";
}
}
$params = $_GET;
$data = $_POST;
//$dddd = $_REQUEST;
//var_dump($dddd);
logger::write("request:".json_encode($params)."\n"."data:".print_r($data, true), "interface");
if (!isset($params['handler']) || !isset($params['findex']))
{
logger::error("request error".json_encode($params)."\n".print_r($data, true), "interface");
echo response::format(ERROR_PARAMS, "interface request error")."\n";
}
$function = $GLOBALS["handlers"][$params["handler"]][$params["findex"]];
logger::write("handle func name : ".$function, "interface");
$timer = new elapsedTime($function."_".$params["findex"]);
$packet = array();
if (isset($data['json_data'])) {
$json_data = $data['json_data'];
// echo "json:".$json_data."\n";
// echo "encode:".urldecode($json_data)."\n";
//$json_data = addslashes($json_data);
//$json_data = ltrim($json_data, "\"");
//$json_data = rtrim($json_data, "\"");
$packet = json_decode(urldecode($json_data), true);
if (is_null($packet)) {
logger::error("packet parse error", "interface");
echo response::format(ERROR_PARAMS, "packet parse error")."\n";
}
}
logger::write("request packet:".print_r($packet, true), "interface");
$handler = NULL;
if ($params["handler"] === "account" ) {
include account;
$handler = new account();
}
else if ($params["handler"] === "message" ) {
include message;
$handler = new message();
}
else if ($params["handler"] === "friend" ) {
include friend;
$handler = new friend();
}
else if ($params["handler"] === "mail" ) {
include mail;
$handler = new mail();
}
else if ($params["handler"] === "chapter" ) {
include chapter;
$handler = new chapter();
}
else if ($params["handler"] === "seaVentureMgr" ) {
include seaVentureMgr;
$handler = new seaVentureMgr();
}
else if ($params["handler"] === "seaVenture" ) {
include seaVenture;
$handler = new seaVenture();
}
else if ($params["handler"] === "chapterMgr" ) {
include chapterMgr;
$handler = new chapterMgr();
}
else
{
logger::error("request handler error".json_encode($params), "interface");
return response::format(ERROR_PARAMS, "handler error");
}
$result = $handler->process($function, $packet);
//var_dump(error_get_last());
logger::debug("request success: ".$result, "interface");
echo $result."\n";
?>