simple_browser_video.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. """
  2. 简单刷视频
  3. """
  4. import time
  5. from func.action_func import del_key_vague
  6. from task.task_job import callback_task
  7. from tools import loggerKit, redis_client
  8. from scene.oprator.atom_data import start_app, stop_app, continual_swipe_screen
  9. import yaml
  10. with open('config.yaml', 'r') as file:
  11. config = yaml.load(file, Loader=yaml.FullLoader)
  12. extern_domain = config['bmp-cp']['extern_domain']
  13. # 任务执行回调url
  14. task_callback_url = extern_domain + config['bmp-cp']['task_callback_url']
  15. # 抖音急速版根据刷视频获取奖金
  16. # version 28.8.0
  17. def douyin_spider(device_serial, task_id, keyword, media_channel, data):
  18. loggerKit.info('请求信息:{0}'.format(data))
  19. device_id = data.get("deviceID")
  20. perform_action_id = data.get("performActionId")
  21. result = data.get("result")
  22. if result is not None:
  23. """
  24. 非首个指令
  25. """
  26. perform_action_result = result.get("performActionResult")
  27. if perform_action_result is None:
  28. return_dict = {
  29. "data": "",
  30. "code": -2,
  31. "message": "fail, performActionResult is null"
  32. }
  33. # 回调任务中心
  34. del_key_vague(device_id)
  35. callback_task(500, '任务执行失败', task_id, device_id, 0, None)
  36. return return_dict
  37. if perform_action_result != "success":
  38. # 回调任务中心
  39. return_dict = {
  40. "data": "",
  41. "code": -2,
  42. "message": "fail, performActionResult is null"
  43. }
  44. del_key_vague(device_id)
  45. callback_task(500, '任务执行失败', task_id, device_id, 0, None)
  46. return return_dict
  47. # 每次操作完成后会将对应的操作唯一id存储到redis,并且返回给手机端 手机端下次带着上个操作id来执行下一个操作
  48. last_action_id = redis_client.get(device_id + "operate")
  49. step0 = redis_client.get(f"{device_id}_step0")
  50. if step0 is not None and int(step0) == 1 and last_action_id is not None and int(perform_action_id) == int(
  51. last_action_id) \
  52. and perform_action_result == "success":
  53. loggerKit.info("设备:{0}, action2_id_mem:{1}", device_id, int(last_action_id))
  54. action1_id = int(round(time.time() * 1000))
  55. """
  56. 发送第3条指令
  57. 连续滑动视频
  58. """
  59. action3_dict = continual_swipe_screen(action1_id, package_name="com.ss.android.ugc.aweme.lite",
  60. continuous_time=60)
  61. redis_client.set(device_id + "operate", action1_id)
  62. redis_client.set(f"{device_id}_step1", "1")
  63. redis_client.delete(f"{device_id}_step0")
  64. loggerKit.info("设备:{0}, action1_id:{1}", device_id, action1_id)
  65. return action3_dict
  66. """
  67. 停止app
  68. """
  69. step2 = redis_client.get(f"{device_id}_step1")
  70. if (step2 is not None and int(step2) == 1 and last_action_id is not None and int(perform_action_id) == int(last_action_id)
  71. and perform_action_result == "success"):
  72. loggerKit.info("设备:{0}, action10_id_mem:{1}", device_id, int(last_action_id))
  73. action4_id = int(round(time.time() * 1000))
  74. """
  75. 停止指令
  76. 停止app
  77. """
  78. action12_dict = stop_app(action4_id, target_app="douyin", target_version="28.8.0",
  79. package_name="com.ss.android.ugc.aweme.lite")
  80. redis_client.delete(f"{device_id}_step1")
  81. del_key_vague(device_id)
  82. loggerKit.info("设备:{0}, action12_id:{1}", device_id, action12_dict)
  83. # 回调任务中心修改任务状态
  84. callback_task(None, None, task_id, device_id, 1, None)
  85. return action12_dict
  86. else:
  87. action0_id = int(round(time.time() * 1000))
  88. """
  89. 启动指令
  90. 启动app
  91. """
  92. action0_dict = start_app(action0_id, target_app="douyin", target_version="28.8.0",
  93. package_name="com.ss.android.ugc.aweme.lite")
  94. redis_client.set(device_id + "operate", action0_id)
  95. redis_client.set(f"{device_id}_step0", "1")
  96. redis_client.delete(f"{device_id}_step9")
  97. loggerKit.info("设备:{0}, action0_id:{1}", device_id, action0_id)
  98. return action0_dict
  99. # post请求
  100. # def call_back_request(error_code, error_msg, task_id, task_status, task_execute_response, content, demo_flag):
  101. # response = {
  102. # "errorCode": error_code,
  103. # "errorMsg": error_msg,
  104. # "taskId": task_id,
  105. # "taskStatus": task_status,
  106. # "taskExecuteResponse": task_execute_response,
  107. # "content": content,
  108. # "demoFlag": demo_flag
  109. # }
  110. # return response
  111. #
  112. #
  113. # # 回调任务中心接口
  114. # def callback_task(err_code, err_msg, task_id, device_id, execute_status, result):
  115. # callback_request2 = call_back_request(err_code, err_msg, task_id, execute_status, result, None, None)
  116. # loggerKit.info("thread[{0}=>{1}], taskId:{2}, 设备号:{3}, url:{4} 。回调开始", threading.current_thread().name,
  117. # threading.get_ident(), task_id, device_id, task_callback_url)
  118. # current_timeout = (5, 10)
  119. # callback_response2 = requests.post(task_callback_url, json=callback_request2, timeout=current_timeout)
  120. # loggerKit.info("thread[{0}=>{1}], taskId:{2},设备号:{3}。回调结束:{4}", threading.current_thread().name,
  121. # threading.get_ident(), task_id, device_id, json.dumps(callback_response2.text, ensure_ascii=False))
  122. # return callback_response2