local function trimRN(str) --linux 上去除\r换行符,读取问题多是有符号和空格的原因 if str == nil then return nil,"the string parameter is nil" end -- str = string.gsub(str, " ", "") str = string.gsub(str,"\r","") str = string.gsub(str,"\n","") return str end function readFile(path)--读取txt文档 local file = io.open(path,"r"); if file then local _list = {}; for line in file:lines() do str = string.gsub(line,"\r","") str = string.gsub(str,"\n","") if str~=nil and str~="" and str~="\r\n" then table.insert(_list,trimRN(str)) --nLog('++'..trimRN(line)..'--'); nLog("数据正常:"..str.."###") else nLog("数据为空:"..str) end end file:close(); return _list end end function ButtonClick(x,y,name)--按钮点击 if x>-1 and y>-1 then nLog("--------已找到:"..name..",x:"..x.." y:"..y); touchDown(x, y); --在 (150, 550) 按下 mSleep(30); touchUp(x, y); else nLog("--------找不到按钮:"..name..",x:"..x.." y:"..y); end end function FindNeedAddCustomer()--添加按钮点击 --查找添加按钮 --mSleep(1 * 1000); x3,y3 = findMultiColorInRegionFuzzy( 0xdfdfdf, "8|-19|0xdfdfdf,116|-15|0xf5f5f5,116|39|0xdfdfdf,53|40|0xdfdfdf,47|29|0xf8f8f8,45|6|0x353535,52|5|0xf8f8f8,63|11|0x9e9e9e,67|14|0xf8f8f8", 90, 0, 0, 719, 1279) nLog("x3:"..x3.." y3:"..y3); ButtonClick(x3,y3,"添加好友"); end local function writeFile(fileName,content) --输出文本到txt local f = assert(io.open(fileName,'a')) f:write(content.."\r\n") f:close() end ---返回到微信的home界面 function backHome()--返回至主界面 mSleep(500) b=1; while(b>0) do b=0 xQue,yQue = findMultiColorInRegionFuzzy( 0xffffff, "6|7|0xcfeecf,10|10|0x1aad19,16|11|0x83d383,25|9|0xffffff,25|0|0xffffff,34|3|0xa5dfa5,35|9|0xffffff,35|19|0x32b631,39|18|0xfbfdfa", 90, 0, 0, 719, 1279) if xQue>-1 and yQue>-1 then b=b+1; ButtonClick(xQue,yQue,"确定按钮");--如果有确定按钮就确定 end mSleep(3000) xBack,yBack=findMultiColorInRegionFuzzy( 0xffffff, "-5|0|0xdadadb,2|-2|0xdadbdc,6|-2|0x393a3f,8|0|0xffffff,23|1|0xffffff,26|1|0xceced0,27|0|0x393a3f,11|15|0xf3f3f4,11|16|0x5e5f63", 90, 0, 0, 719, 1279) if xBack>-1 and yBack>-1 then b=b+1; ButtonClick(xBack,yBack,"返回按钮");--如果有返回按钮点击返回 end mSleep(500) xBack,yBack=findMultiColorInRegionFuzzy( 0xffffff, "-5|0|0xdadadb,2|-2|0xdadbdc,6|-2|0x393a3f,8|0|0xffffff,23|1|0xffffff,26|1|0xceced0,27|0|0x393a3f,11|15|0xf3f3f4,11|16|0x5e5f63", 90, 0, 0, 719, 1279) if xBack>-1 and yBack>-1 then b=b+1; ButtonClick(xBack,yBack,"返回按钮");--如果有返回按钮点击返回 end end mSleep(3 * 1000); end function Split(szFullString, szSeparator) local nFindStartIndex = 1 local nSplitIndex = 1 local nSplitArray = {} while true do local nFindLastIndex = string.find(szFullString, szSeparator, nFindStartIndex) if not nFindLastIndex then nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, string.len(szFullString)) break end nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, nFindLastIndex - 1) nFindStartIndex = nFindLastIndex + string.len(szSeparator) nSplitIndex = nSplitIndex + 1 end return nSplitArray end function unloackJM() flag = deviceIsLock(); --如果要在设备自启动时解锁屏幕直接使用 unlockDevice 函数即可 if flag == 0 then nLog("未锁定") else nLog("锁定了,正在解锁屏幕") unlockDevice(); --解锁屏幕 nLog("解锁OK。。。") end end function unloackLM() unlockDevice(); --解锁屏幕 end local function urlEncode(s) s = string.gsub(s, "([^%w%.%- ])", function(c) return string.format("%%%02X", string.byte(c)) end) return string.gsub(s, " ", "+") end local function urlDecode(s) s = string.gsub(s, '%%(%x%x)', function(h) return string.char(tonumber(h, 16)) end) return s end list = readFile('/storage/emulated/0/WeiXinCrmLua/ResPhone.txt'); if list ==nil then nLog("====找不到文件,退出脚本=====") lua_exit(); --否则退出脚本 mSleep(10) return end; addPhone={}; addPhone2={}; mlgb=0; time = getNetTime(); nLog(os.date("%Y-%m-%d %H:%M:%S",time)) for key, var in ipairs(list) do mlgb=mlgb+1; if mlgb<11 then --nLog('通讯录+++key:'..key..",var:"..var) alist=Split(var,",") vailmsg=alist[4] x={lastname="",firstname=alist[3],mobile=alist[2]}; y={pici=alist[1],vailmsg=vailmsg,firstname=alist[3],mobile=alist[2]}; table.insert(addPhone,mlgb,x) table.insert(addPhone2,mlgb,y) end end if mlgb==0 then nLog("====无数据,退出脚本=====") lua_exit(); --否则退出脚本 mSleep(10) return end; mSleep(3000) --removeAllContactsFromAB();--清除通讯录 mSleep(5000) time2 = getNetTime(); nLog(os.date("%Y-%m-%d %H:%M:%S",time2)) for _,v in ipairs(addPhone) do --nLog("通讯录添加:"..v) addContactToAB(v) nLog(v.firstname) end nLog("通讯录添加成功!") mSleep(5000) ---通讯录添加成功 nLog("=======解锁屏幕1========") unloackJM() mSleep(2000) nLog("=======解锁屏幕2========") unloackLM()--再次判定是否锁屏 r = runApp("com.tencent.mm") --启动微信 nLog("启动微信") logfile="/storage/emulated/0/WeiXinCrmLua/phonelog.txt"; i=0; backHome();---返回到主界面 mSleep(300) firstx,firsty = findMultiColorInRegionFuzzy( 0xafafaf, "1|7|0x979797,0|3|0xefefef,1|3|0xfcfcfc,4|11|0xfdfdfd,12|29|0x999999,6|28|0xfdfdfd,4|24|0xa9a9a9,13|40|0x9c9c9c,24|24|0x989898", 90, 0, 0, 719, 1279) ButtonClick(firstx,firsty,"微信栏");--点击主界面的微信栏目 mSleep(500) xisC,yisC = findMultiColorInRegionFuzzy( 0xf4b4b2, "1|0|0xe26865,0|9|0xe4736f,-1|13|0xfff8f8,2|23|0xffe8e5,17|2|0xffe7e5,42|-1|0x5e5c5d,41|14|0x94908f,48|10|0xebe1e0,55|8|0x5c5b59", 90, 0, 0, 719, 1279) if xisC>-1 and yisC>-1 then nLog("========毛网络,脚本退出========") lua_exit(); --否则退出脚本 mSleep(10) end mSleep(5000) --ax,ay = findMultiColorInRegionFuzzy( 0x9f9f9f, "-1|6|0xfcfcfc,13|12|0x999999,21|10|0xfcfcfc,22|12|0x999999,15|-15|0xfcfcfc,18|-20|0xbebebe,26|0|0x999999,26|-5|0xfcfcfc,26|-8|0x999999", 90, 0, 0, 719, 1279) ax,ay = findMultiColorInRegionFuzzy( 0xd5d5d5, "-3|0|0xafafaf,8|1|0xfefefe,9|2|0x969696,19|2|0x969696,19|5|0xfefefe,-9|23|0xcccccc,-13|19|0x9a9a9a,-11|31|0xaeaeae,-4|30|0xfcfcfc", 90, 0, 0, 719, 1279) ButtonClick(ax,ay,"通讯录");--点击主界面的通讯录栏目,然后等待一分钟 mSleep(60*1000) unloackJM()--如果一分钟内界面锁定,自行解锁 x1,y1=findMultiColorInRegionFuzzy( 0xffffff, "-7|-8|0x393a3f,-19|-1|0xceced0,-19|1|0xa9a9ab,18|0|0xceced0,1|3|0xffffff,2|-3|0x393a3f,-4|2|0x393a3f,-3|-18|0x393a3f,-1|-2|0xffffff", 90, 0, 0, 719, 1279) ButtonClick(x1,y1,"右上角加号");--点击右上角加号 mSleep(1000) x2,y2=findMultiColorInRegionFuzzy( 0xceced0, "8|0|0xffffff,14|3|0x393a3f,15|16|0xffffff,18|11|0xe6e6e7,19|5|0x393a3f,20|-1|0xcdcdcf,31|-1|0xcdcdcf,32|2|0xfefefe,32|5|0x393a3f", 90, 0, 0, 719, 1279) ButtonClick(x2,y2,"添加朋友菜单");--点击添加朋友 mSleep(1000); x3,y3 = findMultiColorInRegionFuzzy( 0xfa9d3b, "22|1|0xffffff,34|-2|0xfa9d3b,33|13|0xfdd5aa,35|17|0xfa9d3b,47|26|0xfa9d3b,43|29|0xffffff,52|1|0xfa9d3b,46|21|0xffffff,43|34|0xfeeddb", 90, 0, 0, 719, 1279) ButtonClick(x3,y3,"手机联系人按钮");--点击手机联系人 mSleep(1000); --x4,y4 = findMultiColorInRegionFuzzy( 0x4ec326, "0|4|0x4ec326,-1|25|0xffffff,18|21|0xffffff,22|28|0xd2f0c8,31|38|0xa6e192,39|33|0xffffff,39|30|0xffffff,0|18|0x58c632,-1|12|0x4ec326", 90, 0, 0, 719, 1279) --ButtonClick(x4,y4,"手机联系人??");--点击添加手机联系人 mSleep(10000);--停顿10s,显示手机联系人可能会久一点 --switchTSInputMethod(true); for key, nn in ipairs(addPhone2) do var=nn.firstname pici=nn.pici vailmsgx=urlDecode(nn.vailmsg) nLog('key='..key.. ',value='..var..'--') mSleep(3000) x5,y5 = findMultiColorInRegionFuzzy( 0x393a3f, "-11|-1|0xd9dadb,-13|4|0xffffff,-11|6|0xfefefe,-3|16|0xffffff,20|24|0x848487,17|20|0xffffff,13|11|0x45464b,-4|8|0x393a3f,11|-1|0x848487", 90, 0, 0, 719, 1279) ButtonClick(x5,y5,"放大镜搜索");--点击放大镜,搜索联系人 mSleep(1000) x6,y6 = findMultiColorInRegionFuzzy( 0x6b6b6f, "-3|-4|0x4c4d51,-9|-10|0x4c4d51,2|-1|0x6b6b6f,6|-1|0x4c4d51,11|1|0x393a3f,12|7|0x6b6b6f,12|11|0x4c4d51,1|3|0x4c4d51,3|3|0x393a3f", 90, 0, 0, 719, 1279) ButtonClick(x6,y6,"删除文字");--点击删除文字 -- mSleep(500);--延迟 1 秒以便获取焦点,注意某些应用不获取焦点无法输入 -- for var = 1,15 do -- inputText("\b") --删除输入框中的文字(假设输入框中已存在文字) -- end mSleep(1000); inputText(var); --在输入框中输入字符串"Welcome."并回车;此函数在某些应用中无效,如支付宝、密码输入框等位置,甚至可能会导致目标应用闪退 mSleep(3000);--等待搜索 --switchTSInputMethod(false); --无结果 x7,y7 = findMultiColorInRegionFuzzy( 0x888888, "13|2|0x979798,17|1|0xadafb2,47|-2|0xb3b5b8,54|10|0xced2d7,56|2|0xced2d7,77|8|0x888888,88|13|0x888888,77|-11|0x888888,75|-5|0x888888", 90, 0, 0, 719, 1279) --有添加按钮 x8,y8 = findMultiColorInRegionFuzzy( 0xffffff, "-3|8|0x2ab329,11|8|0x6cca6b,12|10|0x4abe49,29|11|0xffffff,33|9|0x6fcc6f,40|13|0x26b125,41|15|0xffffff,-56|33|0x7cc87b,-54|34|0x56b855", 90, 0, 0, 719, 1279) --已添加 x9,y9 = findMultiColorInRegionFuzzy( 0x777777, "-2|-14|0xb1b1b1,1|-11|0xb9b9b9,2|1|0xb9b9b9,19|4|0xb1b1b1,22|1|0xa8a8a8,44|-6|0xa7a7a7,49|-2|0x8c8c8c,68|8|0x777777,70|-10|0xf3f3f3", 90, 0, 0, 719, 1279) if x7==-1 and y7==-1 and x8>-1 and y8>-1 then--有添加按钮 ButtonClick(x8, y8,"添加按钮");--点击添加按钮 nLog("找到添加按钮。。。添加数据"); mSleep(2000) x10,y10 = findMultiColorInRegionFuzzy( 0x1aad19, "14|4|0x1aad19,20|2|0xffffff,22|2|0x1aad19,23|-4|0x7dd07c,30|1|0x1aad19,41|6|0xffffff,42|5|0xbee8be,48|4|0x1aad19,51|10|0x1aad19", 90, 0, 0, 719, 1279) if x10>-1 and y10>-1 then --如果验证信息为空,就使用微信的默认验证消息 if vailmsgx~=nil and vailmsgx~="" then x11,y11 = findMultiColorInRegionFuzzy( 0xbfbfbf, "-5|4|0xffffff,-5|-2|0xbfbfbf,-7|-2|0xe7e7e7,1|-10|0xe7e7e7,8|-12|0xbfbfbf,2|-5|0xe7e7e7,-2|0|0xe7e7e7,0|2|0xe7e7e7,1|2|0xbfbfbf", 90, 0, 0, 719, 1279) ButtonClick(x11, y11,"清除验证消息");--点击备注界面 mSleep(500) inputText(vailmsgx);--填入备注信息 end --输入备注 ButtonClick(684, 483,"备注界面");--点击备注界面 mSleep(500) --switchTSInputMethod(true); inputText("@"..var.."@"); mSleep(500) --switchTSInputMethod(false); ButtonClick(x10, y10,"发生按钮");--点击发送按钮 writeFile(logfile,pici..","..var..",2") nLog(var.." 已发送添加") else writeFile(logfile,pici..","..var..",2")--已发送添加 end elseif x9>-1 and y9>-1 then --已经添加 writeFile(logfile,pici..","..var..",1")--已经添加 else writeFile(logfile,pici..","..var..",3")--找不到 end end backHome();---返回到主界面 --执行成功,进行删除操作 local xn = assert(io.open('/storage/emulated/0/WeiXinCrmLua/ResPhone.txt','w')) for key, var in ipairs(list) do wv=0; for ckey, nn in ipairs(addPhone2) do nLog("var:"..var) linetxt=nn.pici..","..nn.mobile..","..nn.firstname..","..nn.vailmsg; nLog("linetxt:"..linetxt) if linetxt==var then wv=1 nLog("数据相等!"..linetxt) end end if wv==0 then xn:write(var.."\r\n") end end xn:close();--关闭文档写入