-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_task.js
More file actions
197 lines (118 loc) · 4.76 KB
/
test_task.js
File metadata and controls
197 lines (118 loc) · 4.76 KB
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
//console.log('测试写出日志'); //输出日志
//$notification.post('title标题', 'subTitle子标题子标题子标题','body内容内容内容内容') //用于通知栏提醒
//惠头条邀请码 51830362
var $iosrule = iosrule();//声明必须
var app = "惠头条";
var rdurl = $iosrule.read("rdurl");
var wzbd = $iosrule.read("wzbd");
var spbd = $iosrule.read("spbd");
var xspbd = $iosrule.read("xspbd");
task();
function task() {
setTimeout(function () {
wz();
}, 1 * 100);
setTimeout(function () {
sp();
}, 33 * 1000);
setTimeout(function () {
xsp();
}, 66 * 1000);
}
//文章阅读
function wz() {
const llUrl1 = { url: rdurl,headers: { "Content-Type": "application/json"}, body: xgbd(wzbd) };
$iosrule.post(llUrl1, function (error, response, data) {
console.log("[文章阅读返回数据]:" + data);
var obj = JSON.parse(data);
if (obj.statusCode == 200) {
console.log("[文章阅读金币奖励]:" + obj.incCredit );
$iosrule.notify(app,"[文章阅读金币奖励]:" + obj.incCredit,"");
}else{
console.log("[文章阅读失败]:" + obj.statusCode );
$iosrule.notify(app,"[文章阅读失败]:" + obj.statusCode,"");
}
})
}
function sp() {
var nbd = xgbd(spbd);
const llUrl1 = { url: rdurl,headers: { "Content-Type": "application/json"}, body: nbd };
$iosrule.post(llUrl1, function (error, response, data) {
console.log("[视频阅读返回数据]:" + data);
var obj = JSON.parse(data);
if (obj.statusCode == 200) {
console.log("[视频阅读金币奖励]:" + obj.incCredit );
$iosrule.notify(app,"[视频阅读金币奖励]:" + obj.incCredit,"");
}else{
console.log("[视频阅读失败]:" + obj.statusCode );
$iosrule.notify(app,"[视频阅读失败]:" + obj.statusCode,"");
}
})
}
function xsp() {
var nbd = xgbd(spbd);
const llUrl1 = { url: rdurl,headers: { "Content-Type": "application/json"}, body: nbd };
$iosrule.post(llUrl1, function (error, response, data) {
console.log("[小视频阅读返回数据]:" + data);
var obj = JSON.parse(data);
if (obj.statusCode == 200) {
console.log("[小视频阅读金币奖励]:" + obj.incCredit );
$iosrule.notify(app,"[小视频阅读金币奖励]:" + obj.incCredit,"");
}else{
console.log("[小视频阅读失败]:" + obj.statusCode );
$iosrule.notify(app,"[小视频阅读失败]:" + obj.statusCode,"");
}
})
}
function xgbd(bd) {
if (JSON.parse(bd).hasOwnProperty("token")) {
bd = JSON.parse(bd); delete bd["token"]; bd = JSON.stringify(bd);
return bd;
}
else
return bd;
}
function iosrule() {
const isRequest = typeof $request != "undefined"
const isSurge = typeof $httpClient != "undefined"
const isQuanX = typeof $task != "undefined"
const notify = (title, subtitle, message) => {
if (isQuanX) $notify(title, subtitle, message)
if (isSurge) $notification.post(title, subtitle, message)
}
const write = (value, key) => {
if (isQuanX) return $prefs.setValueForKey(value, key)
if (isSurge) return $persistentStore.write(value, key)
}
const read = (key) => {
if (isQuanX) return $prefs.valueForKey(key)
if (isSurge) return $persistentStore.read(key)
}
const get = (options, callback) => {
if (isQuanX) {
if (typeof options == "string") options = { url: options }
options["method"] = "GET"
$task.fetch(options).then(response => {
response["status"] = response.statusCode
callback(null, response, response.body)
}, reason => callback(reason.error, null, null))
}
if (isSurge) $httpClient.get(options, callback)
}
const post = (options, callback) => {
if (isQuanX) {
if (typeof options == "string") options = { url: options }
options["method"] = "POST"
$task.fetch(options).then(response => {
response["status"] = response.statusCode
callback(null, response, response.body)
}, reason => callback(reason.error, null, null))
}
if (isSurge) $httpClient.post(options, callback)
}
const end = () => {
if (isQuanX) isRequest ? $done({}) : ""
if (isSurge) isRequest ? $done({}) : $done()
}
return { isRequest, isQuanX, isSurge, notify, write, read, get, post, end }
};