基于autojs的TikTok自动关注及自动私信脚本

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-1 06:34   22705   1

源代码仅供学习研究autojs使用,不得用于任何非法行为,否则一切后果自行承担。

目前tiktok比较火,花了一天看了一下autojs的文档,又花了一天根据文档写了一个Tiktok的自动关注及自动私信脚本,带UI,使用的是autojs4.0版本,autojs使用的是javascript作为主要编程语言,脚本比较简单,将代码导入到autojs即可运行。脚本适配了华为麦芒5手机,分辨率一样的手机都可以使用。必须安卓7.0以上系统,否则不能使用autojs,不需要越狱。脚本特点是可以设置关注某一个用户的粉丝列表,也可以随机关注用户的粉丝列表,关注用户时随机时间。发私信自动添加随机表情,以防被封,如遇已发过的私信不再继续发送。以下是脚本运行截图。源代码仅供学习研究autojs使用,不得用于任何非法行为,否则一切后果自行承担。


autojs的界面和程序不能写到一个线程里面,否则就无法使用,以下是详细代码:

"ui";
ui.layout(
  <frame>
  <ScrollView>
   <vertical h="auto" w="*">
   <card  w="*" margin="10 5"  h="70" cardCornerRadius="2dp" cardElevation="1dp" gravity="center_vertical">
    <vertical h="auto" w="*">
     <text paddingLeft="20" paddingTop="16" text="TikToK脚本" w="auto" textSize="16sp" textColor="#000000"/>
     <text paddingLeft="20" paddingBottom="16" text="unsoft出品" w="auto"/>
    </vertical>
    <View bg="#f44336" h="auto" w="10"/>
   </card>
   <card  w="*" margin="10 5"  h="250" cardCornerRadius="2dp" cardElevation="1dp" gravity="center_vertical">
    <vertical h="auto" w="*">
     <horizontal>
      <text paddingLeft="20" paddingTop="16" text="自动关注设置" w="auto" textColor="#000000"/>
     </horizontal>
     <horizontal>
      <text paddingLeft="20" text="关注间隔" w="auto" />
      <input id="bmiao" inputType="number" text="2" w="50" gravity="center"/>
      <text text="秒至" w="auto"/>
      <input id="emiao" inputType="number" text="5" w="50" gravity="center"/>
      <text text="秒" w="auto"/>
     </horizontal>
     <horizontal>
      <text paddingLeft="20" text="每作品关注" w="auto"/>
      <input id="zpnumb" inputType="number" text="200" w="50" gravity="center"/>
      <text text="个粉丝" w="auto"/>
     </horizontal>
     <horizontal>
      <text paddingLeft="20" text="总共关注" w="auto"/>
      <input id="allnumb" inputType="number" text="200" w="50" gravity="center"/>
      <text text="个粉丝" w="auto"/>
     </horizontal>
     <horizontal padding="20">
      <button id="btn_gz" w="*" text="开始关注" gravity="center" bg="#409EFF" textColor="#ffffff"/>
     </horizontal>
    </vertical>
    <View bg="#FFA500" h="auto" w="10"/>
   </card>
   <card  w="*" margin="10 5"  min-h="250" cardCornerRadius="2dp" cardElevation="1dp" gravity="center_vertical">
    <vertical h="auto" w="*">
     <horizontal>
      <text paddingLeft="20" paddingTop="16" text="自动私信设置" w="auto" textColor="#000000"/>
     </horizontal>
     <horizontal paddingRight="20">
      <text paddingLeft="20" text="私信一:" w="auto" />
      <input id="fst" w="*"/>
     </horizontal>
     <horizontal paddingRight="20">
      <text paddingLeft="20" text="私信二:" w="auto" />
      <input id="sec" w="*"  />
     </horizontal>
     <horizontal paddingRight="20">
      <text paddingLeft="20" text="私信三:" w="auto" />
      <input id="thr" w="*"  />
     </horizontal>
     <horizontal padding="20">
      <button id="btn_sx" w="*"  text="开始私信" gravity="center" bg="#409EFF" textColor="#ffffff"/>
     </horizontal>
    </vertical>
    <View bg="#4caf50" h="auto" w="10"/>
   </card>
   </vertical>
   </ScrollView>
  </frame>
 );


 
var fuhao=[""," ","  ",".",". ",".  ","。","。 ","!","! ","!",",", ", ",","];
var pics=["😃","😄","😁","😆","😅","😂","","😊","😇","😉","😌","😋","😛","😝","😜","😏","😒","😞","😔","😟","😕","😣","😖","😫","😩","😢","😭","😤","😠","😡","😳","😱","😨","😰","😥","😓","😶","😐","😑","😬","😯","😦","😧","😮","😲","😴","😪","😵","😷","😈","👿","👹","👺","👻","💀","👽","👾","🎃","😺","😸","😹","😻","😼","😽","🙀","😿","😾"];

function flo()
{
 var w = floaty.rawWindow(
    <frame gravity="center">
        <text id="flt" text="Stop" textSize="16sp" textColor="red"/>
    </frame>
 );
 w.setPosition(0, 500);

 w.flt.click(function(){
 threads.start(endprocess);
}
);
}

function main_gz()
{
 auto.waitFor();
 console.show();
 //flo();
 var int_bmiao=parseInt(ui.bmiao.getText());
 var int_emiao=parseInt(ui.emiao.getText());
 var int_zpnumb=parseInt(ui.zpnumb.getText());
 var int_allnumb=parseInt(ui.allnumb.getText());
 var i=0;
 var j=0;
    toast("开启关注程序!");
 launchApp("TikTok");
 sleep(4000);
 
 while(i<int_allnumb)
 {
  click(985,560);
  sleep(2000);
  var user=id("aol").findOne();
  sleep(2000);
  click(user.bounds().centerX(),user.bounds().centerY());
  sleep(2000);
  m=0;
  while(m<int_zpnumb)
  {
   var follow=id("s3").find();
   sleep(800)
   console.log("找到点击目标");
   for(n=0;n<follow.length;n++)
   {
    
    var txt=follow[n].text();
    if(txt=="Follow" && m<int_zpnumb && follow[n].bounds().centerY()<1789 && follow[n].bounds().centerY()>360)
    {
     click(follow[n].bounds().centerX(),follow[n].bounds().centerY());
     var rdm=random(int_bmiao,int_emiao);
     sleep(rdm*1000);
     console.log("正在点击...");
     m++;
     i++;
    }
   }
   sleep(2000);
   swipe(540,1618,540,330,1000);
   sleep(2000)
  }
  back();
  sleep(1000);
  back();
  sleep(2000);
  swipe(540,1618,540,330,500);
  sleep(2000);
 }
 
 toast("程序结束!");
}

ui.btn_gz.click(function(){
 threads.start(main_gz);
});

ui.btn_sx.click(function(){
 threads.start(main_sx);
}
);


function endprocess()
{
 engines.stopAll();
 floaty.closeAll();
 toast("程序结束!");
}

function main_sx()
{
 auto.waitFor();
 console.show();
 //flo();
 var fsts=ui.fst.getText();
 var ssecs=ui.sec.getText();
 var thrs=ui.thr.getText();
 var str_fst=String(fsts);
 var str_sec=String(ssecs);
 var str_thr=String(thrs);
 toast("开启私信程序!");
 launchApp("TikTok");
 sleep(2000);
 click(754,1700);
 sleep(2000);
 while(true){
  var msg=id("s3").find();
  sleep(800);
  for(n=0;n<msg.length;n++)
  {
   stat=1;
   if(msg[n].bounds().centerY()<1603 && msg[n].bounds().centerY()>240 && msg[n].text()=="Message")
   {
    click(msg[n].bounds().centerX(),msg[n].bounds().centerY());
   }
   else
   {
    continue;
   }
   console.log("正在点击...");
   sleep(1000);
   
   var istxt=id("bsa").findOnce();
   sleep(800);
   if(istxt!=null)
   {
    console.log("已经发过了");
    stat=2;
    sleep(1000);
   }
   /*
   var cud=id("cud").findOnce();
   sleep(800);
   if(cud!=null)
   {
    console.log("被封号了");
    engines.stopAll();
    stat=2;
    sleep(1000);
   }
   */
   if(stat==1)
   {
    if(str_fst!="")
    {
     var nb=parseInt(random(0,fuhao.length));
     var picnb=parseInt(random(0,pics.length));
     //var str_fst_txt=str_fst+fuhao[nb]+pics[picnb];
     var str_fst_txt=str_fst+" "+pics[picnb];
     id("bs8").setText(str_fst_txt);
     sleep(1000);
     id("cli").findOne().click();
     sleep(1000)
    }
    if(str_sec!="")
    {
     var nb=parseInt(random(0,fuhao.length));
     var picnb=parseInt(random(0,pics.length));
     //var str_sec_txt=str_sec+fuhao[nb]+pics[picnb];
     var str_sec_txt=str_sec+" "+pics[picnb];
     id("bs8").findOne().setText(str_sec_txt);
     sleep(1000);
     id("cli").findOne().click();
     sleep(1000)
    }
    if(str_thr!="")
    {
     var nb=parseInt(random(0,fuhao.length));
     var picnb=parseInt(random(0,pics.length));
     //var str_thr_txt=str_thr+fuhao[nb]+pics[picnb];
     var str_thr_txt=str_thr+" "+pics[picnb];
     id("bs8").findOne().setText(str_thr_txt);
     sleep(1000);
     id("cli").findOne().click();
     sleep(1000)
    }
   }
   sleep(1000);
   back();
   sleep(1000);
  }
  swipe(540,1618,540,350,500);
  sleep(2000);
 }
}



autojs比较简单,但是编辑代码比较麻烦,他设置的是在手机端编辑的,虽然官方提供了一个VScode的插件,因为代码本身也比较简单,就懒得去装了。在电脑端写完后全文复制到手机端的。与autojs类似的脚本框架还有很多,都比较简单。看一看文档一般很快就能上手,对于这类脚本应用还有很多地方,可以解放双手。如你也感兴趣欢迎交流学习。

分享到 :
0 人收藏

1 个回复

倒序浏览
2#
是我先生  1级新秀 | 2022-4-9 11:39:08 (来自手机浏览器) 发帖IP地址来自 广东广州
有最新版的嗎
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP