platform_sign.py 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. """
  2. 平台用户签到
  3. """
  4. import time
  5. from func.action_func import del_key_vague
  6. from scene.oprator.atom_data import single_click_by_control, click_pic, stop_app, start_app
  7. from task.task_job import callback_task
  8. from tools import loggerKit, redis_client
  9. from tools.pic_base64_util import pic_to_base64
  10. def platform_sign(task_id, device_id, data):
  11. loggerKit.info('请求信息:{0}'.format(data))
  12. device_id = data.get("deviceID")
  13. perform_action_id = data.get("performActionId")
  14. result = data.get("result")
  15. if result is not None:
  16. """
  17. 非首个指令
  18. """
  19. perform_action_result = result.get("performActionResult")
  20. if perform_action_result is None:
  21. return_dict = {
  22. "data": "",
  23. "code": -2,
  24. "message": "fail, performActionResult is null"
  25. }
  26. # 回调任务中心
  27. del_key_vague(device_id)
  28. callback_task(500, '指令执行失败', task_id, device_id, 0, None)
  29. return return_dict
  30. # 指令执行失败
  31. if perform_action_result == "failure":
  32. # 回调任务中心
  33. return_dict = {
  34. "data": "",
  35. "code": -2,
  36. "message": "fail, performActionResult is null"
  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 == "stop":
  43. # 回调任务中心
  44. return_dict = {
  45. "data": "",
  46. "code": -2,
  47. "message": "指令被用户终止"
  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 == "eleNotFound":
  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="dongchedi", target_version="7.9.0",
  77. package_name="com.ss.android.auto",
  78. control_id="android:id/tabs", timeout=5, sleep_time=5,
  79. item_index=4)
  80. redis_client.set(device_id + "operate", action1_id)
  81. redis_client.set(f"{device_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}_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}, last_action_id:{1}", device_id, int(last_action_id))
  89. action2_id = int(round(time.time() * 1000))
  90. """
  91. 发送第2条指令
  92. 点击进入签到元素
  93. """
  94. action2_dict = single_click_by_control(action2_id, target_app="dongchedi", target_version="7.9.0",
  95. package_name="com.ss.android.auto",
  96. control_id="com.ss.android.auto:id/a6l",
  97. timeout=5, sleep_time=5)
  98. redis_client.set(device_id + "operate", action2_id)
  99. redis_client.set(f"{device_id}_step2", "1")
  100. redis_client.delete(f"{device_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}_step2")
  104. dongchedi_sign_path = 'dongchedi/pic/dongchedi_sign.png'
  105. if step2 is not None and int(step2) == 1 and last_action_id is not None and int(perform_action_id) == int(
  106. last_action_id) and perform_action_result == "success":
  107. action3_id = int(round(time.time() * 1000))
  108. """
  109. 发送第3条指令
  110. 点击签到
  111. """
  112. dongchedi_sign_base64 = pic_to_base64(dongchedi_sign_path)
  113. action3_dict = click_pic(action3_id, target_app="dongchedi", target_version="7.9.0",
  114. package_name="com.ss.android.auto",
  115. pic_base64=dongchedi_sign_base64)
  116. redis_client.set(device_id + "operate", action3_id)
  117. redis_client.set(f"{device_id}_step3", "1")
  118. redis_client.delete(f"{device_id}_step2")
  119. loggerKit.info("设备:{0}, action3_id:{1}", device_id, action3_id)
  120. return action3_dict
  121. step3 = redis_client.get(f"{device_id}_step3")
  122. if step3 is not None and int(step3) == 1 and (last_action_id is not None
  123. and int(perform_action_id) == int(last_action_id)
  124. and perform_action_result == "success"):
  125. loggerKit.info("设备:{0}, action4_id_mem:{1}", device_id, int(last_action_id))
  126. action4_id = int(round(time.time() * 1000))
  127. """
  128. 发送第4条指令
  129. 关闭app
  130. """
  131. action4_dict = stop_app(action4_id, target_version="7.9.0", target_app="dongchedi", timeout=5, sleep_time=3)
  132. del_key_vague(device_id)
  133. loggerKit.info("设备:{0}, action4_id:{1}", device_id, action4_dict)
  134. # 回调任务中心修改任务状态
  135. callback_task(None, None, task_id, device_id, 1, None)
  136. return action4_dict
  137. else:
  138. action0_id = int(round(time.time() * 1000))
  139. """
  140. 启动指令
  141. 启动app
  142. """
  143. action0_dict = start_app(action0_id, target_version="7.9.0")
  144. redis_client.set(device_id + "operate", action0_id)
  145. redis_client.set(f"{device_id}_step0", "1")
  146. loggerKit.info("设备:{0}, action0_id:{1}", device_id, action0_id)
  147. return action0_dict