self_sign.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. """
  2. app: 头条极速版:
  3. desc:完整签到
  4. """
  5. import base64
  6. import time
  7. import yaml
  8. from func.action_func import del_key_vague
  9. from scene.oprator.atom_data import single_click_by_text, single_click_by_control, click_pic, stop_app, start_app
  10. from task.task_job import callback_task
  11. from tools import loggerKit, redis_client
  12. with open('config.yaml', 'r') as file:
  13. config = yaml.load(file, Loader=yaml.FullLoader)
  14. extern_domain = config['bmp-cp']['extern_domain']
  15. # 任务执行回调url
  16. task_callback_url = extern_domain + config['bmp-cp']['task_callback_url']
  17. """
  18. 头条极速版
  19. 开宝箱刷视频
  20. """
  21. def self_sign(task_id, data):
  22. loggerKit.info("[头条极速版]请求信息:{0}'.format(data))")
  23. device_id = data.get("deviceID")
  24. perform_action_id = data.get("performActionId")
  25. result = data.get("result")
  26. if result is not None:
  27. """
  28. 非首个指令
  29. """
  30. perform_action_result = result.get("performActionResult")
  31. if perform_action_result is None:
  32. return_dict = {
  33. "data": "",
  34. "code": -2,
  35. "message": "fail, performActionResult is null"
  36. }
  37. # 回调任务中心
  38. del_key_vague(device_id)
  39. callback_task(500, '指令执行失败', task_id, device_id, 0, None)
  40. return return_dict
  41. # 指令执行失败
  42. if perform_action_result == "failure":
  43. # 回调任务中心
  44. return_dict = {
  45. "data": "",
  46. "code": -2,
  47. "message": "fail, performActionResult is null"
  48. }
  49. del_key_vague(device_id)
  50. callback_task(500, '指令执行失败', task_id, device_id, 0, None)
  51. return return_dict
  52. # 终止指令
  53. if perform_action_result == "stop":
  54. # 回调任务中心
  55. return_dict = {
  56. "data": "",
  57. "code": -2,
  58. "message": "指令被用户终止"
  59. }
  60. del_key_vague(device_id)
  61. callback_task(500, '指令被用户终止', task_id, device_id, 0, None)
  62. return return_dict
  63. """
  64. 每次操作完成后会将对应的操作唯一id存储到redis
  65. 并且返回给手机端 手机端下次带着上个操作id来执行下一个操作
  66. """
  67. last_action_id = redis_client.get(device_id + "operate")
  68. step0 = redis_client.get(f"{device_id}_step0")
  69. if step0 is not None and int(step0) == 1 and last_action_id is not None and int(perform_action_id) == int(
  70. last_action_id) and perform_action_result == "success":
  71. action1_id = int(round(time.time() * 1000))
  72. """
  73. 发送第1条指令
  74. 首页点击任务
  75. """
  76. action1_dict = single_click_by_control(action1_id, target_app="com.ss.android.article.lite",
  77. target_version="9.7.0.0",
  78. package_name="com.ss.android.article.lite",
  79. control_id="com.ss.android.article.lite:id/kp", timeout=30)
  80. redis_client.set(device_id + "operate", action1_id)
  81. redis_client.set(f"{device_id}_{action1_id}_step1", "1")
  82. redis_client.delete(f"{device_id}_step0")
  83. loggerKit.info("设备:{0}, action1_id:{1}", device_id, action1_id)
  84. return action1_dict
  85. step1 = redis_client.get(f"{device_id}_{perform_action_id}_step1")
  86. if step1 is not None and int(step1) == 1 and last_action_id is not None and int(perform_action_id) == int(
  87. last_action_id) and perform_action_result == "success":
  88. loggerKit.info("设备:{0}, action1_id_mem:{1}", device_id, int(last_action_id))
  89. action2_id = int(round(time.time() * 1000))
  90. """
  91. 发送第2条指令
  92. 点击开宝箱
  93. """
  94. with open("pic/boxes.png", "rb") as image_file:
  95. encoded_string = base64.b64encode(image_file.read())
  96. action2_dict = click_pic(action2_id, target_app="com.ss.android.article.lite", target_version="9.7.0.0",
  97. package_name="com.ss.android.article.lite", pic_base64=encoded_string)
  98. redis_client.set(device_id + "operate", action2_id)
  99. redis_client.set(f"{device_id}_{action2_id}_step2", "1")
  100. redis_client.delete(f"{device_id}_{action2_id}_step1")
  101. loggerKit.info("设备:{0}, action2_id:{1}", device_id, action2_id)
  102. return action2_dict
  103. step2 = redis_client.get(f"{device_id}_{perform_action_id}_step2")
  104. if step2 is not None and int(step2) == 1 and last_action_id is not None and int(perform_action_id) == int(
  105. last_action_id) and perform_action_result == "success":
  106. loggerKit.info("设备:{0}, action2_id_mem:{1}", device_id, int(last_action_id))
  107. action3_id = int(round(time.time() * 1000))
  108. """
  109. 发送第3条指令
  110. 看视频再领金币
  111. """
  112. with open("pic/video.png", "rb") as image_file:
  113. encoded_string = base64.b64encode(image_file.read())
  114. action3_dict = click_pic(action3_id, target_app="com.ss.android.article.lite", target_version="9.7.0.0",
  115. package_name="com.ss.android.article.lite", pic_base64=encoded_string)
  116. redis_client.set(device_id + "operate", action3_id)
  117. redis_client.set(f"{device_id}_{action3_id}_step3", "1")
  118. redis_client.delete(f"{device_id}_{action3_id}_step2")
  119. loggerKit.info("设备:{0}, action3_id:{1}", device_id, action3_id)
  120. return action3_dict
  121. while True:
  122. action3_id_mem = redis_client.get(device_id + "operate")
  123. step3 = redis_client.get(f"{device_id}_{perform_action_id}_step3")
  124. if step3 is not None and int(step3) == 1 and action3_id_mem is not None and int(perform_action_id) == int(
  125. action3_id_mem) and perform_action_result == "success":
  126. loggerKit.info("设备:{0}, action3_id_mem:{1}", device_id, int(action3_id_mem))
  127. action4_id = int(round(time.time() * 1000))
  128. """
  129. 发送第4条指令
  130. 点击领取成功
  131. """
  132. with open("pic/draw.png", "rb") as image_file:
  133. encoded_string = base64.b64encode(image_file.read())
  134. action4_dict = click_pic(action4_id, target_app="com.ss.android.article.lite", target_version="9.7.0.0",
  135. package_name="com.ss.android.article.lite", pic_base64=encoded_string)
  136. redis_client.set(device_id + "operate", action4_id)
  137. redis_client.set(f"{device_id}_{action4_id}_step4", "1")
  138. redis_client.delete(f"{device_id}_{action4_id}_step3")
  139. loggerKit.info("设备:{0}, action3_id:{1}", device_id, action4_id)
  140. return action4_dict
  141. """
  142. 出现逛街最多则跳出循环
  143. """
  144. with open("pic/video.png", "rb") as image_file:
  145. encoded_string = base64.b64encode(image_file.read())
  146. if encoded_string is not None:
  147. break
  148. else:
  149. action4_id_mem = redis_client.get(device_id + "operate")
  150. step4 = redis_client.get(f"{device_id}_{perform_action_id}_step4")
  151. if step4 is not None and int(step4) == 1 and action4_id_mem is not None and int(
  152. perform_action_id) == int(
  153. action4_id_mem) and perform_action_result == "success":
  154. loggerKit.info("设备:{0}, action4_id_mem:{1}", device_id, int(action4_id_mem))
  155. action5_id = int(round(time.time() * 1000))
  156. """
  157. 发送第5条指令
  158. 看视频再领金币
  159. """
  160. with open("pic/video.png", "rb") as image_file:
  161. encoded_string = base64.b64encode(image_file.read())
  162. action5_dict = click_pic(action5_id, target_app="com.ss.android.article.lite",
  163. target_version="9.7.0.0",
  164. package_name="com.ss.android.article.lite", pic_base64=encoded_string)
  165. redis_client.set(device_id + "operate", action5_id)
  166. redis_client.set(f"{device_id}_{action5_id}_step5", "1")
  167. redis_client.delete(f"{device_id}_{action5_id}_step4")
  168. loggerKit.info("设备:{0}, action3_id:{1}", device_id, action5_id)
  169. return action5_dict
  170. """
  171. 开始看视频
  172. """
  173. time.sleep(38)
  174. """
  175. 停止app
  176. """
  177. step5 = redis_client.get(f"{device_id}_step5")
  178. if step5 is not None and int(step5) == 1 and last_action_id is not None and int(perform_action_id) == int(
  179. last_action_id) and perform_action_result == "success":
  180. loggerKit.info("设备:{0}, action10_id_mem:{1}", device_id, int(last_action_id))
  181. action6_id = int(round(time.time() * 1000))
  182. """
  183. 停止指令
  184. 停止app
  185. """
  186. action6_dict = stop_app(action6_id, target_app="com.ss.android.article.lite",
  187. target_version="9.7.0.0",
  188. package_name="com.ss.android.article.lite")
  189. redis_client.delete(f"{device_id}_step4")
  190. del_key_vague(device_id)
  191. loggerKit.info("设备:{0}, action6_dict:{1}", device_id, action6_dict)
  192. # 回调任务中心修改任务状态
  193. callback_task(None, None, task_id, device_id, 1, None)
  194. return action6_dict
  195. else:
  196. action0_id = int(round(time.time() * 1000))
  197. """
  198. 启动指令
  199. 启动app
  200. """
  201. action0_dict = start_app(action0_id, target_app="com.ss.android.article.lite",
  202. target_version="9.7.0.0",
  203. package_name="com.ss.android.article.lite")
  204. redis_client.set(device_id + "operate", action0_id)
  205. redis_client.set(f"{device_id}_step0", "1")
  206. redis_client.delete(f"{device_id}_step9")
  207. loggerKit.info("设备:{0}, action0_id:{1}", device_id, action0_id)
  208. return action0_dict