commit | author | age
|
3e083b
|
1 |
<?php |
B |
2 |
|
|
3 |
/** |
|
4 |
* 在线客服聊天系统前端请求转发拦截器 |
|
5 |
*/ |
|
6 |
define('IN_ECS', true); |
|
7 |
|
|
8 |
require (dirname(__FILE__) . '/includes/init.php'); |
|
9 |
|
|
10 |
// file_put_contents("D:/php.debug", |
|
11 |
// var_export(file_get_contents("php://input")."\n", true), FILE_APPEND); |
|
12 |
|
|
13 |
// 获取页面提交的数据 |
|
14 |
$input = file_get_contents("php://input"); |
|
15 |
|
|
16 |
if(empty($input)) |
|
17 |
{ |
|
18 |
print(''); |
|
19 |
return; |
|
20 |
} |
|
21 |
|
|
22 |
// 解析消息 |
|
23 |
$xml = simplexml_load_string($input); |
|
24 |
|
|
25 |
if(! empty($xml->response)) |
|
26 |
{ |
|
27 |
$response = $xml->response; |
|
28 |
$response_plain = base64_decode($response); |
|
29 |
|
|
30 |
// $response_plain = str_replace('==from==', $_SESSION['OF_FROM'], |
|
31 |
// $response_plain); |
|
32 |
$response_plain = str_replace('==to==', $_SESSION['OF_TO'], $response_plain); |
|
33 |
|
|
34 |
$xml->response = base64_encode($response_plain); |
|
35 |
|
|
36 |
// file_put_contents("D:/php.debug", $response_plain, FILE_APPEND); |
|
37 |
|
|
38 |
$input = $xml->asXML(); |
|
39 |
|
|
40 |
// 根据用户名称判断当前用户是否为此用户并且是否已经登录 |
|
41 |
|
|
42 |
// 判断此用户是否已经注册,未注册则需要先到聊天服务器进行注册 |
|
43 |
} |
|
44 |
else if(! empty($xml->message)) |
|
45 |
{ |
|
46 |
$message = $xml->message; |
|
47 |
$message->attributes()->from = $_SESSION['OF_FROM']; |
|
48 |
$message->attributes()->to = $_SESSION['OF_TO']; |
|
49 |
$message->body = $message->body; |
|
50 |
|
|
51 |
$input = $xml->asXML(); |
|
52 |
|
|
53 |
// file_put_contents("D:/php.debug", |
|
54 |
// var_export($xml."--->>>".$_SESSION['OF_TO']."--->>>".$_SESSION['OF_FROM'], |
|
55 |
// true), FILE_APPEND); |
|
56 |
} |
|
57 |
else |
|
58 |
{ |
|
59 |
$input = $xml->asXML(); |
|
60 |
} |
|
61 |
|
|
62 |
$_CFG = $GLOBALS['_CFG']; |
|
63 |
$of_ip = $_CFG['chat_server_ip']; |
|
64 |
$http_bind_port = $_CFG['chat_http_bind_port']; |
|
65 |
|
|
66 |
$of_url = "http://$of_ip:$http_bind_port/http-bind/"; |
|
67 |
|
|
68 |
// 初始化curl |
|
69 |
$ch = curl_init(); |
|
70 |
// 抓取指定网页 |
|
71 |
curl_setopt($ch, CURLOPT_URL, $of_url); |
|
72 |
// 设置header |
|
73 |
curl_setopt($ch, CURLOPT_HEADER, 0); |
|
74 |
// 要求结果为字符串且输出到屏幕上 |
|
75 |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
|
76 |
// post提交方式 |
|
77 |
curl_setopt($ch, CURLOPT_POST, 1); |
|
78 |
// 提交的数据 |
|
79 |
curl_setopt($ch, CURLOPT_POSTFIELDS, $input); |
|
80 |
// 运行curl |
|
81 |
$data = curl_exec($ch); |
|
82 |
// 关闭 |
|
83 |
curl_close($ch); |
|
84 |
|
|
85 |
//file_put_contents("D:/php.debug", $of_url."\n".$data."\n", FILE_APPEND); |
|
86 |
|
|
87 |
// 输出结果 |
|
88 |
print_r($data); |
|
89 |
|
|
90 |
?> |