Last active
December 22, 2018 09:46
-
-
Save liuqinh2s/79ca611e612217ab03e2d9f953e2b6cd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/************************************************ | |
* | |
* 全局变量 | |
* | |
* 1. LOG 相关变量和函数 | |
* 2. 延时函数,控制点击速度,寻找最佳的速度,避免被支付宝限制 | |
* 3. 结束函数,自定义结束时候要执行的动作 | |
* 2. 路径和文件相关变量和函数 | |
* | |
************************************************/ | |
/************************************** | |
* LOG 相关变量和函数 | |
**************************************/ | |
/** | |
* TracePrint 日志等级 | |
*/ | |
Dim LOG_LEVEL | |
/** | |
* TracePrint 日志等级: | |
* VERBOSE | |
* DEBUG | |
* INFO | |
* WARN | |
* ERROR | |
* NOTHING | |
* 当 LOG_LEVEL = 0 时,所有类型日志都能输出 | |
* 当 LOG_LEVEL = 6 时,所有类型日志都不能输出 | |
* 当 0 < LOG_LEVEL < 6 时,大于等于 LOG_LEVEL 的日志都可以输出,小于 LOG_LEVEL 的日志不能输出 | |
*/ | |
Dim VERBOSE = 1 | |
Dim DEBUG = 2 | |
Dim INFO = 3 | |
Dim WARN = 4 | |
Dim ERROR = 5 | |
Dim NOTHING = 6 | |
/** | |
* VERBOSE 等级日志输出函数 | |
*/ | |
Function logV(tag, msg) | |
If VERBOSE >= LOG_LEVEL | |
TracePrint tag & msg | |
End If | |
End Function | |
/** | |
* DEBUG 等级日志输出函数 | |
*/ | |
Function logD(tag, msg) | |
If DEBUG >= LOG_LEVEL | |
TracePrint tag & msg | |
End If | |
End Function | |
/** | |
* INFO 等级日志输出函数 | |
*/ | |
Function logI(tag, msg) | |
If INFO >= LOG_LEVEL | |
TracePrint tag & msg | |
ShowMessage tag & msg | |
End If | |
End Function | |
/** | |
* WARN 等级日志输出函数 | |
*/ | |
Function logW(tag, msg) | |
If WARN >= LOG_LEVEL | |
TracePrint tag & msg | |
End If | |
End Function | |
/** | |
* ERROR 等级日志输出函数 | |
*/ | |
Function logE(tag, msg) | |
If ERROR >= LOG_LEVEL | |
TracePrint tag & msg | |
End If | |
End Function | |
/************************************** | |
* 延时函数 | |
* | |
* 功能:用于寻找最佳的速度,避免被支付宝限制 | |
**************************************/ | |
Dim DELAY_TIME = 3000 | |
Function delayFunction() | |
Delay DELAY_TIME | |
End Function | |
/************************************** | |
* 结束函数 | |
* | |
* 功能:自定义结束所需要执行的动作 | |
**************************************/ | |
Function endFunction(tag) | |
LogI tag, "脚本停止运行" | |
END_TIME = Now() | |
File.Append(RECORD_TIME_FILE, "结束时间:" & END_TIME & "\n") | |
EndScript | |
End Function | |
/************************************** | |
* 路径和文件相关变量和函数 | |
**************************************/ | |
/** | |
* 数据源 | |
*/ | |
Dim URL_NAME = "ec-hsd-1004" | |
/** | |
* 从什么时候开始跑的 | |
*/ | |
Dim START_TIME | |
/** | |
* 什么时候被限制 | |
*/ | |
Dim END_TIME | |
/** | |
* 记录时间文件 | |
*/ | |
Dim RECORD_TIME_FILE = "/sdcard/" & URL_NAME & "/recordTimeFile.txt" | |
/** | |
* 总共多少个电话号码 | |
*/ | |
Dim TOTAL_PHONE_NUMBER_COUNT | |
/** | |
* 已经跑了多少个电话号码 | |
*/ | |
Dim FINISH_PHONE_NUMBER_COUNT | |
/** | |
* 总电话数记录文件 | |
*/ | |
Dim TOTAL_PHONE_NUMBER_COUNT_FILE = "/sdcard/" & URL_NAME & "/totalPhoneNumberCountFile.txt" | |
/** | |
* 跑了多少个电话记录文件 | |
*/ | |
Dim FINISH_PHONE_NUMBER_COUNT_FILE = "/sdcard/" & URL_NAME & "/finishPhoneNumberCountFile.txt" | |
/** | |
* 有些手机号点搜索之后出现:账号无法访问或对方关闭了通过手机查找,这里把这些手机收集起来 | |
*/ | |
Dim EXCEPT_PHONE_FILE = "/sdcard/" & URL_NAME & "/ExceptPhoneFile.txt" | |
/** | |
* 手机号码存放文件,供按键精灵读取 | |
*/ | |
Dim PHONE_LIST_FILE = "/sdcard/" & URL_NAME & ".txt" | |
/** | |
* 从文件中读到数组里 | |
*/ | |
Dim PHONE_LIST_ARRAY = File.ReadLines(PHONE_LIST_FILE) | |
/** | |
* 截图保存路径 | |
*/ | |
Dim SNAPSHOT_PATH = "/sdcard/" & URL_NAME & "/dump/" | |
/** | |
* OCR需要的截图保存路径,PNG格式的不用于OCR | |
* | |
* - jpg格式的图片用于OCR,可以提高OCR的准确率 | |
* - png格式的图片仅供以后参考,不用于OCR | |
*/ | |
Dim JPG_STORE_PATH = "/sdcard/" & URL_NAME & "/dump/" | |
Dim PNG_STORE_PATH = "/sdcard/" & URL_NAME & "/dump/" & "withoutOCR/" | |
/** | |
* 初始化日志等级,时间,路径、文件 | |
*/ | |
Function init() | |
Dim tag = "[init Function: ]" | |
// 日志等级 | |
LOG_LEVEL = VERBOSE | |
// 判断路径是否存在 | |
Dim isDirExist | |
// SNAPSHOT_PATH | |
isDirExist=Dir.Exist(SNAPSHOT_PATH) | |
logV(tag, "snapshot isDirExist = " & isDirExist) | |
If isDirExist=0 Then | |
Dir.Create (SNAPSHOT_PATH) | |
Else | |
logV(tag, "截图存储路径已经存在") | |
End If | |
// JPG_STORE_PATH | |
isDirExist=Dir.Exist(JPG_STORE_PATH) | |
logV(tag, "jpg isDirExist = " & isDirExist) | |
If isDirExist=0 Then | |
logV(tag, "jpg路径不存在,创建之") | |
Dir.Create (JPG_STORE_PATH) | |
Else | |
logV(tag, "jpg存储路径已经存在") | |
End If | |
// PNG_STORE_PATH | |
isDirExist = Dir.Exist(PNG_STORE_PATH) | |
logV(tag, "png isDirExist = " & isDirExist) | |
If isDirExist=0 Then | |
logV(tag, "png路径不存在,创建之") | |
Dir.Create (PNG_STORE_PATH) | |
Else | |
logV(tag, "png存储路径已经存在") | |
End If | |
// 判断文件是否存在 | |
Dim str | |
// RECORD_TIME_FILE | |
str = File.Read(RECORD_TIME_FILE) | |
If IsNull(str) Then | |
File.Write(RECORD_TIME_FILE, "") | |
End If | |
// TOTAL_PHONE_NUMBER_COUNT_FILE | |
str = File.Read(TOTAL_PHONE_NUMBER_COUNT_FILE) | |
If IsNull(str) Then | |
str = File.LinesNumber(PHONE_LIST_FILE) | |
TOTAL_PHONE_NUMBER_COUNT = CInt(str) | |
logI(tag, "TOTAL_PHONE_NUMBER_COUNT" & TOTAL_PHONE_NUMBER_COUNT) | |
// 记录总共多少手机号 | |
File.Write TOTAL_PHONE_NUMBER_COUNT_FILE, str | |
End If | |
// FINISH_PHONE_NUMBER_COUNT_FILE | |
str = File.Read(FINISH_PHONE_NUMBER_COUNT_FILE) | |
If IsNull(str) Then | |
File.Write(FINISH_PHONE_NUMBER_COUNT_FILE, 0) | |
End If | |
// EXCEPT_PHONE_FILE | |
str = File.Read(EXCEPT_PHONE_FILE) | |
If IsNull(str) Then | |
File.Write(EXCEPT_PHONE_FILE, "") | |
End If | |
End Function | |
/** | |
* 转账按钮界面的所有操作都包装在这个函数里 | |
*/ | |
Function transfer(phoneNumber, itemNumber) | |
// 函数 tag | |
Dim tag = "[transfer Function]: " | |
// 有没有头像的转账按钮位置不同,所以只能通过颜色来判断位置 | |
Dim transferPointX, transferPointY | |
// 转账按钮界面的下边界 | |
Dim borderX, borderY | |
// 转账按钮界面的性别颜色 | |
Dim blueX, blueY, redX, redY, greenX, greenY, gender | |
Dim color | |
// 操作太过频繁的颜色 | |
Dim color7, color8 | |
// 账号存在异常的颜色 | |
Dim color4, color5 | |
// 操作上限颜色 | |
Dim color6 | |
// 今天操作太频繁了,请改天再来 | |
color=CmpColor(13, 1263, "626262", 1.0) | |
If color > -1 Then | |
logV(tag, "今天操作太频繁了,请改天再来") | |
SnapShot PNG_STORE_PATH & phoneNumber & "-" & CStr(itemNumber) & "-今日操作过多" & ".png" | |
Tap 545, 751 | |
Call endFunction(tag) | |
End If | |
// 性别这里总共有三种颜色,绿色代表公司,粉红代表女,蓝色代表男 | |
// 蓝色 | |
FindColor 27, 585, 709, 1268, "FA9B25", 0, 1.0, blueX, blueY | |
If blueX > -1 And blueY > -1 Then | |
gender = "man" | |
End If | |
// 粉红色 | |
FindColor 27, 585, 709, 1268, "7E59F6", 0, 1.0, redX, redY | |
If redX > -1 And redY > -1 Then | |
gender = "woman" | |
End If | |
// 绿色 | |
FindColor 27, 585, 709, 1268, "A1B112", 0, 1.0, greenX, greenY | |
If greenX > -1 And greenY > -1 Then | |
gender = "company" | |
End If | |
// 截图 | |
FindColor 27, 585, 709, 1268, "FFFFFF", 3, 1.0, borderX, borderY | |
If borderX > -1 And borderY > -1 Then | |
SnapShot PNG_STORE_PATH & phoneNumber & "-" & CStr(itemNumber) & "-" & gender & ".png", 27, 585, 709, borderY | |
End If | |
// 延长版 | |
delayFunction() | |
// 点击:转账 | |
FindColor 0, 507, 33, 972, "E98E10", 0, 1.0, transferPointX, transferPointY | |
logV(tag, "transferPointX=" & transferPointX & ",transferPointY=" & transferPointY) | |
If transferPointX > -1 And transferPointY > -1 Then | |
Tap transferPointX, transferPointY | |
logV(tag, "点击转账") | |
Delay 1000 | |
End If | |
logV(tag, "点击转账结束") | |
// 点击转账后,如果出现:操作太过频繁,请稍后再试 | |
color7 = CmpColor(13, 1263, "626262", 1.0) | |
color8 = CmpColor(136, 574, "FFFFFF", 1.0) | |
If color7 > -1 And color8 > -1 Then | |
SnapShot PNG_STORE_PATH & phoneNumber & "-" & CStr(itemNumber) & "-操作太过频繁" & ".png" | |
Tap 548, 758 | |
Delay 100 | |
// 开始返回一层 | |
KeyPress "Back" | |
Delay 1000 | |
Call endFunction(tag) | |
End If | |
logV(tag, "操作太过频繁验证通过") | |
// 点击转账后,如果账号存在异常 | |
color4 = CmpColor(13, 1263, "626262", 1.0) | |
color5 = CmpColor(168, 788, "FFFFFF", 1.0) | |
If color4 > -1 And color5>-1 Then | |
logV(tag, "账号存在异常") | |
SnapShot PNG_STORE_PATH & phoneNumber & "-" & CStr(itemNumber) & "-账号存在异常.png" | |
Tap 548, 759 | |
Delay 1000 | |
// 开始返回一层 | |
KeyPress "Back" | |
Delay 1000 | |
Else | |
logV(tag, "进入克服网络延迟") | |
// 克服网络延迟,循环等待 | |
// Dim returnColor = CmpColor(668, 713, "DDDDDD", 1.0) | |
// While returnColor <> 0 | |
// Delay 100 | |
// returnColor = CmpColor(668, 713, "DDDDDD", 1.0) | |
// Wend | |
color = CmpColor(35, 92, "E98E10", 1.0) | |
While color <> 0 | |
Delay 100 | |
color = CmpColor(35, 92, "E98E10", 1.0) | |
Wend | |
// 有个提示:对方长时间没用支付宝,把这个提示叉掉 | |
Tap 682, 179 | |
Delay 2000 | |
// 延长版 | |
delayFunction() | |
logV(tag, "叉掉点击验证") | |
// 去掉点击验证 | |
Dim verifyX, verifyY | |
FindColor 0, 236, 717, 258, "E98E10", 0, 1.0, verifyX, verifyY | |
If verifyX > -1 And verifyY > -1 Then | |
verifyX = verifyX - 2 | |
End If | |
logV(tag, "准备截图") | |
SnapShot JPG_STORE_PATH & phoneNumber & "-" & CStr(itemNumber) & "-verify.jpg", 0, 224, verifyX, 273 | |
// 开始返回(两层) | |
Tap 36, 91 | |
color = CmpColor(41, 92, "FFFFFF", 1.0) | |
While color <> 0 | |
Delay 100 | |
color = CmpColor(41, 92, "FFFFFF", 1.0) | |
Wend | |
// 延长版 | |
delayFunction() | |
Tap 36, 91 | |
color = CmpColor(40, 90, "E98E10", 1.0) | |
While color <> 0 | |
Delay 100 | |
color = CmpColor(40, 90, "E98E10", 1.0) | |
Wend | |
Delay 200 | |
logV tag, "返回两层" | |
// 延长版 | |
delayFunction() | |
End If | |
End Function | |
/** | |
* 1. 在导入联系人版本的支付宝脚本中,这个函数负责点击联系人电话之后的一切操作 | |
* 2. 在按键精灵自动搜索电话的版本的支付宝脚本中,这个函数负责点击搜索之后的一切操作 | |
*/ | |
Function clickPhone(positionX, positionY, phoneNumber) | |
// 函数 tag | |
Dim tag = "[clickPhone Function]: " | |
logV tag, "positionX=" & positionX & ", positionY=" & positionY | |
// 如果有多条记录,就要进入选择界面 | |
Dim color1=CmpColor(13, 1263, "646262", 0.9) | |
If color1 > -1 Then | |
logV(tag, "对应多个支付宝") | |
// 截取选择界面 | |
Dim leftTopX, leftTopY, rightBottomX, rightBottomY, itemColor, isSwipe, barColor | |
FindColor 0, 108, 63, 1259, "FFFFFF", 0, 1.00, leftTopX, leftTopY | |
FindColor 661, 108, 694, 1259, "FFFFFF", 2, 1.00, rightBottomX, rightBottomY | |
logV(tag, leftTopX & ", " & leftTopY & ", " & rightBottomX & ", " & rightBottomY) | |
If leftTopX > -1 And leftTopY > -1 And rightBottomX > -1 And rightBottomY > -1 Then | |
SnapShot PNG_STORE_PATH & phoneNumber & "-itemList.png", leftTopX, leftTopY, rightBottomX, rightBottomY | |
// 有些手机号对应9个支付宝,而界面只能容纳7个,如果多于6个item,itemColor这个位置就是纯白色 | |
itemColor = CmpColor(669, 1263, "FFFFFF", 1.0) | |
If itemColor > -1 Then | |
isSwipe = True | |
End If | |
// 选择记录,每个记录的单元格是恒定不变的,大概是x:620,y:151 | |
Dim itemNumber, itemHeight, clickX, clickY | |
itemNumber = (rightBottomY - leftTopY) / 151 | |
itemNumber = CInt(itemNumber) | |
itemHeight = (rightBottomY - leftTopY) / itemNumber | |
clickX = (rightBottomX - leftTopX) / 2 | |
logV(tag, "itemNumber = " & itemNumber) | |
For i = 0 To itemNumber - 1 Step 1 | |
logV(tag, "i = " & i) | |
// 如果不是第一次点,item界面是要重新点击才能获取的 | |
If Not (i = 0) Then | |
logV(tag, "如果不是第一次点,item界面是要重新点击才能获取的") | |
Tap positionX, positionY | |
// 点击搜索会有网络方面的延迟 | |
Dim color = CmpColor(56, 640, "FFFFFF", 1.0) | |
While color <> 0 | |
Delay 100 | |
color = CmpColor(56, 640, "FFFFFF", 1.0) | |
Wend | |
End If | |
// 点击item | |
clickY = leftTopY + i * itemHeight + itemHeight / 2 | |
Tap clickX, clickY | |
Delay 300 | |
color = CmpColor(41, 92, "FFFFFF", 1.0) | |
While color <> 0 | |
Delay 100 | |
color = CmpColor(41, 92, "FFFFFF", 1.0) | |
Wend | |
// 延长版 | |
delayFunction() | |
Call transfer(phoneNumber, i) | |
Next | |
If isSwipe = True Then | |
For i = 0 To 6 Step 1 | |
logV(tag, "i = " & i+7) | |
logV(tag, "如果不是第一次点,item界面是要重新点击才能获取的") | |
Tap positionX, positionY | |
// 点击搜索会有网络方面的延迟 | |
color = CmpColor(56, 640, "FFFFFF", 1.0) | |
While color <> 0 | |
Delay 100 | |
color = CmpColor(56, 640, "FFFFFF", 1.0) | |
Wend | |
Swipe 364, 1000, 364, 500 | |
Delay 1000 | |
// 点击item | |
clickY = leftTopY + i * itemHeight + itemHeight / 2 | |
Tap clickX, clickY | |
color = CmpColor(41, 92, "FFFFFF", 1.0) | |
While color <> 0 | |
Delay 100 | |
color = CmpColor(41, 92, "FFFFFF", 1.0) | |
Wend | |
// 延长版 | |
delayFunction() | |
Call transfer(phoneNumber, i+7) | |
Next | |
End If | |
End If | |
Else | |
logV(tag, "对应单个支付宝") | |
Call transfer(phoneNumber, 0) | |
End If | |
End Function | |
Function main() | |
// 初始化文件、路径、全局变量 | |
init | |
START_TIME = Now() | |
File.Append(RECORD_TIME_FILE, "开始时间:" & START_TIME & "\n") | |
// 函数 tag | |
Dim tag = "[main Function]: " | |
// 颜色 | |
Dim color | |
Dim color1 | |
Dim color2 | |
// 坐标 | |
Dim positionX, positionY | |
// 计数器,当前跑了多少个号码 | |
Dim count = File.Read(FINISH_PHONE_NUMBER_COUNT_FILE) | |
count = CInt(count) | |
logV(tag, "count = " & count) | |
// 输出日志信息 | |
Dim logStr | |
For Each element In PHONE_LIST_ARRAY | |
// 搜索框的叉,点击可以清除搜索框内容,这里检测搜索框的叉是否存在 | |
color = CmpColor(671, 91, "B8B8B8", 1.0) | |
logV(tag, "点叉颜色:" & color) | |
If color=0 Then | |
Tap 671, 91 | |
logV(tag, "点叉") | |
Delay 100 | |
End If | |
LogV(tag, CStr(element)) | |
Sys.SetClipText (element) | |
// 长按出现粘贴 | |
Touch 369, 90, 50 | |
Delay 500 | |
// 延长版 | |
delayFunction() | |
// 点击粘贴 | |
Tap 161, 175 | |
Delay 300 | |
// 点击搜索 | |
positionX = 315 | |
positionY = 203 | |
Tap positionX, positionY | |
Delay 1500 | |
// 延长版 | |
delayFunction() | |
// 账号无法访问 | |
color = CmpColor(12, 513, "FFFFFF", 1.0) | |
color1 = CmpColor(535, 763, "E98E10", 1.0) | |
color2 = CmpColor(140, 610, "FFFFFF", 1.0) | |
If color = -1 and color1 = 0 and color2 = 0 Then | |
File.Append(EXCEPT_PHONE_FILE, element & "\n") | |
Tap 535, 763 | |
Delay 1000 | |
Goto final | |
End If | |
// 操作太频繁 | |
color = CmpColor(12, 513, "FFFFFF", 1.0) | |
color1 = CmpColor(535, 763, "E98E10", 1.0) | |
color2 = CmpColor(140, 610, "FFFFFF", 1.0) | |
If color = -1 and color1 = 0 and color2=-1 Then | |
Tap 535, 763 | |
Delay 1000 | |
EndScript | |
End If | |
// 点击搜索会有网络方面的延迟 | |
color = CmpColor(56, 640, "FFFFFF", 1.0) | |
While color <> 0 | |
Delay 100 | |
color = CmpColor(56, 640, "FFFFFF", 1.0) | |
Wend | |
clickPhone(positionX, positionY, element) | |
/** | |
* 这一段进行一些处理,包括: | |
* 1. 删除已经跑完的一条手机号 | |
* 2. 在手机界面弹出Toast显示还剩多少个手机号没跑完 | |
* 3. 把还剩多少个手机号没跑数记录到文件中 | |
*/ | |
Rem final | |
File.DeleteLine PHONE_LIST_FILE, 1 | |
logStr = "还剩多少个手机号:" & File.LinesNumber(PHONE_LIST_FILE) | |
logI(tag, logStr) | |
count = count + 1 | |
File.Write FINISH_PHONE_NUMBER_COUNT_FILE, count | |
// 用于调试 | |
FINISH_PHONE_NUMBER_COUNT = count | |
TOTAL_PHONE_NUMBER_COUNT = File.ReadLine(TOTAL_PHONE_NUMBER_COUNT_FILE, 1) | |
logV tag, "FINISH_PHONE_NUMBER_COUNT = " & FINISH_PHONE_NUMBER_COUNT | |
logV tag, "TOTAL_PHONE_NUMBER_COUNT = " & TOTAL_PHONE_NUMBER_COUNT | |
logI(tag, logStr) | |
Next | |
End Function | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment