cubic_simple_action.py 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. """
  2. 汽车之家官媒互动
  3. """
  4. import random
  5. import time
  6. from func.action_func import del_key_vague
  7. from scene.oprator.atom_data import single_click_by_control, send_text_by_control, swipe_screen, \
  8. stop_app, start_app, get_content_by_control, single_click_by_control_exact
  9. from tools import redis_client, loggerKit
  10. import json
  11. import httpx
  12. import threading
  13. import yaml
  14. import requests
  15. from urllib.parse import quote
  16. with open('config.yaml', 'r') as file:
  17. config = yaml.load(file, Loader=yaml.FullLoader)
  18. extern_domain = config['bmp-cp']['extern_domain']
  19. # 任务执行回调url
  20. task_callback_url = extern_domain + config['bmp-cp']['task_callback_url']
  21. # 调用AIGC接口
  22. post_ai_gc_url = extern_domain + config['bmp-content-center']['comment_local_url']
  23. get_commented_list_url = extern_domain + config['bmp-cp']['get_commented_list_url']
  24. def cubic_simple_action(task_id, device_id, data):
  25. loggerKit.info('请求信息:{0}'.format(data))
  26. device_id = data.get("deviceID")
  27. perform_action_id = data.get("performActionId")
  28. result = data.get("result")
  29. inner_data = data.get("data")
  30. # title = inner_data.get("resourceName")
  31. # author = inner_data.get("subResourceName")
  32. extension_info = data['data']['extendInfo']
  33. extension_info = json.loads(extension_info)
  34. title = extension_info['title']
  35. author = extension_info['author']
  36. loggerKit.info("inner_data:{0}, keyword:{1}", inner_data, inner_data.get("resourceName"))
  37. if result is not None:
  38. """
  39. 非首个指令
  40. """
  41. perform_action_result = result.get("performActionResult")
  42. if perform_action_result is None:
  43. return_dict = {
  44. "data": "",
  45. "code": -2,
  46. "message": "fail, performActionResult is null"
  47. }
  48. # 回调任务中心
  49. del_key_vague(device_id)
  50. call_back_task_reply(500, '指令执行失败', task_id, device_id, 0, None, None)
  51. return return_dict
  52. # 指令执行失败
  53. if perform_action_result == "failure":
  54. # 回调任务中心
  55. return_dict = {
  56. "data": "",
  57. "code": -2,
  58. "message": "fail, performActionResult is null"
  59. }
  60. del_key_vague(device_id)
  61. call_back_task_reply(500, '指令执行失败', task_id, device_id, 0, None, None)
  62. return return_dict
  63. # 终止指令
  64. if perform_action_result == "stop":
  65. # 回调任务中心
  66. return_dict = {
  67. "data": "",
  68. "code": -2,
  69. "message": "指令被用户终止"
  70. }
  71. del_key_vague(device_id)
  72. call_back_task_reply(500, '指令被用户终止', task_id, device_id, 0, None, None)
  73. return return_dict
  74. # 终止指令
  75. if perform_action_result == "eleNotFound":
  76. # 回调任务中心
  77. return_dict = {
  78. "data": "",
  79. "code": -2,
  80. "message": "未找到签到指示"
  81. }
  82. del_key_vague(device_id)
  83. call_back_task_reply(500, '未找到签到指示,该账号当天可能已经签到过', task_id, device_id, 0, None, None)
  84. return return_dict
  85. """
  86. 每次操作完成后会将对应的操作唯一id存储到redis
  87. 并且返回给手机端 手机端下次带着上个操作id来执行下一个操作
  88. """
  89. last_action_id = redis_client.get(device_id + "operate")
  90. step0 = redis_client.get(f"{device_id}_step0")
  91. if (step0 is not None and int(step0) == 1 and last_action_id is not None and int(perform_action_id) == int(
  92. last_action_id)
  93. and perform_action_result == "success"):
  94. action1_id = int(round(time.time() * 1000))
  95. """
  96. 发送第1条指令
  97. 点击:搜索目标帖子
  98. """
  99. action1_dict = single_click_by_control(action1_id, target_app="cubic",
  100. target_version="11.59.5",
  101. package_name="com.cubic.autohome",
  102. control_id="com.cubic.autohome:id/search_bar_vertical_banner_view",
  103. item_index=4)
  104. redis_client.set(device_id + "operate", action1_id)
  105. redis_client.set(f"{device_id}_step1", "1")
  106. redis_client.delete(f"{device_id}_step0")
  107. loggerKit.info("taskId:{0}, action1_id:{1}", task_id, action1_id)
  108. return action1_dict
  109. step1 = redis_client.get(f"{device_id}_step1")
  110. if step1 is not None and int(step1) == 1 and last_action_id is not None and int(perform_action_id) == int(
  111. last_action_id):
  112. loggerKit.info("设备:{0}, last_action_id:{1}", device_id, int(last_action_id))
  113. action2_id = int(round(time.time() * 1000))
  114. # 元素未找到
  115. if perform_action_result == "invalid operation":
  116. # 回调任务中心
  117. return_dict = {
  118. "data": "",
  119. "code": -2,
  120. "message": "fail, performActionResult is not success"
  121. }
  122. del_key_vague(device_id)
  123. call_back_task_reply(500, '任务执行失败,元素未找到', task_id, device_id, 0, None, None)
  124. return return_dict
  125. """
  126. 发送第2条指令
  127. 在搜索框输入作者
  128. """
  129. action2_dict = send_text_by_control(action2_id,
  130. control_id="com.autohome.plugin.search:id"
  131. "/fragment_search_keyword_autocompleteview",
  132. content=f'{author}',
  133. target_app="cubic",
  134. target_version="11.59.5",
  135. package_name="com.cubic.autohome")
  136. redis_client.set(device_id + "operate", action2_id)
  137. redis_client.set(f"{device_id}_step2", "1")
  138. redis_client.delete(f"{device_id}_step1")
  139. loggerKit.info("taskId:{0}, action2_id:{1}", task_id, action2_id)
  140. return action2_dict
  141. step2 = redis_client.get(f"{device_id}_step2")
  142. if step2 is not None and int(step2) == 1 and last_action_id is not None and int(perform_action_id) == int(
  143. last_action_id):
  144. loggerKit.info("设备:{0}, last_action_id:{1}", device_id, int(last_action_id))
  145. action3_id = int(round(time.time() * 1000))
  146. # 元素未找到
  147. if perform_action_result == "invalid operation":
  148. # 回调任务中心
  149. return_dict = {
  150. "data": "",
  151. "code": -2,
  152. "message": "fail, performActionResult is not success"
  153. }
  154. del_key_vague(device_id)
  155. call_back_task_reply(500, '任务执行失败,元素未找到', task_id, device_id, 0, None, None)
  156. return return_dict
  157. """
  158. 发送第3条指令
  159. 点击搜索
  160. """
  161. action3_dict = single_click_by_control(action3_id,
  162. target_app="cubic",
  163. target_version="11.59.5",
  164. package_name="com.cubic.autohome",
  165. control_id="com.autohome.plugin.search:id"
  166. "/fragment_search_action_textview")
  167. redis_client.set(device_id + "operate", action3_id)
  168. redis_client.set(f"{device_id}_step3", "1")
  169. redis_client.delete(f"{device_id}_step2")
  170. loggerKit.info("taskId:{0}, action3_id:{1}", task_id, action3_id)
  171. return action3_dict
  172. step3 = redis_client.get(f"{device_id}_step3")
  173. if step3 is not None and int(step3) == 1 and last_action_id is not None and int(perform_action_id) == int(
  174. last_action_id):
  175. loggerKit.info("设备:{0}, last_action_id:{1}", device_id, int(last_action_id))
  176. action4_id = int(round(time.time() * 1000))
  177. # 元素未找到
  178. if perform_action_result == "invalid operation":
  179. # 回调任务中心
  180. return_dict = {
  181. "data": "",
  182. "code": -2,
  183. "message": "fail, performActionResult is not success"
  184. }
  185. del_key_vague(device_id)
  186. call_back_task_reply(500, '任务执行失败,元素未找到', task_id, device_id, 0, None, None)
  187. return return_dict
  188. """
  189. 发送第4条指令
  190. 通过文本点击
  191. """
  192. action4_dict = get_content_by_control(action4_id, title=f'{author}',
  193. target_app="cubic",
  194. target_version="11.59.5",
  195. package_name="com.cubic.autohome")
  196. redis_client.set(device_id + "operate", action4_id)
  197. redis_client.set(f"{device_id}_step4", "1")
  198. redis_client.delete(f"{device_id}_step3")
  199. loggerKit.info("taskId:{0}, action4_id:{1}", device_id, action4_id)
  200. return action4_dict
  201. step4 = redis_client.get(f"{device_id}_step4")
  202. if step4 is not None and int(step4) == 1 and last_action_id is not None and int(perform_action_id) == int(
  203. last_action_id):
  204. loggerKit.info("设备:{0}, last_action_id:{1}", device_id, int(last_action_id))
  205. action5_id = int(round(time.time() * 1000))
  206. # 元素未找到
  207. if perform_action_result == "invalid operation":
  208. # 回调任务中心
  209. return_dict = {
  210. "data": "",
  211. "code": -2,
  212. "message": "fail, performActionResult is not success"
  213. }
  214. del_key_vague(device_id)
  215. call_back_task_reply(500, '任务执行失败,元素未找到', task_id, device_id, 0, None, None)
  216. return return_dict
  217. """
  218. 发送第5条指令
  219. 通过文本点击
  220. """
  221. action5_dict = get_content_by_control(action5_id,
  222. title=f"{title}",
  223. target_app="cubic",
  224. target_version="11.59.5",
  225. package_name="com.cubic.autohome")
  226. redis_client.set(device_id + "operate", action5_id)
  227. redis_client.set(f"{device_id}_step6", "1")
  228. redis_client.delete(f"{device_id}_step4")
  229. return action5_dict
  230. step6 = redis_client.get(f"{device_id}_step6")
  231. if step6 is not None and int(step6) == 1 and last_action_id is not None and int(perform_action_id) == int(
  232. last_action_id):
  233. loggerKit.info("设备:{0}, last_action_id:{1}", device_id, int(last_action_id))
  234. action7_id = int(round(time.time() * 1000))
  235. # 元素未找到
  236. if perform_action_result == "invalid operation":
  237. # 回调任务中心
  238. return_dict = {
  239. "data": "",
  240. "code": -2,
  241. "message": "fail, performActionResult is not success"
  242. }
  243. del_key_vague(device_id)
  244. call_back_task_reply(500, '任务执行失败,元素未找到', task_id, device_id, 0, None, None)
  245. return return_dict
  246. """
  247. 点击视频/帖子点赞
  248. """
  249. action7_dict = single_click_by_control(action7_id,
  250. target_app="cubic",
  251. target_version="11.59.5",
  252. package_name="com.cubic.autohome",
  253. control_id="com.autohome.main.article:id/bottom_space",
  254. control_ids="com.autohome.main.club:id/fl_praise_root,com.autohome.main.article:id/bottom_space,com.autohome.main.article:id/moments_like",
  255. item_index=0,
  256. sub_item_index=2)
  257. redis_client.set(device_id + "operate", action7_id)
  258. redis_client.set(f"{device_id}_step7", "1")
  259. redis_client.delete(f"{device_id}_step6")
  260. return action7_dict
  261. step7 = redis_client.get(f"{device_id}_step7")
  262. if step7 is not None and int(step7) == 1 and last_action_id is not None and int(perform_action_id) == int(
  263. last_action_id):
  264. loggerKit.info("设备:{0}, last_action_id:{1}", device_id, int(last_action_id))
  265. # 元素未找到
  266. if perform_action_result == "invalid operation":
  267. # 回调任务中心
  268. return_dict = {
  269. "data": "",
  270. "code": -2,
  271. "message": "fail, performActionResult is not success"
  272. }
  273. del_key_vague(device_id)
  274. call_back_task_reply(500, '任务执行失败,元素未找到', task_id, device_id, 0, None, None)
  275. return return_dict
  276. action8_id = int(round(time.time() * 1000))
  277. """
  278. 点击视频/帖子 收藏
  279. """
  280. action8_dict = single_click_by_control(action8_id,
  281. target_app="cubic",
  282. target_version="11.59.5",
  283. package_name="com.cubic.autohome",
  284. control_id="com.autohome.main.article:id/bottom_space",
  285. control_ids="com.autohome.main.club:id/fl_collect_root,com.autohome.main.article:id/bottom_space,com.autohome.main.article:id/moments_favorite",
  286. item_index=0,
  287. sub_item_index=3)
  288. redis_client.set(device_id + "operate", action8_id)
  289. redis_client.set(f"{device_id}_step8", "1")
  290. redis_client.delete(f"{device_id}_step7")
  291. return action8_dict
  292. step8 = redis_client.get(f"{device_id}_step8")
  293. if step8 is not None and int(step8) == 1 and last_action_id is not None and int(perform_action_id) == int(
  294. last_action_id):
  295. loggerKit.info("设备:{0}, last_action_id:{1}", device_id, int(last_action_id))
  296. # 元素未找到
  297. if perform_action_result == "invalid operation":
  298. # 回调任务中心
  299. return_dict = {
  300. "data": "",
  301. "code": -2,
  302. "message": "fail, performActionResult is not success"
  303. }
  304. del_key_vague(device_id)
  305. call_back_task_reply(500, '任务执行失败,元素未找到', task_id, device_id, 0, None, None)
  306. return return_dict
  307. action8_id = int(round(time.time() * 1000))
  308. """
  309. 点击视频的评论框 进入评论区
  310. """
  311. action8_dict = single_click_by_control(action8_id,
  312. target_app="cubic",
  313. target_version="11.59.5",
  314. package_name="com.cubic.autohome",
  315. control_id="com.autohome.main.article:id/moments_comment")
  316. redis_client.set(device_id + "operate", action8_id)
  317. redis_client.set(f"{device_id}_step9", "1")
  318. redis_client.delete(f"{device_id}_step8")
  319. return action8_dict
  320. step9 = redis_client.get(f"{device_id}_step9")
  321. if step9 is not None and int(step9) == 1 and last_action_id is not None and int(perform_action_id) == int(
  322. last_action_id):
  323. loggerKit.info("设备:{0}, action4_id_mem:{1}", device_id, int(last_action_id))
  324. action10_id = int(round(time.time() * 1000))
  325. """
  326. 发送第10条指令
  327. 根据视频内容 生成评论文案将文案缓存 并且点击评论
  328. """
  329. comment_response = httpx.get(get_commented_list_url + '?resourceName=' + title, timeout=120)
  330. # 评论实体
  331. comment_body = json.loads(comment_response.text)
  332. # 评论集合
  333. comment_list = comment_body.get('data')
  334. loggerKit.info("任务id:{0}对应标题:{1},已有评论:{2}", task_id, title, comment_list)
  335. existing_comment = ''
  336. if comment_list is not None:
  337. comment_list = list(set(comment_list))
  338. existing_comment = '||'.join(comment_list)
  339. loggerKit.info("任务id:{0}对应标题:{1},拼接后的评论集合:{2}", task_id, title, existing_comment)
  340. existing_comment = quote(existing_comment)
  341. request_data = {
  342. "mode": "1",
  343. "title": title,
  344. "platform": "autohome",
  345. "comment": existing_comment
  346. }
  347. loggerKit.info("任务id:{0}对应标题:{1},请求AIGC信息:{2}", task_id, title, request_data)
  348. response = httpx.post(post_ai_gc_url, json=request_data, timeout=120)
  349. # 点击评论框
  350. action10_dict = single_click_by_control(action10_id,
  351. target_app="cubic", target_version="11.59.5",
  352. package_name="com.cubic.autohome",
  353. control_ids="com.autohome.main.club:id/topic_page_publish_entrance,com.autohome.main.article:id/article_new_bottombar_dysc,com.autohome.main.article:id/bottom_space",
  354. timeout=5,
  355. item_index=0,
  356. sub_item_index=0)
  357. if not response.is_success:
  358. # 调用AIGC获取评论失败
  359. loggerKit.info("任务id:{0}对应标题:{1},请求AIGC失败信息:{2},返回信息:{3}", task_id, title, request_data,
  360. response)
  361. redis_client.set(device_id + "autoHome" + "comments", '不错👍')
  362. redis_client.set(device_id + "operate", action10_id)
  363. redis_client.set(f"{device_id}_step10", "1")
  364. redis_client.delete(f"{device_id}_step9")
  365. loggerKit.info("设备:{0}, action10_id:{1}", device_id, action10_id)
  366. return action10_dict
  367. response_body = json.loads(response.text)
  368. reply_data = response_body.get('data')
  369. reply = reply_data.get('comment')
  370. if '内容太少' in reply or '对不起' in reply or reply is None or reply == '' or '提供' in reply:
  371. # 获取到的评论内容不符合
  372. loggerKit.info("任务id:{0}对应标题:{1},请求AIGC失败信息:{2},返回信息:{3}", task_id, title, request_data,
  373. response)
  374. redis_client.set(device_id + "autoHome" + "comments", '不错👍')
  375. redis_client.set(device_id + "operate", action10_id)
  376. redis_client.set(f"{device_id}_step10", "1")
  377. redis_client.delete(f"{device_id}_step9")
  378. loggerKit.info("设备:{0}, action10_id:{1}", device_id, action10_id)
  379. return action10_dict
  380. # 将需要评论的内容存入缓存
  381. redis_client.set(device_id + "autoHome" + "comments", reply)
  382. redis_client.set(device_id + "operate", action10_id)
  383. redis_client.set(f"{device_id}_step11", "1")
  384. redis_client.delete(f"{device_id}_step9")
  385. loggerKit.info("设备:{0}, action10_id:{1}", device_id, action10_id)
  386. return action10_dict
  387. step11 = redis_client.get(f"{device_id}_step11")
  388. if step11 is not None and int(step11) == 1 and last_action_id is not None and int(perform_action_id) == int(
  389. last_action_id) \
  390. and perform_action_result == "success":
  391. loggerKit.info("设备:{0}, action12_id_mem:{1}", device_id, int(last_action_id))
  392. # 元素未找到
  393. if perform_action_result == "invalid operation":
  394. # 回调任务中心
  395. return_dict = {
  396. "data": "",
  397. "code": -2,
  398. "message": "fail, performActionResult is not success"
  399. }
  400. del_key_vague(device_id)
  401. call_back_task_reply(500, '任务执行失败,元素未找到', task_id, device_id, 0, None, None)
  402. return return_dict
  403. action12_id = int(round(time.time() * 1000))
  404. """
  405. 发送第12条指令
  406. 对评论框进行赋值
  407. """
  408. reply = redis_client.get(device_id + "autoHome" + "comments")
  409. if reply is None:
  410. # 调用AIGC获取评论失败
  411. del_key_vague(device_id)
  412. return_dict = {
  413. "data": "",
  414. "code": -2,
  415. "message": "fail, result_text is null"
  416. }
  417. call_back_task_reply(500, '获取到的内容标题为null,无法评论', task_id, device_id, 0, None, None)
  418. return return_dict
  419. action12_dict = send_text_by_control(action12_id, target_app="cubic",
  420. target_version="11.59.5",
  421. package_name="com.cubic.autohome",
  422. control_id="com.cubic.autohome:id/input_edit",
  423. content=reply, timeout=5)
  424. redis_client.set(device_id + "operate", action12_id)
  425. redis_client.set(f"{device_id}_step12", "1")
  426. redis_client.delete(f"{device_id}_step11")
  427. content_result = content_detail(title, title, reply, None)
  428. redis_client.set(device_id + "reply_json", json.dumps(content_result.to_dict(), ensure_ascii=False))
  429. loggerKit.info("设备:{0}, action12_id:{1}", device_id, action12_id)
  430. return action12_dict
  431. step12 = redis_client.get(f"{device_id}_step12")
  432. if step12 is not None and int(step12) == 1 and last_action_id is not None and int(perform_action_id) == int(
  433. last_action_id) \
  434. and perform_action_result == "success":
  435. loggerKit.info("设备:{0}, action13_id_mem:{1}", device_id, int(last_action_id))
  436. # 元素未找到
  437. if perform_action_result == "invalid operation":
  438. # 回调任务中心
  439. return_dict = {
  440. "data": "",
  441. "code": -2,
  442. "message": "fail, performActionResult is not success"
  443. }
  444. del_key_vague(device_id)
  445. call_back_task_reply(500, '任务执行失败,元素未找到', task_id, device_id, 0, None, None)
  446. return return_dict
  447. action13_id = int(round(time.time() * 1000))
  448. """
  449. 发送第13条指令
  450. 发送评论
  451. """
  452. action12_dict = single_click_by_control_exact(action13_id, target_app="cubic",
  453. target_version="11.59.5",
  454. package_name="com.cubic.autohome",
  455. control_id="com.cubic.autohome:id/input_btn_send", timeout=5)
  456. redis_client.set(device_id + "operate", action13_id)
  457. redis_client.set(f"{device_id}_step13", "1")
  458. redis_client.delete(f"{device_id}_step12")
  459. loggerKit.info("设备:{0}, action13_id:{1}", device_id, action12_dict)
  460. return action12_dict
  461. step13 = redis_client.get(f"{device_id}_step13")
  462. if step13 is not None and int(step13) == 1 and last_action_id is not None and int(perform_action_id) == int(
  463. last_action_id):
  464. loggerKit.info("设备:{0}, last_action_id:{1}", device_id, int(last_action_id))
  465. action6_id = int(round(time.time() * 1000))
  466. # 元素未找到
  467. if perform_action_result == "invalid operation":
  468. # 回调任务中心
  469. return_dict = {
  470. "data": "",
  471. "code": -2,
  472. "message": "fail, performActionResult is not success"
  473. }
  474. del_key_vague(device_id)
  475. call_back_task_reply(500, '任务执行失败,元素未找到', task_id, device_id, 0, None, None)
  476. return return_dict
  477. """
  478. 发送第14条指令
  479. 随机滑动
  480. """
  481. random_scale = random.randint(1, 3)
  482. action6_dict = swipe_screen(action6_id, scale=random_scale, timeout=30,
  483. target_app="cubic",
  484. target_version="11.59.5",
  485. package_name="com.cubic.autohome")
  486. redis_client.set(device_id + "operate", action6_id)
  487. redis_client.set(f"{device_id}_step14", "1")
  488. redis_client.delete(f"{device_id}_step13")
  489. return action6_dict
  490. step13 = redis_client.get(f"{device_id}_step14")
  491. if step13 is not None and int(step13) == 1 and last_action_id is not None and int(perform_action_id) == int(
  492. last_action_id):
  493. loggerKit.info("设备:{0}, last_action_id:{1}", device_id, int(last_action_id))
  494. action9_id = int(round(time.time() * 1000))
  495. # 元素未找到
  496. if perform_action_result == "invalid operation":
  497. # 回调任务中心
  498. return_dict = {
  499. "data": "",
  500. "code": -2,
  501. "message": "fail, performActionResult is not success"
  502. }
  503. del_key_vague(device_id)
  504. call_back_task_reply(500, '任务执行失败,元素未找到', task_id, device_id, 0, None, None)
  505. return return_dict
  506. """
  507. 发送第15条指令
  508. 关闭app
  509. """
  510. action9_dict = stop_app(action9_id, target_app="cubic",
  511. target_version="11.59.5",
  512. package_name="com.cubic.autohome")
  513. loggerKit.info("设备:{0}, action9_id:{1}", device_id, action9_dict)
  514. reply_json = redis_client.get(device_id + "reply_json")
  515. # 回调任务中心修改任务状态
  516. call_back_task_reply(None, None, task_id, device_id, 1, None, reply_json)
  517. del_key_vague(device_id)
  518. return action9_dict
  519. else:
  520. action0_id = int(round(time.time() * 1000))
  521. """
  522. 启动指令
  523. 启动app
  524. """
  525. action0_dict = start_app(action0_id, target_app="cubic",
  526. target_version="11.59.5",
  527. package_name="com.cubic.autohome")
  528. redis_client.set(device_id + "operate", action0_id)
  529. redis_client.set(f"{device_id}_step0", "1")
  530. loggerKit.info("设备:{0}, action0_id:{1}", device_id, action0_id)
  531. return action0_dict
  532. def call_back_task_reply(err_code, err_msg, task_id, device_id, execute_status, result, content):
  533. callback_request2 = call_back_request(err_code, err_msg, task_id, execute_status, result, content, None)
  534. loggerKit.info("thread[{0}=>{1}], taskId:{2}, 设备号:{3}, url:{4}, 执行状态:{5}, requestJson:{6} 。回调开始",
  535. threading.current_thread().name,
  536. threading.get_ident(), task_id, device_id, task_callback_url, execute_status, callback_request2)
  537. current_timeout = (5, 10)
  538. callback_response2 = requests.post(task_callback_url, json=callback_request2, timeout=current_timeout)
  539. loggerKit.info("thread[{0}=>{1}], taskId:{2},设备号:{3}。回调结束:{4}, 执行状态:{5}, result:{6}",
  540. threading.current_thread().name,
  541. threading.get_ident(), task_id, device_id, json.dumps(callback_response2.text, ensure_ascii=False),
  542. execute_status, result)
  543. return callback_response2
  544. """
  545. 添加了其他参数
  546. """
  547. # post请求
  548. def call_back_request(error_code, error_msg, task_id, task_status, task_execute_response, content, demo_flag):
  549. response = {
  550. "errorCode": error_code,
  551. "errorMsg": error_msg,
  552. "taskId": task_id,
  553. "taskStatus": task_status,
  554. "taskExecuteResponse": task_execute_response,
  555. "content": content,
  556. "demoFlag": demo_flag
  557. }
  558. return response
  559. # 回复详情
  560. class content_detail:
  561. def __init__(self, keyword, title, reply, account_name):
  562. """
  563. :rtype: object
  564. """
  565. # 搜索关键词
  566. self.keyword = keyword
  567. self.title = title
  568. self.reply = reply
  569. self.account_name = account_name
  570. def to_dict(self):
  571. return {
  572. 'keyword': self.keyword,
  573. 'title': self.title,
  574. 'reply': self.reply,
  575. 'accountName': self.account_name
  576. }