-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhttp-bind.php
executable file
·92 lines (70 loc) · 2.18 KB
/
http-bind.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
<?php
/**
* 在线客服聊天系统前端请求转发拦截器
* $Author: 倪庆洋
*/
define('IN_ECS', true);
require (dirname(__FILE__) . '/includes/init.php');
// file_put_contents("D:/php.debug",
// var_export(file_get_contents("php://input")."\n", true), FILE_APPEND);
// 获取页面提交的数据
$input = file_get_contents("php://input");
if(empty($input))
{
print('');
return;
}
// 解析消息
$xml = simplexml_load_string($input);
if(! empty($xml->response))
{
$response = $xml->response;
$response_plain = base64_decode($response);
// $response_plain = str_replace('==from==', $_SESSION['OF_FROM'],
// $response_plain);
$response_plain = str_replace('==to==', $_SESSION['OF_TO'], $response_plain);
$xml->response = base64_encode($response_plain);
// file_put_contents("D:/php.debug", $response_plain, FILE_APPEND);
$input = $xml->asXML();
// 根据用户名称判断当前用户是否为此用户并且是否已经登录
// 判断此用户是否已经注册,未注册则需要先到聊天服务器进行注册
}
else if(! empty($xml->message))
{
$message = $xml->message;
$message->attributes()->from = $_SESSION['OF_FROM'];
$message->attributes()->to = $_SESSION['OF_TO'];
$message->body = $message->body;
$input = $xml->asXML();
// file_put_contents("D:/php.debug",
// var_export($xml."--->>>".$_SESSION['OF_TO']."--->>>".$_SESSION['OF_FROM'],
// true), FILE_APPEND);
}
else
{
$input = $xml->asXML();
}
$_CFG = $GLOBALS['_CFG'];
$of_ip = $_CFG['chat_server_ip'];
$of_port = $_CFG['chat_server_port'];
$of_url = "http://$of_ip:$of_port/http-bind/";
// 初始化curl
$ch = curl_init();
// 抓取指定网页
curl_setopt($ch, CURLOPT_URL, $of_url);
// 设置header
curl_setopt($ch, CURLOPT_HEADER, 0);
// 要求结果为字符串且输出到屏幕上
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// post提交方式
curl_setopt($ch, CURLOPT_POST, 1);
// 提交的数据
curl_setopt($ch, CURLOPT_POSTFIELDS, $input);
// 运行curl
$data = curl_exec($ch);
// 关闭
curl_close($ch);
// file_put_contents("D:/php.debug", $data."\n", FILE_APPEND);
// 输出结果
print_r($data);
?>