当前位置:   article > 正文

AutoJs 脚本 实现 抖音自动参与超级福袋_抖音福袋脚本

抖音福袋脚本

 自己做的一个小脚本工具,可以全自动参与抖音的超级福袋,只是超级福袋,普通福袋没做,而且只会参加“只需要发评论”的超级福袋,粉丝团等其他要求的不会参加
用的是autojs,opencv的图像识别
需要把所需的功能权限开启,
1.通知权限(看到实时日志),
2.悬浮框、后台弹出应用(同上),
3.无障碍权限(模拟点击功能),
4.分享屏幕给应用(提供屏幕的图像识别功能)

首先截取了福袋的图标,并手工截取了红框中的区域作为原来识别的福袋图像,图三的素材在项目包内也有提供 抢福袋.zip - 蓝奏云

以上是项目包,包含代码

 

然后开始正文:

  1. /**
  2. 由于本人很菜,变量命名为拼音命名法【狗头】,不想查英文,英文与拼音相比也不太直观,后续复看也不太方便
  3. 代码写的很垃圾,有很多重复的代码可以提取为方法,比如提取控件中心点,但是写了能跑就算了
  4. 而且没有做当前软件的包名检查,打开就直接运行了,需要改,主体全挤到一起了,非常的臃肿垃圾,好在能用
  5. 不知道为什么弹窗toast有很多会不弹出来显示,只有日志完整记录了
  6. 开始阅读垃圾代码吧,预计阅读4分钟
  7. **/
  8. //看到别人都用这个,我也用,貌似是用了之后,click这些无障碍操作就可以生效
  9. auto();
  10. //轮次
  11. var cishu=1;
  12. //开启录屏/截图权限申请,为后面的图像识别的截图做准备
  13. if (!requestScreenCapture()) {
  14. toast("请求截图失败");
  15. console.log("请求截图失败");
  16. exit();
  17. }
  18. //识别率,也可以写死进去,实际的区域识别率大概在95%以上,所以只要满足90%就行
  19. var shibielv = 0.9
  20. //识别区域的坐标信息
  21. var region = null;
  22. //隐藏控件区域的中心坐标信息,实际就是屏幕中心上方空白的区域,点一下之后那些控件会自动关闭。用的是乘以测算的百分比
  23. var yincang = [ device.height * 0.225,device.width * 0.69375];
  24. //“我知道了”的控件的中心坐标
  25. var zhidaolecenter=null;
  26. //我知道了的控件的 矩阵信息
  27. var wozhidaolebound = null;
  28. //我知道了 控件对象
  29. var wozhidaoleelements = null;
  30. //“一键发表评论”的控件的中心坐标
  31. var pingluncenter=null;
  32. //“一键发表评论”的控件的 矩阵信息
  33. var pinglunbound = null;
  34. //“一键发表评论” 控件对象
  35. var pinglunelements = null;
  36. //图像识别福袋的函数
  37. function searchfudai(fudai, shibielv, region) {
  38. //大图为屏幕截图
  39. let Bigpic = captureScreen()
  40. //小图为福袋图标的一小部分的截图
  41. let fudaipic1 = images.read("Images/" + fudai + ".png");
  42. //根据我的截图机器的分辨率对图像进行缩放,我的是3200*1440,小于这个设备的应该可以吧,大于的恐怕不行,需要优化
  43. let suofangx = device.width / 1440
  44. let suofangy = device.height / 3200
  45. //缩放
  46. let fudaipic = images.scale(fudaipic1, suofangx, suofangy)
  47. //开始识别,最大匹配为5,识别区域设定为福袋的识别区域 如果为空则是全屏 ,识别率为 0.9
  48. let result = images.matchTemplate(Bigpic, fudaipic, {
  49. max: 5,
  50. region: region||[0, 0, device.width, device.height], //区域
  51. threshold: shibielv,
  52. });
  53. console.log("福袋识别区域结果(坐标和相似度):"+result.matches)
  54. //对识别结果提取福袋的坐标与中心坐标,中心坐标为坐上顶点坐标加上被识别图像的宽高的一半
  55. if (result != null) {
  56. for (let i = 0; i < result.matches.length; i++) {
  57. let pp = result.matches[i].point
  58. // log(pp)
  59. // console.nk
  60. console.log("找到福袋位置:" , pp.x, pp.y);
  61. // console.log("相对全屏坐标" + fudai, pp.x + region[0], pp.y + region[1]); // 本来我推测如果是区域识别的话,坐标应该是匹配点的坐标加上福袋识别区域的坐标,但是不知道为什么不行
  62. console.log("福袋点击的中心坐标" + fudai, pp.x + fudaipic1.width / 2, pp.y + fudaipic1.height / 2);
  63. let matchX = pp.x + fudaipic1.width / 2; // 匹配位置相对于整个大图的x坐标 63
  64. let matchY = pp.y + fudaipic1.height / 2; // 匹配位置相对于整个大图的y坐标 63
  65. click(matchX , matchY)
  66. // click(pp.x, pp.y)
  67. // log(pp.x, pp.y)
  68. console.log("点击福袋")
  69. sleep(200)
  70. return true
  71. }
  72. } else {
  73. console.log("未找到福袋" )
  74. return false
  75. }
  76. // fudaipic1.recycle(); //图像回收是要的,以免内存泄漏,但是貌似导致了一些问题,所以没用
  77. }
  78. while(true){
  79. toast("下一轮");
  80. console.log("下一轮");
  81. toast("第"+cishu++ +"次抽福袋");
  82. console.log("第"+cishu+"轮");
  83. // 关闭我知道了的弹窗
  84. var wozhidaole2 = className("com.lynx.tasm.behavior.ui.view.UIView").desc("我知道了");
  85. //如果存在 我知道了 的弹窗
  86. if (wozhidaole2.exists()) {
  87. toast("关闭我知道了");
  88. console.log("新的一轮,关闭我知道了");
  89. if(zhidaolecenter==null){
  90. //找到具体的控件
  91. wozhidaoleelements = className("com.lynx.tasm.behavior.ui.view.UIView").desc("我知道了").find();
  92. if(wozhidaolebound==null){
  93. for (var i = 0; i < wozhidaoleelements.length; i++) {
  94. if(wozhidaoleelements[i].bounds()!=null){
  95. console.warn(wozhidaoleelements[i].bounds())
  96. wozhidaolebound = [wozhidaoleelements[i].bounds().left, wozhidaoleelements[i].bounds().top, wozhidaoleelements[i].bounds().right, wozhidaoleelements[i].bounds().bottom]; // 存储当前元素的坐标值
  97. break;
  98. } // 获取当前元素的边界信息
  99. }
  100. // 输出坐标数组
  101. console.log(wozhidaolebound);
  102. }
  103. //提取“我知道了”控件中心坐标
  104. var zhidaolecenterX = (wozhidaolebound[0] + wozhidaolebound[2]) / 2;
  105. var zhidaolecenterY = (wozhidaolebound[1] + wozhidaolebound[3]) / 2;
  106. zhidaolecenter = [zhidaolecenterX,zhidaolecenterY]
  107. console.log("我知道了的中心点:"+zhidaolecenter);
  108. }
  109. click(zhidaolecenter[0],zhidaolecenter[1]);//关闭我知道了
  110. // click(yincang[0],yincang[1]);//隐藏所有控件
  111. sleep(3000);
  112. }
  113. click(yincang[0],yincang[1]);//隐藏所有控件,是屏幕中心上方的中心点
  114. console.log("查找福袋监控区域")
  115. var elements = className("android.widget.FrameLayout").id("ud0").find(); //福袋那一栏的控件
  116. //如果控件存在则提取监控区域的矩阵坐标信息
  117. if(region==null){
  118. for (var i = 0; i < elements.length; i++) {
  119. if(elements[i].bounds()!=null){
  120. // console.log(elements[i].bounds())
  121. region = [elements[i].bounds().left, elements[i].bounds().top, elements[i].bounds().right, elements[i].bounds().bottom]; // 存储当前元素的坐标值
  122. break;
  123. } // 获取当前元素的边界信息
  124. }
  125. // 输出数组
  126. // console.log(region);
  127. console.log("福袋监控区域:"+region)
  128. }
  129. //福袋刚结束可能会在5秒内快速补充,以免进入30秒长时间倒计时
  130. console.log("休息5秒,等待新的福袋出现");
  131. sleep(5000);
  132. // if(region==null){continue;}
  133. // var targetControl = className("android.widget.FrameLayout").boundsInside(189,400,315,526).findOne();
  134. //开始识别福袋,其中的region 为我们刚刚在上面识别提取到的福袋监控区域的矩阵坐标信息
  135. if (searchfudai("fudai2", shibielv, region)) {
  136. toast("福袋存在");
  137. console.log("福袋存在");
  138. // click(252,463);
  139. sleep(3000);
  140. toast("开始检测发评论");
  141. console.log("开始检测发评论");
  142. var yijianfabiaopinglun = className("com.lynx.tasm.behavior.ui.view.UIView").desc("一键发表评论");
  143. //如果一键发评论的控件存在
  144. if(yijianfabiaopinglun.exists()){
  145. sleep(3000);
  146. toast("一键发表评论存在");
  147. console.log("一键发表评论存在");
  148. if(pingluncenter==null){
  149. pinglunelements = className("com.lynx.tasm.behavior.ui.view.UIView").desc("一键发表评论").find();
  150. //找到具体的控件坐标信息
  151. if(pinglunbound==null){
  152. for (var i = 0; i < pinglunelements.length; i++) {
  153. if(pinglunelements[i].bounds()!=null){
  154. console.warn(pinglunelements[i].bounds())
  155. pinglunbound = [pinglunelements[i].bounds().left, pinglunelements[i].bounds().top, pinglunelements[i].bounds().right, pinglunelements[i].bounds().bottom]; // 存储当前元素的坐标值
  156. break;
  157. } // 获取当前元素的边界信息
  158. }
  159. // 输出数组
  160. console.log(pinglunbound);
  161. }
  162. //计算控件中心点 pingluncenterX = (bounds().left+bounds().right)/2 pingluncenterY = (bounds().top + bounds().bottom) / 2;
  163. var pingluncenterX = (pinglunbound[0] + pinglunbound[2]) / 2;
  164. var pingluncenterY = (pinglunbound[1] + pinglunbound[3]) / 2;
  165. pingluncenter = [pingluncenterX,pingluncenterY]
  166. console.log("一键发评论的中心点:"+pingluncenter);
  167. }
  168. click(pingluncenter[0],pingluncenter[1]);//点击发评论控件的中心点
  169. // click(727,2892);
  170. //点击后就查找参与成功的反馈
  171. var dengdaikaichoujiang = className("com.lynx.tasm.behavior.ui.view.UIView").desc("参与成功 等待抽奖").find();
  172. if(dengdaikaichoujiang){
  173. sleep(3000);
  174. toast("参与成功 等待抽奖");
  175. console.log("参与成功 等待抽奖");
  176. click(yincang[0],yincang[1]);//隐藏所有控件
  177. searchfudai("fudai2", shibielv, region)
  178. //sleep(120000);
  179. //continue; // 跳出当前循环
  180. }
  181. }
  182. else{
  183. toast("没找到发表评论");
  184. console.log("没找到发表评论");
  185. //对于加入粉丝团的,不进行操作并停止脚本运行
  186. if(className("com.lynx.tasm.behavior.ui.view.UIView").desc("加入粉丝团").exists()){
  187. toast("加入粉丝团,不可能的,不加,停止脚本");
  188. console.warn("加入粉丝团,不可能的,不加,停止脚本");
  189. break;
  190. }
  191. // click(yincang[0],yincang[1]);//隐藏所有控件
  192. }
  193. //等一会
  194. sleep(3000);
  195. //找一下参与成功后点击福袋原来 “一键发表评论” 位置的文本是否变为 "参与成功 等待开奖" ,判断是否参加成功
  196. var canyuchenggong = className("com.lynx.tasm.behavior.ui.view.UIView").desc("参与成功 等待开奖");
  197. //如果存在
  198. if(canyuchenggong.exists()){
  199. toast("参与成功 等待开奖");
  200. console.log("参与成功 等待开奖");
  201. // click(yincang[0],yincang[1]);//隐藏所有控件
  202. sleep(2000);
  203. toast("开始等待开奖");
  204. console.log("开始等待开奖,请耐心等待");
  205. //findOne的意思:刚学,不确定:findOne()会阻塞线程,直到找到目标的控件,否则会一直等待,因此我们确定参加成功后使用findOne等待结果而不是盲目操作
  206. var wozhidaole = className("com.lynx.tasm.behavior.ui.view.UIView").desc("我知道了").findOne();
  207. //我知道了控件找到后,也就是开奖了
  208. if (wozhidaole) {
  209. toast("关闭我知道了");
  210. console.log("开奖了,关闭我知道了");
  211. //如果我知道了的控件的中心点坐标信息为空,则需要重新获取,这里貌似可以沿用上面的wozhidaole?罢了写了就不想改了,能跑就行
  212. if(zhidaolecenter==null){
  213. wozhidaoleelements = className("com.lynx.tasm.behavior.ui.view.UIView").desc("我知道了").find();
  214. if(wozhidaolebound==null){
  215. for (var i = 0; i < wozhidaoleelements.length; i++) {
  216. if(wozhidaoleelements[i].bounds()!=null){
  217. console.warn(wozhidaoleelements[i].bounds())
  218. wozhidaolebound = [wozhidaoleelements[i].bounds().left, wozhidaoleelements[i].bounds().top, wozhidaoleelements[i].bounds().right, wozhidaoleelements[i].bounds().bottom]; // 存储当前元素的坐标值
  219. break;
  220. } // 获取当前元素的边界信息
  221. }
  222. // 输出数组
  223. console.log(wozhidaolebound);
  224. }
  225. //提取中心点坐标,中心点计算方式在上面一样的
  226. var zhidaolecenterX = (wozhidaolebound[0] + wozhidaolebound[2]) / 2;
  227. var zhidaolecenterY = (wozhidaolebound[1] + wozhidaolebound[3]) / 2;
  228. zhidaolecenter = [zhidaolecenterX,zhidaolecenterY]
  229. console.log("我知道了的中心点:"+zhidaolecenter);
  230. }
  231. click(zhidaolecenter[0],zhidaolecenter[1]);//关闭我知道了
  232. sleep(3000);
  233. click(yincang[0],yincang[1]);//隐藏所有控件
  234. //别问为啥,菜鸟害怕这些变量携带旧的信息,手动置空
  235. wozhidaole = null;
  236. wozhidaole2 = null;
  237. canyuchenggong = null;
  238. dengdaikaichoujiang = null;
  239. targetControl = null;
  240. yijianfabiaopinglun = null;
  241. //确认开奖后就可以跳过这一轮了,进行下一轮
  242. continue;
  243. }
  244. }
  245. else{
  246. toast("没找到参与成功 等待开奖");
  247. console.log("没找到参与成功 等待开奖");
  248. click(yincang[0],yincang[1]);//隐藏所有控件
  249. wozhidaole = null;
  250. wozhidaole2 = null;
  251. canyuchenggong = null;
  252. dengdaikaichoujiang = null;
  253. targetControl = null;
  254. yijianfabiaopinglun = null;
  255. continue;
  256. }
  257. } else {
  258. toast("福袋不存在,等待30秒");
  259. console.log("福袋不存在,等待30秒");
  260. //如果不存在等30秒
  261. sleep(30000);
  262. click(yincang[0],yincang[1]);//隐藏所有控件
  263. wozhidaole = null;
  264. wozhidaole2 = null;
  265. canyuchenggong = null;
  266. dengdaikaichoujiang = null;
  267. targetControl = null;
  268. yijianfabiaopinglun = null;
  269. continue;
  270. }
  271. }

下面是打包好的软件:

软件名称:抢福袋
软件版本:V2.0.0
软件大小:18.64MB


软件无毒,但会误报毒,没有问题的,不放心的可以把软件的联网权限关闭
脚本运行后,手动前往直播间,找到只用发评论就可以参与的直播间,按音量加键可以停止运行,返回软件可以看到实时日志
需要一直保持前台全屏显示抖音直播间
中途可能会出现验证码或人机验证,需要手动验证
 因为autojs是今天刚学的,所以写的比较垃圾,好在会JavaScript
下载链接:
链接:https://pan.baidu.com/s/1i39EKwA-wYaFQnFc6THtcA?pwd=h5e9 
提取码:h5e9
注意事项:
该程序只能作为学习研究使用,不能用于非法用途,否则后果自负
应用截图:

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/488831
推荐阅读
相关标签
  

闽ICP备14008679号