local sn = getSN(); local host, port = "34.143.180.5", 8095 local app = "com.ss.iphone.ugc.Ame" local socket = require("socket") local tcp = assert(socket.tcp()) local json = require "json" local numberKeys = { ['0'] = { ['x'] = 384, ['y'] = 1274, }, ['1'] = { ['x'] = 139, ['y'] = 957, }, ['2'] = { ['x'] = 378, ['y'] = 957, }, ['3'] = { ['x'] = 628, ['y'] = 957, }, ['4'] = { ['x'] = 139, ['y'] = 1063, }, ['5'] = { ['x'] = 378, ['y'] = 1063, }, ['6'] = { ['x'] = 628, ['y'] = 1063, }, ['7'] = { ['x'] = 139, ['y'] = 1168, }, ['8'] = { ['x'] = 378, ['y'] = 1168, }, ['9'] = { ['x'] = 628, ['y'] = 1168, }, } local addColor = 16657493 local addX = 699 local addY = 510 local messageIconColor = 15987184 local messageIconX = 688 local messageIconY = 735 local messageIconColor = 15987184 local messageInputX = 449 local messageInputY = 1272 local messageInputColor = 15856114 local sendButtonX = 623 local sendButtonY = 1278 local sendButtonColor = 31487 function comment(message) local res = { ["success"] = false, ["code"] = 0, ["message"] = "Lỗi không xác định" } local tryTimes = 0 local isNormalClip = check(addColor, addX, addY, 4, 500000, 10, 10) repeat tryTimes = tryTimes + 1 touchDown(0, 300, 300); usleep(50000); touchMove(0, 300, 200); usleep(50000); touchUp(0, 300, 200); usleep(2000000) isNormalClip = check(addColor, addX, addY, 4, 500000, 10, 10) until (isNormalClip or tryTimes == 5) if not isNormalClip then res["code"] = 1 res["message"] = "Không tìm thấy clip có thể comment" return res end tap(messageIconX, messageIconY) local tapMessageInput = tapIcon(messageInputColor, messageInputX, messageInputY, 4, 500000, 10, 10) if not tapMessageInput then local tapMessageInput2 = tapIcon(messageInputColor, messageInputX, messageInputY-600, 4, 500000, 10, 10) if not tapMessageInput2 then restartApp() res["code"] = 1 res["message"] = "Không thể nhấn ô nhập comment" return res end end usleep(1000000) inputText(message) usleep(1000000) local tapSendButton = tapIcon(sendButtonColor, sendButtonX, sendButtonY, 4, 500000, 10, 10) if not tapSendButton then res["code"] = 1 res["message"] = "Không thể nhấn button Gửi" return res end usleep(1000000) tap(300,190) usleep(1000000) local isHome = check(addColor, addX, addY, 4, 500000, 10, 10) if not isHome then tap(300,190) usleep(1000000) isHome = check(addColor, addX, addY, 4, 500000, 10, 10) restartApp() end res["success"] = true res["message"] = "Thành công" return res end function tapIcon(c, x, y, times, delay, diffX, diffY) times = times or 4 delay = delay or 500000 diffX = diffX or 5 diffY = diffY or 5 local curTimes = 0; local isTap = false; repeat curTimes = curTimes + 1; local find = findColor(c, 1, {x, y, diffX, diffY}) local b1 = 0; local b2 = 0; for i, v in pairs(find) do b1 = v[1]; b2 = v[2]; end usleep(delay); if (b1 ~= 0 or b2 ~= 0) then tap(b1, b2); isTap = true; end until(curTimes == times or isTap) return isTap; end function check(c, x, y, times, delay, diffX, diffY) times = times or 4 delay = delay or 500000 diffX = diffX or 5 diffY = diffY or 5 local curTimes = 0; local found = false; repeat curTimes = curTimes + 1; local find = findColor(c, 1, {x, y, diffX, diffY}) local b1 = 0; local b2 = 0; for i, v in pairs(find) do b1 = v[1]; b2 = v[2]; end usleep(delay); if (b1 ~= 0 or b2 ~= 0) then found = true; end until(curTimes == times or found) return found; end function restartApp() appKill(app); usleep(2000000); appRun(app); usleep(3000000); end tcp:connect(host, port); tcp:setoption("keepalive", true) tcp:setoption("reuseaddr", true) assert(tcp:send(json.encode(init))) restartApp() repeat data, errormsg = tcp:receive() if data then if (data == "end") then break else local mess = json.decode(data) local res = { ["sender"] = mess["sender"], ["content"] = "", ["message"] = "", ["success"] = false, } if mess['content'] then local send = comment(mess["content"]) res["sender"] = sn res["content"] = mess["content"] res["success"] = send["success"] res["message"] = send["message"] if not res["success"] then restartApp() else usleep(1000000) touchDown(0, 300, 300); usleep(50000); touchMove(0, 300, 200); usleep(50000); touchUp(0, 300, 200); end usleep(5000000) tcp:send(json.encode(res)) end end else assert(tcp:send("ready")) end until not tcp