tomato_sign.py 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. """
  2. 番茄小说
  3. 签到赚金币
  4. """
  5. import time
  6. from func.action_func import del_key_vague
  7. from scene.oprator.atom_data import single_click_by_control, click_by_content, continual_swipe_screen, stop_app, \
  8. start_app, single_click_by_pic
  9. from tools.pic_base64_util import pic_to_base64
  10. from task.task_job import call_back_task_reply, callback_task
  11. from tools import loggerKit, redis_client
  12. def watch_goods(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. call_back_task_reply(500, '指令执行失败', task_id, device_id, 0, None, 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. call_back_task_reply(500, '指令执行失败', task_id, device_id, 0, None, 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. call_back_task_reply(500, '指令被用户终止', task_id, device_id, 0, None, 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. call_back_task_reply(500, '未找到签到指示,该账号当天可能已经签到过', task_id, device_id, 0, None, None)
  66. return return_dict
  67. """
  68. 每次操作完成后会将对应的操作唯一id存储到redis
  69. 并且返回给手机端 手机端下次带着上个操作id来执行下一个操作
  70. """
  71. last_action_id = redis_client.get(device_id + "operate")
  72. step0 = redis_client.get(f"{device_id}_step0")
  73. if (step0 is not None and int(step0) == 1 and last_action_id is not None and int(perform_action_id) == int(
  74. last_action_id)
  75. and perform_action_result == "success"):
  76. action1_id = int(round(time.time() * 1000))
  77. """
  78. 发送第1条指令
  79. 点击:福利
  80. """
  81. action1_dict = single_click_by_control(action1_id, target_app="dragon",
  82. target_version="6.1.7",
  83. package_name="com.dragon.read",
  84. control_id="com.dragon.read:id/de3")
  85. redis_client.set(device_id + "operate", action1_id)
  86. redis_client.set(f"{device_id}_step1", "1")
  87. redis_client.delete(f"{device_id}_step0")
  88. loggerKit.info("taskId:{0}, action1_id:{1}", task_id, action1_id)
  89. return action1_dict
  90. step1 = redis_client.get(f"{device_id}_step1")
  91. if step1 is not None and int(step1) == 1 and last_action_id is not None and int(perform_action_id) == int(
  92. last_action_id):
  93. loggerKit.info("设备:{0}, last_action_id:{1}", device_id, int(last_action_id))
  94. action2_id = int(round(time.time() * 1000))
  95. # 元素未找到
  96. if perform_action_result == "invalid operation":
  97. # 回调任务中心
  98. return_dict = {
  99. "data": "",
  100. "code": -2,
  101. "message": "fail, performActionResult is not success"
  102. }
  103. del_key_vague(device_id)
  104. call_back_task_reply(500, '任务执行失败,元素未找到', task_id, device_id, 0, None, None)
  105. return return_dict
  106. """
  107. 发送第2条指令
  108. 向上滑动屏幕后,点击"签到领金币"
  109. """
  110. action2_dict = click_by_content(action2_id,
  111. target_app="dragon",
  112. target_version="6.1.7",
  113. package_name="com.dragon.read",
  114. title="签到领金币"
  115. )
  116. redis_client.set(device_id + "operate", action2_id)
  117. redis_client.set(f"{device_id}_step2", "1")
  118. redis_client.delete(f"{device_id}_step1")
  119. loggerKit.info("taskId:{0}, action2_id:{1}", task_id, action2_id)
  120. return action2_dict
  121. step2 = redis_client.get(f"{device_id}_step2")
  122. if step2 is not None and int(step2) == 1 and last_action_id is not None and int(perform_action_id) == int(
  123. last_action_id):
  124. loggerKit.info("设备:{0}, last_action_id:{1}", device_id, int(last_action_id))
  125. action3_id = int(round(time.time() * 1000))
  126. """
  127. 发送第3条指令
  128. 根据图片点击签到
  129. """
  130. sign_path = 'sign.png'
  131. sign_base64 = pic_to_base64(sign_path)
  132. action3_dict = single_click_by_pic(action3_id,
  133. target_app="dragon",
  134. target_version="6.1.7",
  135. package_name="com.dragon.read",
  136. base64_pic=sign_base64
  137. )
  138. redis_client.set(device_id + "operate", action3_id)
  139. redis_client.set(f"{device_id}_step3", "1")
  140. redis_client.delete(f"{device_id}_step2")
  141. loggerKit.info("taskId:{0}, action3_id:{1}", task_id, action3_id)
  142. return action3_dict
  143. """
  144. 停止app
  145. """
  146. step4 = redis_client.get(f"{device_id}_step4")
  147. if step4 is not None and int(step4) == 1 and last_action_id is not None and int(perform_action_id) == int(
  148. last_action_id) and perform_action_result == "success":
  149. loggerKit.info("设备:{0}, action10_id_mem:{1}", device_id, int(last_action_id))
  150. action5_id = int(round(time.time() * 1000))
  151. """
  152. 停止指令
  153. 停止app
  154. """
  155. action5_dict = stop_app(action5_id, target_app="dragon",
  156. target_version="6.1.7",
  157. package_name="com.dragon.read")
  158. redis_client.delete(f"{device_id}_step4")
  159. del_key_vague(device_id)
  160. loggerKit.info("设备:{0}, action12_id:{1}", device_id, action5_dict)
  161. # 回调任务中心修改任务状态
  162. callback_task(None, None, task_id, device_id, 1, None)
  163. return action5_dict
  164. else:
  165. action0_id = int(round(time.time() * 1000))
  166. """
  167. 启动指令
  168. 启动app
  169. """
  170. action0_dict = start_app(action0_id, target_app="com.ss.android.article.lite",
  171. target_version="9.7.0.0",
  172. package_name="com.ss.android.article.lite")
  173. redis_client.set(device_id + "operate", action0_id)
  174. redis_client.set(f"{device_id}_step0", "1")
  175. redis_client.delete(f"{device_id}_step9")
  176. loggerKit.info("设备:{0}, action0_id:{1}", device_id, action0_id)
  177. return action0_dict