weixin_watch_video.py 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. """
  2. 微信视频号随机浏览
  3. """
  4. import random
  5. import time
  6. from func.action_func import del_key_vague
  7. from scene.oprator.atom_data import single_click_by_control, single_click_by_text, many_click_by_position, click_pic, \
  8. stop_app, start_app
  9. from task.task_job import callback_task
  10. from tools import loggerKit, redis_client
  11. from tools.pic_base64_util import pic_to_base64
  12. def weixin_watch_video(task_id, device_id, data):
  13. loggerKit.info('请求信息:{0}'.format(data))
  14. device_id = data.get("deviceID")
  15. perform_action_id = data.get("performActionId")
  16. result = data.get("result")
  17. inner_data = data.get("data")
  18. loggerKit.info("inner_data:{0}, keyword:{1}", inner_data, inner_data.get("resourceName"))
  19. if result is not None:
  20. """
  21. 非首个指令
  22. """
  23. perform_action_result = result.get("performActionResult")
  24. if perform_action_result is None:
  25. return_dict = {
  26. "data": "",
  27. "code": -2,
  28. "message": "fail, performActionResult is null"
  29. }
  30. # 回调任务中心
  31. del_key_vague(device_id)
  32. callback_task(500, '指令执行失败', task_id, device_id, 0, None)
  33. return return_dict
  34. # 指令执行失败
  35. if perform_action_result == "failure":
  36. # 回调任务中心
  37. return_dict = {
  38. "data": "",
  39. "code": -2,
  40. "message": "fail, performActionResult is null"
  41. }
  42. del_key_vague(device_id)
  43. callback_task(500, '指令执行失败', task_id, device_id, 0, None)
  44. return return_dict
  45. # 终止指令
  46. if perform_action_result == "stop":
  47. # 回调任务中心
  48. return_dict = {
  49. "data": "",
  50. "code": -2,
  51. "message": "指令被用户终止"
  52. }
  53. del_key_vague(device_id)
  54. callback_task(500, '指令被用户终止', task_id, device_id, 0, None)
  55. return return_dict
  56. # 终止指令
  57. if perform_action_result == "eleNotFound":
  58. # 回调任务中心
  59. return_dict = {
  60. "data": "",
  61. "code": -2,
  62. "message": "未找到签到指示"
  63. }
  64. del_key_vague(device_id)
  65. callback_task(500, '未找到签到指示,该账号当天可能已经签到过', task_id, device_id, 0, None)
  66. return return_dict
  67. # 元素未找到
  68. if perform_action_result == "invalid operation":
  69. # 回调任务中心
  70. return_dict = {
  71. "data": "",
  72. "code": -2,
  73. "message": "fail, performActionResult is not success"
  74. }
  75. del_key_vague(device_id)
  76. callback_task(500, '任务执行失败,元素未找到', task_id, device_id, 0, None)
  77. return return_dict
  78. """
  79. 每次操作完成后会将对应的操作唯一id存储到redis
  80. 并且返回给手机端 手机端下次带着上个操作id来执行下一个操作
  81. """
  82. last_action_id = redis_client.get(device_id + "operate")
  83. step0 = redis_client.get(f"{device_id}_step0")
  84. if (step0 is not None and int(step0) == 1 and last_action_id is not None and int(perform_action_id) == int(
  85. last_action_id)
  86. and perform_action_result == "success"):
  87. action1_id = int(round(time.time() * 1000))
  88. """
  89. 发送第1条指令
  90. 点击:发现(菜单)
  91. """
  92. action1_dict = single_click_by_control(action1_id, target_app="weixin",
  93. target_version="8.0.47",
  94. package_name="com.tencent.mm",
  95. control_id="com.tencent.mm:id/icon_tv")
  96. redis_client.set(device_id + "operate", action1_id)
  97. redis_client.set(f"{device_id}_step1", "1")
  98. redis_client.delete(f"{device_id}_step0")
  99. loggerKit.info("taskId:{0}, action1_id:{1}", task_id, action1_id)
  100. return action1_dict
  101. step1 = redis_client.get(f"{device_id}_step1")
  102. if step1 is not None and int(step1) == 1 and last_action_id is not None and int(perform_action_id) == int(
  103. last_action_id):
  104. loggerKit.info("设备:{0}, last_action_id:{1}", device_id, int(last_action_id))
  105. action2_id = int(round(time.time() * 1000))
  106. """
  107. 发送第2条指令
  108. 点击:视频号
  109. """
  110. action2_dict = single_click_by_text(action2_id,
  111. text="视频号",
  112. target_app="weixin",
  113. target_version="8.0.47",
  114. package_name="com.tencent.mm")
  115. redis_client.set(device_id + "operate", action2_id)
  116. redis_client.set(f"{device_id}_step2", "1")
  117. redis_client.delete(f"{device_id}_step1")
  118. loggerKit.info("taskId:{0}, action2_id:{1}", task_id, action2_id)
  119. return action2_dict
  120. step2 = redis_client.get(f"{device_id}_step2")
  121. if step2 is not None and int(step2) == 1 and last_action_id is not None and int(perform_action_id) == int(
  122. last_action_id):
  123. loggerKit.info("设备:{0}, last_action_id:{1}", device_id, int(last_action_id))
  124. action3_id = int(round(time.time() * 1000))
  125. """
  126. 发送第3条指令
  127. 点击:人像
  128. """
  129. action3_dict = single_click_by_control(action3_id, control_id="com.tencent.mm:id/ktr",
  130. control_ids="com.tencent.mm:id/ktr",
  131. target_app="weixin",
  132. target_version="8.0.47",
  133. package_name="com.tencent.mm")
  134. redis_client.set(device_id + "operate", action3_id)
  135. redis_client.set(f"{device_id}_step3", "1")
  136. redis_client.delete(f"{device_id}_step2")
  137. loggerKit.info("taskId:{0}, action3_id:{1}", task_id, action3_id)
  138. return action3_dict
  139. step3 = redis_client.get(f"{device_id}_step3")
  140. if step3 is not None and int(step3) == 1 and last_action_id is not None and int(perform_action_id) == int(
  141. last_action_id):
  142. loggerKit.info("设备:{0}, last_action_id:{1}", device_id, int(last_action_id))
  143. action4_id = int(round(time.time() * 1000))
  144. """
  145. 发送第4条指令
  146. 点击: 关注
  147. """
  148. action4_dict = single_click_by_text(action4_id,
  149. text="关注",
  150. target_app="weixin",
  151. target_version="8.0.47",
  152. package_name="com.tencent.mm")
  153. redis_client.set(device_id + "operate", action4_id)
  154. redis_client.set(f"{device_id}_step4", "1")
  155. redis_client.delete(f"{device_id}_step3")
  156. return action4_dict
  157. step4 = redis_client.get(f"{device_id}_step4")
  158. if step4 is not None and int(step4) == 1 and last_action_id is not None and int(perform_action_id) == int(
  159. last_action_id):
  160. loggerKit.info("设备:{0}, last_action_id:{1}", device_id, int(last_action_id))
  161. action5_id = int(round(time.time() * 1000))
  162. """
  163. 发送第5条指令
  164. 点击: 荣威ROEWE
  165. """
  166. action5_dict = single_click_by_text(action5_id, text="荣威ROEWE",
  167. target_app="weixin",
  168. target_version="8.0.47",
  169. package_name="com.tencent.mm")
  170. redis_client.set(device_id + "operate", action5_id)
  171. redis_client.set(f"{device_id}_step5", "1")
  172. redis_client.delete(f"{device_id}_step4")
  173. return action5_dict
  174. step5 = redis_client.get(f"{device_id}_step5")
  175. if step5 is not None and int(step5) == 1 and last_action_id is not None and int(perform_action_id) == int(
  176. last_action_id):
  177. loggerKit.info("设备:{0}, last_action_id:{1}", device_id, int(last_action_id))
  178. action6_id = int(round(time.time() * 1000))
  179. """
  180. 发送第6条指令
  181. 点击:视频
  182. """
  183. action6_dict = single_click_by_control(action6_id, control_id="com.tencent.mm:id/nuw",
  184. control_ids="com.tencent.mm:id/nuw",
  185. item_index=1,
  186. target_app="weixin",
  187. target_version="8.0.47",
  188. package_name="com.tencent.mm")
  189. redis_client.set(device_id + "operate", action6_id)
  190. redis_client.set(f"{device_id}_step6", "1")
  191. redis_client.delete(f"{device_id}_step5")
  192. return action6_dict
  193. step6 = redis_client.get(f"{device_id}_step6")
  194. if step6 is not None and int(step6) == 1 and last_action_id is not None and int(perform_action_id) == int(
  195. last_action_id):
  196. loggerKit.info("设备:{0}, last_action_id:{1}", device_id, int(last_action_id))
  197. action7_id = int(round(time.time() * 1000))
  198. """
  199. 发送第7条指令
  200. 随机点击某个视频
  201. """
  202. random_index = random.randint(1, 5)
  203. action7_dict = single_click_by_control(action7_id, control_id="com.xingin.xhs:id/aki",
  204. control_ids="com.xingin.xhs:id/aki",
  205. target_app="weixin",
  206. target_version="8.0.47",
  207. package_name="com.tencent.mm",
  208. item_index=random_index)
  209. redis_client.set(device_id + "operate", action7_id)
  210. redis_client.set(f"{device_id}_step7", "1")
  211. redis_client.delete(f"{device_id}_step6")
  212. return action7_dict
  213. # 视频点赞
  214. step7 = redis_client.get(f"{device_id}_step7")
  215. if step7 is not None and int(step7) == 1 and last_action_id is not None and int(perform_action_id) == int(
  216. last_action_id):
  217. loggerKit.info("设备:{0}, last_action_id:{1}", device_id, int(last_action_id))
  218. action8_id = int(round(time.time() * 1000))
  219. """
  220. 发送第8条指令
  221. 视频点赞
  222. """
  223. action8_dict = many_click_by_position(action8_id, target_app="weixin",
  224. target_version="8.0.47",
  225. package_name="com.tencent.mm")
  226. redis_client.set(device_id + "operate", action8_id)
  227. redis_client.set(f"{device_id}_step8", "1")
  228. redis_client.delete(f"{device_id}_step7")
  229. return action8_dict
  230. # 视频收藏
  231. step8 = redis_client.get(f"{device_id}_step8")
  232. if step8 is not None and int(step8) == 1 and last_action_id is not None and int(perform_action_id) == int(
  233. last_action_id):
  234. loggerKit.info("设备:{0}, last_action_id:{1}", device_id, int(last_action_id))
  235. action9_id = int(round(time.time() * 1000))
  236. """
  237. 发送第9条指令
  238. 视频收藏->判断视频是否已经收藏了
  239. """
  240. no_collected_base64 = pic_to_base64("weixin/screen/no_collected.png")
  241. action9_dict = click_pic(action9_id, target_app="weixin",
  242. target_version="8.0.47",
  243. package_name="com.tencent.mm",
  244. pic_base64=no_collected_base64)
  245. redis_client.set(device_id + "operate", action9_id)
  246. redis_client.set(f"{device_id}_step9", "1")
  247. redis_client.delete(f"{device_id}_step8")
  248. loggerKit.info("设备:{0}, action7_id:{1}", device_id, action9_id)
  249. return action9_dict
  250. """
  251. 停止app
  252. """
  253. step9 = redis_client.get(f"{device_id}_step9")
  254. if step9 is not None and int(step9) == 1 and last_action_id is not None and int(perform_action_id) == int(
  255. last_action_id):
  256. loggerKit.info("设备:{0}, last_action_id:{1}", device_id, int(last_action_id))
  257. action10_id = int(round(time.time() * 1000))
  258. """
  259. 停止指令
  260. 停止app
  261. """
  262. action10_dict = stop_app(action10_id,
  263. target_app="weixin",
  264. target_version="8.0.47",
  265. package_name="com.tencent.mm")
  266. del_key_vague(device_id)
  267. loggerKit.info("设备:{0}, action10_id:{1}", device_id, action10_id)
  268. callback_task(None, None, task_id, device_id, 1, None)
  269. return action10_dict
  270. else:
  271. action0_id = int(round(time.time() * 1000))
  272. """
  273. 启动指令
  274. 启动app
  275. """
  276. action0_dict = start_app(action0_id, target_app="weixin",
  277. target_version="8.0.47",
  278. package_name="com.tencent.mm")
  279. redis_client.set(device_id + "operate", action0_id)
  280. redis_client.set(f"{device_id}_step0", "1")
  281. redis_client.delete(f"{device_id}_step11")
  282. loggerKit.info("设备:{0}, action0_id:{1}", device_id, action0_id)
  283. return action0_dict