-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrule_default_success.js
151 lines (130 loc) · 4.46 KB
/
rule_default_success.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
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
'use strict';
module.exports = {
summary: 'the default rule for AnyProxy',
/**
*
*
* @param {object} requestDetail
* @param {string} requestDetail.protocol
* @param {object} requestDetail.requestOptions
* @param {object} requestDetail.requestData
* @param {object} requestDetail.response
* @param {number} requestDetail.response.statusCode
* @param {object} requestDetail.response.header
* @param {buffer} requestDetail.response.body
* @returns
*/
*beforeSendRequest(requestDetail) {
return null;
},
/**
*
*
* @param {object} requestDetail
* @param {object} responseDetail
*/
*beforeSendResponse(requestDetail, responseDetail) {
try{
// function nextPageCallback(reponse){
// // 修改响应到客户端的数据 response 为注入的js
// console.log('回调' + reponse)
// if (reponse == "None"){
// return responseDetail.response;
// }else{
// return reponse + return responseDetail.response;
// }
// }
var next_page = ''
if(/mp\/profile_ext\?action=home/i.test(requestDetail.url) || /mp\/profile_ext\?action=getmsg/i.test(requestDetail.url)){ //文章列表 包括html格式和json格式
next_page = httpPost(responseDetail.response.body.toString(), "/wechat/get_article_list", requestDetail.url);
}
else if(/\/s\?__biz=/i.test(requestDetail.url) || /mp\/appmsg\/show\?__biz=/i.test(requestDetail.url) || /\/mp\/rumor/i.test(requestDetail.url)){ //文章内容;mp/appmsg/show?_biz 为2014年老版链接; mp/rumor 是不详实的文章
next_page = httpPost(responseDetail.response.body.toString(), "/wechat/get_article_content", requestDetail.url);
}
else if (/mp\/getappmsgext/i.test(requestDetail.url)){ // 阅读量 观看量
next_page = httpPost(responseDetail.response.body.toString(), "/wechat/get_read_watched_count", requestDetail.requestData.toString());
}
else if (/mp\/appmsg_comment/i.test(requestDetail.url)){ // 评论列表
next_page = httpPost(responseDetail.response.body.toString(), "/wechat/get_comment", requestDetail.url);
}
else if (/http:\/\/localhost:6210\/tip/i.test(requestDetail.url)){ // 本地提示界面
next_page = httpPost(responseDetail.response.body.toString(), "/wechat/tip", requestDetail.url);
}
console.log('------------next_page')
console.log(next_page)
}catch(e){
console.log(e);
}
return null;
},
/**
* default to return null
* the user MUST return a boolean when they do implement the interface in rule
*
* @param {any} requestDetail
* @returns
*/
*beforeDealHttpsRequest(requestDetail) {
return null;
},
/**
*
*
* @param {any} requestDetail
* @param {any} error
* @returns
*/
*onError(requestDetail, error) {
return null;
},
/**
*
*
* @param {any} requestDetail
* @param {any} error
* @returns
*/
*onConnectError(requestDetail, error) {
return null;
},
};
// 发送数据到自己的服务端
function httpPost(data, actionMethod, reqUrl) {
console.log('发送数据到服务端')
console.log(reqUrl)
const deasync = require("deasync");
let newBody, isReturn = false;
var http = require('http');
var data = {
data:data,
req_url:reqUrl
};
var content = require('querystring').stringify(data);
var options = {
method: "POST",
host: "localhost", //注意没有http://,这是服务器的域名。
port: 6210,
path: actionMethod, //处理请求的action
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
"Content-Length": content.length
}
};
var req = http.request(options, function (res) {
res.setEncoding('utf8');
res.on('data', function (chunk) { // chunk 为假时不触发回调
console.log('BODY: ' + chunk);
newBody = chunk
isReturn = true;
});
});
req.on('error', function (e) {
console.log('problem with request: ' + e.message);
});
req.write(content);
req.end();
while(!isReturn){
deasync.runLoopOnce();
}
return newBody;
}