run.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # _*_ coding: utf-8 _*_
  2. # author : "zhen_li"
  3. # mail : "zhen1_li@intsig.net"
  4. # date : 2022/10/13 14:57
  5. # desc : "补环境的瑞数fastApi服务"
  6. import logging
  7. import uvicorn as uvicorn
  8. from pydantic import BaseModel
  9. from fastapi import FastAPI
  10. from py_mini_racer import MiniRacer
  11. import os,re
  12. app = FastAPI()
  13. class GeetestCaptcha:
  14. path = os.path.join(os.path.dirname(__file__), "1.js")
  15. with open(path, mode='r', encoding='utf-8') as f:
  16. code = f.read()
  17. path = os.path.join(os.path.dirname(__file__), "new_.js")
  18. with open(path, mode='r', encoding='utf-8') as f:
  19. code1 = f.read()
  20. @classmethod
  21. def get_cookie_202(cls,content,innerjs,win_ts):
  22. """
  23. 获取202-200的cookie
  24. """
  25. print("原始202")
  26. ctx = MiniRacer()
  27. ctx.eval(cls.code)
  28. cookie = re.findall('VyaT=(.*?); p', ctx.call("get_cookie",win_ts,innerjs,content))[0]
  29. data = {'cookie':cookie}
  30. return data
  31. @classmethod
  32. def up_cookie(cls,content,innerjs,win_ts,cookie):
  33. """
  34. #刷新cookie,用的get_cookie_200所保存的self.ctx2
  35. """
  36. ctx2 = MiniRacer()
  37. ctx2.eval(cls.code1)
  38. cookie = re.findall('VyaT=(.*?); p', ctx2.call("Search_First_DetialPage",win_ts,innerjs,content,cookie))[0]
  39. data = {'cookie':cookie}
  40. return data
  41. class GeetestParamsModel_202(BaseModel):
  42. content:str
  43. innerjs:str
  44. win_ts:str
  45. class UpdateCookie(BaseModel):
  46. content:str
  47. innerjs:str
  48. win_ts:str
  49. cookie: str
  50. @app.post("/rs_update_cookie")
  51. def geetest_cookie(params: UpdateCookie):
  52. result = GeetestCaptcha.up_cookie(params.content,params.innerjs,params.win_ts,params.cookie)
  53. return result
  54. @app.post("/rs_202")
  55. def geetest_202(params: GeetestParamsModel_202):
  56. result = GeetestCaptcha.get_cookie_202(params.content,params.innerjs,params.win_ts)
  57. return result
  58. if __name__ == '__main__':
  59. uvicorn.run("run:app", reload=True, host="127.0.0.1", port=8006)