算法暴露接口(xhs、dy、ks、wx、hnw)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

266 lines
7.7 KiB

7 months ago
  1. import time
  2. import json
  3. from dianping.mtgsig import mtgsig_run
  4. from douyin.dy_abogus import run
  5. from hnw.hnw_hook import build_headers
  6. from flask import Flask, request
  7. import traceback
  8. from utils.Logger import MyLogger
  9. from wx.video.video_decode import main
  10. from xhs.shield import shield_run
  11. from xhs.shield_aes import get_key
  12. from xhs.xhs_captcha import SignalCaptcha
  13. from xhs.xhs_param import get_xs, get_a1, get_comment
  14. app = Flask(__name__)
  15. log = MyLogger()
  16. """
  17. nohup /root/anaconda3/envs/py3.8/bin/python server.py > /dev/null 2>&1 &
  18. uwsgi -d --ini uwsgi.ini
  19. uwsgi --stop
  20. uwsgi --reload
  21. """
  22. @app.route("/getData", methods=['GET'])
  23. def get_review_list():
  24. # shop_id = request.query.shopId
  25. # page_num = request.query.pageNum
  26. # page_num = int(page_num) * 14
  27. # review_list = main(shop_id, str(page_num))
  28. # ret = {"desc": "success", "result": review_list}
  29. ret = ""
  30. return json.dumps(ret, ensure_ascii=False)
  31. @app.route("/hnw/get_header", methods=['GET'])
  32. def get_hnw_headers():
  33. ret = {"code": 200, "data": {}}
  34. try:
  35. headers = build_headers()
  36. ret["data"] = headers
  37. except Exception as e:
  38. ret["code"] = 500
  39. ret["data"] = f"{e}"
  40. log.info(f"[hnw]: {ret}")
  41. return json.dumps(ret, ensure_ascii=False)
  42. @app.route("/xhs/get_header", methods=['POST'])
  43. def get_xhs_headers():
  44. """
  45. x-s参数接口
  46. /a1/timeStamp
  47. cookie信息如果不传则本地生成一个
  48. :return:
  49. """
  50. ret = {"code": 200, "data": {}}
  51. try:
  52. api_type = request.args.get("api")
  53. a1 = request.args.get("a1") if request.args.get("a1") else get_a1("Mac OS")[0]
  54. times = request.args.get("timStamp") if request.args.get("timStamp") else str(int(time.time() * 1000))
  55. data = request.get_data()
  56. params = json.dumps(json.loads(data), ensure_ascii=False, separators=(',', ':'))
  57. res = get_xs(a1, api_type, params, times)
  58. ret["data"] = res
  59. except Exception as e:
  60. log.error(e)
  61. ret = {"code": 500, "data": str(e)}
  62. log.info(f"[xhs]: {ret}")
  63. return json.dumps(ret, ensure_ascii=False)
  64. @app.route("/xhs/get_header_all", methods=['POST'])
  65. def get_xhs_headers_all():
  66. """
  67. x-sx-comment参数接口
  68. /a1/timeStamp
  69. :return:
  70. """
  71. ret = {"code": 200, "data": {}}
  72. try:
  73. api_type = request.args.get("api")
  74. a1 = request.args.get("a1")
  75. times = str(int(time.time() * 1000))
  76. data = request.get_data()
  77. params = json.dumps(json.loads(data), ensure_ascii=False, separators=(',', ':'))
  78. res = get_xs(a1, api_type, params, times)
  79. res["x-s-common"] = get_comment(a1, res['x-s'], res['x-t'])
  80. ret["data"] = res
  81. except Exception as e:
  82. log.error(e)
  83. ret = {"code": 500, "data": str(e)}
  84. log.info(f"[xhs]: {ret}")
  85. return json.dumps(ret, ensure_ascii=False)
  86. @app.route("/xhs/pass_captcha", methods=['POST'])
  87. def verify_captcha():
  88. """
  89. xhs验证码
  90. 461
  91. :return:
  92. """
  93. ret = {"code": 200, "data": {}}
  94. try:
  95. data = request.get_data()
  96. data = json.loads(data)
  97. log.info(data)
  98. web_session = data["web_session"]
  99. verify_uuid = data["verify_uuid"]
  100. source = data["source"]
  101. a1 = data["a1"]
  102. webId = data["webId"]
  103. is_proxy = data.get("is_proxy") if data.get("is_proxy") else False
  104. A = SignalCaptcha(web_session, verify_uuid, a1, webId, source=source, is_proxy=is_proxy)
  105. res = A.run()
  106. ret["data"] = res
  107. except Exception as e:
  108. log.error(e)
  109. ret = {"code": 500, "data": str(e)}
  110. log.info(f"[xhs]: {ret}")
  111. return json.dumps(ret, ensure_ascii=False)
  112. @app.route("/xhs/get_cookie", methods=['GET'])
  113. def get_xhs_cookies():
  114. """
  115. platform cookie
  116. Android/iOS/Mac OS/Linux/Windows
  117. :return:
  118. """
  119. ret = {"code": 200, "data": {}}
  120. try:
  121. platform = request.args.get("platform") if request.args.get("platform") else "Mac OS"
  122. a1, web_id = get_a1(platform)
  123. ret["data"] = {
  124. "a1": a1,
  125. "webId": web_id
  126. }
  127. except Exception as e:
  128. ret["code"] = 500
  129. ret["data"] = f"{e}"
  130. log.info(f"[xhs]: {ret}")
  131. return json.dumps(ret, ensure_ascii=False)
  132. @app.route("/wx/decode", methods=["POST"])
  133. async def get_upload_path():
  134. """
  135. :return:
  136. """
  137. if 'file' not in request.files:
  138. return json.dumps({"code": 500, "msg": "视频流文件不存在"}, ensure_ascii=False)
  139. file = request.files["file"]
  140. decode = request.args.get("decodekey")
  141. log.info(f"[wx]: 获取的decode {decode}")
  142. upload_path = await main(file, decode)
  143. log.info(f"[wx]: {upload_path}")
  144. return json.dumps(upload_path, ensure_ascii=False)
  145. @app.route("/wx/decode", methods=["GET"])
  146. async def get_upload_path1():
  147. """
  148. :return:
  149. """
  150. decode = request.args.get("decodekey")
  151. localpath = request.args.get("localpath")
  152. try:
  153. files = {'file': open(localpath, 'rb')}
  154. except Exception as e:
  155. log.error(f"[wx] error {e}")
  156. return json.dumps({"code":500, "msg": "视频读取失败"}, ensure_ascii=False)
  157. log.info(f"[wx]: 获取的decode {decode}")
  158. upload_path = await main(files["file"], decode)
  159. log.info(f"[wx]: {upload_path}")
  160. return json.dumps(upload_path, ensure_ascii=False)
  161. @app.route("/dy/get_abogus", methods=["POST"])
  162. async def get_abogus():
  163. """
  164. :return:
  165. """
  166. try:
  167. data = json.loads(request.get_data())
  168. ua = data.get("ua")
  169. param = data.get("param")
  170. a_bogus = run(param, ua)
  171. res = {"code": 200, "data": a_bogus}
  172. log.info(f"[dy]: {len(a_bogus)} => {res}")
  173. return json.dumps(res, ensure_ascii=False)
  174. except Exception as e:
  175. log.error(f"[dy] error {e}")
  176. return json.dumps({"code":500, "msg": "算法生成失败"}, ensure_ascii=False)
  177. @app.route("/dp/get_mtgsig", methods=["POST"])
  178. async def get_mtgsig():
  179. """
  180. mtgsig1.2
  181. :return:
  182. """
  183. try:
  184. data = json.loads(request.get_data())
  185. url = data.get("url")
  186. a3 = data.get("a3")
  187. b8 = data.get("b8") # 循环的次数
  188. a6 = data.get("a6")
  189. if not b8 or not a6 or not a3:
  190. raise Exception("check b8/a6/a3 params!!!")
  191. mtgsig = mtgsig_run(url, b8, a3, a6)
  192. res = {"code": 200, "data": mtgsig}
  193. log.info(f"[mtgsig]: => {res}")
  194. return json.dumps(res, ensure_ascii=False)
  195. except Exception as e:
  196. log.error(f"[mtgsig] error {e}")
  197. return json.dumps({"code":500, "msg": "算法生成失败"}, ensure_ascii=False)
  198. @app.route("/xhs/get_shield", methods=['POST'])
  199. async def get_app_xhs_headers():
  200. """
  201. app端
  202. shield本地生成
  203. :return:
  204. """
  205. ret = {"code": 200, "data": {}}
  206. try:
  207. data = request.get_data()
  208. data_json = json.loads(data)
  209. hmac_main = data_json["hmac_main"]
  210. url = data_json["url"]
  211. xy_common_params = data_json["xy_common_params"]
  212. deviceId = data_json["deviceId"]
  213. api = data_json["api"] # /api/sns/v1/note/feed 默认
  214. keys = get_key(deviceId, hmac_main) # 获得keys
  215. res = shield_run(url, keys, xy_common_params, deviceId, api) # 加密流程
  216. ret["data"] = res
  217. except Exception as e:
  218. log.error(e)
  219. traceback.print_exc()
  220. ret = {"code": 500, "data": str(e)}
  221. log.info(f"[xhs]: {ret}")
  222. return json.dumps(ret, ensure_ascii=False)
  223. if __name__ == '__main__':
  224. app.run(host='0.0.0.0', port=8088)