-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.php
247 lines (215 loc) · 9.56 KB
/
index.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<?php
function post_request($url, $data, $referer = '') {
// Convert the data array into URL Parameters like a=b&foo=bar etc.
// $data = http_build_query($data);
// parse the given URL
$url = parse_url($url);
if ($url['scheme'] != 'http') {
return array(
'status' => 'err',
'error' => "Host must starts with http:// !!"
);
}
// extract host and path:
$host = $url['host'];
$path = $url['path'];
// open a socket connection on port 80 - timeout: 30 sec
$fp = fsockopen($host, 80, $errno, $errstr, 30);
if ($fp) {
// send the request headers:
fputs($fp, "POST $path HTTP/1.1\r\n");
fputs($fp, "Host: $host\r\n");
if ($referer != '')
fputs($fp, "Referer: $referer\r\n");
// fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-type: text/xml\r\n");
fputs($fp, "Content-length: " . strlen($data) . "\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $data);
$result = '';
while (!feof($fp)) {
// receive the results of the request
$result .= fgets($fp, 128);
}
} else {
return array(
'status' => 'err',
'error' => "$errstr ($errno)"
);
}
// close the socket connection:
fclose($fp);
// split the result header from the content
$result = explode("\r\n\r\n", $result, 2);
$header = isset($result[0]) ? $result[0] : '';
$content = isset($result[1]) ? $result[1] : '';
// return as structured array:
return array(
'status' => 'ok',
'header' => $header,
'content' => $content
);
}
if ('POST' == $_SERVER['REQUEST_METHOD']) {
// Submit those variables to the server
$post_data = "<xml>
<ToUserName><![CDATA[$_POST[ToUserName]]]></ToUserName>
<FromUserName><![CDATA[$_POST[FromUserName]]]></FromUserName>
<CreateTime>$_POST[CreateTime]</CreateTime>
<MsgType><![CDATA[$_POST[MsgType]]]></MsgType>
<Content><![CDATA[$_POST[Content]]]></Content>
<MsgId>$_POST[MsgId]</MsgId> </xml>";
// Send a request to example.com
$result = post_request($_POST['Host'], $post_data);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>虚拟微信调用</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="papa">
<!-- Le styles -->
<link href="assets/css/bootstrap.css" rel="stylesheet">
<link href="assets/css/responsive.css" rel="stylesheet">
<style type="text/css">
/* Footer
-------------------------------------------------- */
.footer {
text-align: center;
padding: 20px 0;
margin-top: 50px;
border-top: 1px solid #e5e5e5;
background-color: #f5f5f5;
}
.footer p {
margin-bottom: 0;
color: #777;
}
.footer-links {
margin: 10px 0;
}
.footer-links li {
display: inline;
padding: 0 2px;
}
.footer-links li:first-child {
padding-left: 0;
}
</style>
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<!-- Le fav and touch icons -->
<link rel="shortcut icon" href="assets/ico/favicon.png">
<script type="text/javascript">
</script>
</head>
<body data-spy="scroll" data-target=".bs-docs-sidebar">
<div style="height:50px;"></div>
<div class="container">
<div class="row">
<div class="span3 offset1">
<h3>虚拟微信调用</h3>
<form method="post">
<div class="control-group">
<label class="control-label" for="Host">Host</label>
<div class="controls">
<input type="text" name="Host" placeholder="Host" value="<?= isset($_POST['Host']) ? $_POST['Host'] : 'http://wx.tisa7.com/index.php' ?>">
</div>
</div>
<div class="control-group">
<label class="control-label" for="FromUserName">FromUserName</label>
<div class="controls">
<input type="text" name="FromUserName" placeholder="FromUserName" value="tisa007">
</div>
</div>
<div class="control-group">
<label class="control-label" for="ToUserName">ToUserName</label>
<div class="controls">
<input type="text" name="ToUserName" placeholder="ToUserName" value="alan">
</div>
</div>
<div class="control-group">
<label class="control-label" for="MsgType">MsgType</label>
<div class="controls">
<input type="text" name="MsgType" placeholder="text|voice|location" value="text">
</div>
</div>
<div class="control-group">
<label class="control-label" for="Content">Content</label>
<div class="controls">
<input type="text" name="Content" placeholder="Content" value="<?= isset($_POST['Content']) ? $_POST['Content'] : 'test content' ?>">
</div>
</div>
<div class="control-group">
<label class="control-label" for="CreateTime">CreateTime</label>
<div class="controls">
<input type="text" name="CreateTime" placeholder="CreateTime" value="<?= time() ?>">
</div>
</div>
<div class="control-group">
<label class="control-label" for="MsgId">MsgId</label>
<div class="controls">
<input type="text" name="MsgId" placeholder="MsgId" value="1234567890">
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn">提交</button>
</div>
</div>
</form>
</div>
<div class="span8">
<section id="forms">
<?php if (isset($result)) { ?>
<h3>调用结果</h3>
<?php if ($result['status'] == 'ok') { ?>
<pre class="prettyprint"><?= $result['header'] ?></pre>
<pre class="prettyprint"><?= htmlentities($result['content'], ENT_NOQUOTES, "utf-8") ?></pre>
<?php } else { ?>
<pre class="prettyprint"><?= $result['error'] ?></pre>
<?php } ?>
<?php } ?>
</section>
</div>
</div>
</div>
<!-- Footer
================================================== -->
<footer class="footer">
<div class="container">
<p>Code licensed under <a href="http://www.apache.org/licenses/LICENSE-2.0" target="_blank">Apache License v2.0</a></p>
<ul class="footer-links">
<li><a href="http://blog.tisa7.com">小猪爬爬</a></li>
<li class="muted">·</li>
<li><a href="http://weibo.com/u/2101388255">Alan微博</a></li>
</ul>
</div>
</footer>
<!-- Le javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="assets/js/jquery.js"></script>
<script src="assets/js/bootstrap-transition.js"></script>
<script src="assets/js/bootstrap-alert.js"></script>
<script src="assets/js/bootstrap-modal.js"></script>
<script src="assets/js/bootstrap-dropdown.js"></script>
<script src="assets/js/bootstrap-scrollspy.js"></script>
<script src="assets/js/bootstrap-tab.js"></script>
<script src="assets/js/bootstrap-tooltip.js"></script>
<script src="assets/js/bootstrap-popover.js"></script>
<script src="assets/js/bootstrap-button.js"></script>
<script src="assets/js/bootstrap-collapse.js"></script>
<script src="assets/js/bootstrap-carousel.js"></script>
<script src="assets/js/bootstrap-typeahead.js"></script>
<script src="assets/js/bootstrap-affix.js"></script>
<script src="assets/js/holder/holder.js"></script>
<script src="assets/js/google-code-prettify/prettify.js"></script>
<script src="assets/js/application.js"></script>
</body>
</html>