-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
105 lines (78 loc) · 2.17 KB
/
index.js
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
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var bodyParser = require("body-parser");
var log4js = require("log4js");
var wechat = require("wechat");
var numlist = {
"1":"勇哥真帅!",
"2":"再创佳绩",
"3":"老虎机",
"4":"炸金花威武",
"5":"斗牛威武",
"6":"麻将威武",
"7":"德州威武",
"8":"大家加油!"
}
var shortText = "";
for(var i in numlist){
shortText += "发送["+i+"] "+numlist[i.toString()]+"\n";
}
console.log(shortText);
log4js.configure("log4js.json");
var logger = log4js.getLogger("logInfo");
app.use(bodyParser.urlencoded({extended: false}));
//get/post 访问方法一样
app.use(function (req, res, next) {
if (req.method == "GET") {
req.body = req.query;
}
next();
})
app.get('/input.html', function (req, res) {
res.sendFile(__dirname + '/input.html');
});
app.get('/client.html', function (req, res) {
console.log("readfile:client.html")
res.sendFile(__dirname + '/client.html');
});
app.get('/socket.io-1.2.0.js', function (req, res) {
res.sendFile(__dirname + '/socket.io-1.2.0.js');
});
app.use('/baina', wechat("baina", wechat.text(function (message, req, res, next) {
// { ToUserName: 'gh_6d72c20eb836',
// FromUserName: 'o-8wiwkwWxP4KQamySqMdlKEP7NE',
// CreateTime: '1460950280',
// MsgType: 'text',
// Content: '你好',
// MsgId: '6274733674086114390' }
logger.info(message.Content);
var showText = message.Content;
var longText = numlist[showText];
if (longText){
showText = longText;
}
io.emit("dm", showText);
res.reply(shortText);
})));
app.get('/sendmsg', function (req, res) {
var msg = req.body.msg;
io.emit('dm', msg);
res.send("success");
})
app.post("/sendwx", function (req, res) {
})
app.post("/*", function (req, res) {
console.log(req)
})
app.get("/*", function (req, res) {
console.log(req.url)
})
io.on('connection', function (socket) {
socket.on('dm', function (msg) {
io.emit('dm', msg);
});
});
http.listen(80, function () {
console.log('listening on *:80');
});