dongchedi_sign.py 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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, stop_app, start_app, \
  7. single_click_by_text, click_pic
  8. from task.task_job import callback_task
  9. from tools import loggerKit, redis_client
  10. from tools.pic_base64_util import pic_to_base64
  11. def dongchedi_sign(task_id, mobile, data):
  12. loggerKit.info('请求信息:{0}'.format(data))
  13. device_id = data.get("deviceID")
  14. perform_action_id = data.get("performActionId")
  15. result = data.get("result")
  16. if result is not None:
  17. """
  18. 非首个指令
  19. """
  20. perform_action_result = result.get("performActionResult")
  21. if perform_action_result is None:
  22. return_dict = {
  23. "data": "",
  24. "code": -2,
  25. "message": "fail, performActionResult is null"
  26. }
  27. # 回调任务中心
  28. del_key_vague(device_id)
  29. callback_task(500, '指令执行失败', task_id, mobile, 0, None)
  30. return return_dict
  31. # 指令执行失败
  32. if perform_action_result == "failure":
  33. # 回调任务中心
  34. return_dict = {
  35. "data": "",
  36. "code": -2,
  37. "message": "fail, performActionResult is null"
  38. }
  39. del_key_vague(device_id)
  40. callback_task(500, '指令执行失败', task_id, mobile, 0, None)
  41. return return_dict
  42. # 终止指令
  43. if perform_action_result == "stop":
  44. # 回调任务中心
  45. return_dict = {
  46. "data": "",
  47. "code": -2,
  48. "message": "指令被用户终止"
  49. }
  50. del_key_vague(device_id)
  51. callback_task(500, '指令被用户终止', task_id, mobile, 0, None)
  52. return return_dict
  53. # 终止指令
  54. if perform_action_result == "eleNotFound":
  55. # 回调任务中心
  56. return_dict = {
  57. "data": "",
  58. "code": -2,
  59. "message": "未找到签到指示"
  60. }
  61. del_key_vague(device_id)
  62. callback_task(500, '未找到签到指示,该账号当天可能已经签到过', task_id, mobile, 0, None)
  63. return return_dict
  64. """
  65. 每次操作完成后会将对应的操作唯一id存储到redis
  66. 并且返回给手机端 手机端下次带着上个操作id来执行下一个操作
  67. """
  68. last_action_id = redis_client.get(device_id + "operate")
  69. step0 = redis_client.get(f"{device_id}_step0")
  70. if step0 is not None and int(step0) == 1 and last_action_id is not None and int(perform_action_id) == int(
  71. last_action_id) and perform_action_result == "success":
  72. action1_id = int(round(time.time() * 1000))
  73. """
  74. 发送第1条指令
  75. 点击进入我的页面
  76. """
  77. action1_dict = single_click_by_control(action1_id, target_app="dongchedi", target_version="7.9.0",
  78. package_name="com.ss.android.auto",
  79. control_id="android:id/tabs", timeout=5, sleep_time=5,
  80. item_index=4)
  81. redis_client.set(device_id + "operate", action1_id)
  82. redis_client.set(f"{device_id}_step1", "1")
  83. redis_client.delete(f"{device_id}_step0")
  84. loggerKit.info("设备:{0}, action1_id:{1}", device_id, action1_id)
  85. return action1_dict
  86. step1 = redis_client.get(f"{device_id}_step1")
  87. if step1 is not None and int(step1) == 1 and last_action_id is not None and int(perform_action_id) == int(
  88. last_action_id) and perform_action_result == "success":
  89. loggerKit.info("设备:{0}, last_action_id:{1}", device_id, int(last_action_id))
  90. action2_id = int(round(time.time() * 1000))
  91. """
  92. 发送第2条指令
  93. 点击进入签到元素
  94. """
  95. action2_dict = single_click_by_control(action2_id, target_app="dongchedi", target_version="7.9.0",
  96. package_name="com.ss.android.auto",
  97. control_id="com.ss.android.auto:id/a6l",
  98. timeout=5, sleep_time=5)
  99. redis_client.set(device_id + "operate", action2_id)
  100. redis_client.set(f"{device_id}_step2", "1")
  101. redis_client.delete(f"{device_id}_step1")
  102. loggerKit.info("设备:{0}, action2_id:{1}", device_id, action2_id)
  103. return action2_dict
  104. step2 = redis_client.get(f"{device_id}_step2")
  105. dongchedi_sign_path = 'dongchedi/pic/dongchedi_sign.png'
  106. if step2 is not None and int(step2) == 1 and last_action_id is not None and int(perform_action_id) == int(
  107. last_action_id) and perform_action_result == "success":
  108. action3_id = int(round(time.time() * 1000))
  109. """
  110. 发送第3条指令
  111. 点击签到
  112. """
  113. dongchedi_sign_base64 = pic_to_base64(dongchedi_sign_path)
  114. action3_dict = click_pic(action3_id, target_app="dongchedi", target_version="7.9.0",
  115. package_name="com.ss.android.auto",
  116. pic_base64=dongchedi_sign_base64)
  117. redis_client.set(device_id + "operate", action3_id)
  118. redis_client.set(f"{device_id}_step3", "1")
  119. redis_client.delete(f"{device_id}_step2")
  120. loggerKit.info("设备:{0}, action3_id:{1}", device_id, action3_id)
  121. return action3_dict
  122. step3 = redis_client.get(f"{device_id}_step3")
  123. if step3 is not None and int(step3) == 1 and (last_action_id is not None
  124. and int(perform_action_id) == int(last_action_id)
  125. and perform_action_result == "success"):
  126. loggerKit.info("设备:{0}, action4_id_mem:{1}", device_id, int(last_action_id))
  127. action4_id = int(round(time.time() * 1000))
  128. """
  129. 发送第4条指令
  130. 关闭app
  131. """
  132. action4_dict = stop_app(action4_id, target_version="7.9.0", target_app="dongchedi", timeout=5, sleep_time=3)
  133. del_key_vague(device_id)
  134. loggerKit.info("设备:{0}, action4_id:{1}", device_id, action4_dict)
  135. # 回调任务中心修改任务状态
  136. callback_task(None, None, task_id, mobile, 1, None)
  137. return action4_dict
  138. else:
  139. action0_id = int(round(time.time() * 1000))
  140. """
  141. 启动指令
  142. 启动app
  143. """
  144. action0_dict = start_app(action0_id, target_version="7.9.0")
  145. redis_client.set(device_id + "operate", action0_id)
  146. redis_client.set(f"{device_id}_step0", "1")
  147. loggerKit.info("设备:{0}, action0_id:{1}", device_id, action0_id)
  148. return action0_dict