forked from e1399579/autojs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path京东金融.js
167 lines (137 loc) · 3.96 KB
/
京东金融.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
auto();
var config = files.isFile("jd_config.js") ? require("jd_config.js") : {};
var default_config = {
password: "", // 锁屏密码
max_retry_times: 10, // 最大失败重试次数
timeout: 12000, // 超时时间:毫秒
};
if (typeof config !== "object") {
config = {};
}
var options = Object.assign(default_config, config); // 用户配置合并
start(options);
/**
* 开始运行
* @param options
*/
function start(options) {
// 子线程监听音量上键
threads.start(function () {
events.observeKey();
events.onceKeyDown("volume_up", function (event) {
storages.remove(source);
toastLog("停止脚本");
engines.stopAll();
exit();
});
});
var isScreenOn = device.isScreenOn(); // 屏幕是否点亮
if (!isScreenOn) {
log("唤醒");
device.wakeUp();
sleep(500);
}
this.checkModule();
var Robot = require("Robot.js");
var robot = new Robot(options.max_retry_times);
var jdFinancial = new JDFinancial(robot, options);
// 先打开APP,节省等待时间
threads.start(function () {
jdFinancial.openApp();
});
if (files.exists("Secure.js")) {
var Secure = require("Secure.js");
var secure = new Secure(robot, options.max_retry_times);
secure.openLock(options.password, options.pattern_size);
}
jdFinancial.launch();
jdFinancial.work();
exit();
}
/**
* 检查必要模块
*/
function checkModule() {
if (!files.exists("Robot.js")) {
throw new Error("缺少Robot.js文件,请核对第一条");
}
if (!files.exists("Secure.js") && context.getSystemService(context.KEYGUARD_SERVICE).inKeyguardRestrictedInputMode()) {
throw new Error("缺少Secure.js文件,请核对第一条");
}
}
function JDFinancial(robot, options) {
this.robot = robot;
options = options || {};
var settings = {
timeout: 12000,
max_retry_times: 10
};
this.options = Object.assign(settings, options);
this.package = "com.jd.jrapp";
this.openApp = function () {
toastLog("即将签到,按音量上键停止");
launch(this.package);
};
this.closeApp = function () {
this.robot.kill(this.package);
};
this.launch = function () {
var times = 0;
do {
if (this.doLaunch()) {
return;
} else {
times++;
this.closeApp();
this.openApp();
}
} while (times < this.options.max_retry_times);
toastLog("运行失败");
engines.stopAll();
exit();
};
this.doLaunch = function () {
sleep(1000);
var jump = text("跳过");
if (jump.exists()) {
jump.findOnce().click();
}
var me;
if (me = id("tv_fourth_icon").text("我").findOne(this.options.timeout)) {
return me.parent().click();
} else {
return false;
}
};
this.work = function () {
var success = false;
for (var times = 0;times < this.options.max_retry_times;times++) {
if (this.signIn()) {
success = true;
toastLog("签到成功");
break;
}
}
if (!success) {
toastLog("签到失败");
}
return false;
};
this.signIn = function() {
if (id("tv_item_label").textMatches(/已签\d+天/).exists()) return true;
var sign_in = text("签到");
if (!sign_in.exists()) return false;
if (!sign_in.findOnce().parent().click()) return false;
sleep(3000);
var btn;
var success;
if (btn = desc("签到领钢镚").findOne(this.options.timeout)) {
success = btn.click();
} else {
success = false;
}
this.robot.back();
sleep(1500);
return success;
};
}