# _*_ coding: utf-8 _*_ # author : "zhen_li" # mail : "zhen1_li@intsig.net" # date : 2022/10/13 14:57 # desc : "补环境的瑞数fastApi服务" import logging import uvicorn as uvicorn from pydantic import BaseModel from fastapi import FastAPI from py_mini_racer import MiniRacer import os,re app = FastAPI() class GeetestCaptcha: path = os.path.join(os.path.dirname(__file__), "1.js") with open(path, mode='r', encoding='utf-8') as f: code = f.read() path = os.path.join(os.path.dirname(__file__), "new_.js") with open(path, mode='r', encoding='utf-8') as f: code1 = f.read() @classmethod def get_cookie_202(cls,content,innerjs,win_ts): """ 获取202-200的cookie """ print("原始202") ctx = MiniRacer() ctx.eval(cls.code) cookie = re.findall('VyaT=(.*?); p', ctx.call("get_cookie",win_ts,innerjs,content))[0] data = {'cookie':cookie} return data @classmethod def up_cookie(cls,content,innerjs,win_ts,cookie): """ #刷新cookie,用的get_cookie_200所保存的self.ctx2 """ ctx2 = MiniRacer() ctx2.eval(cls.code1) cookie = re.findall('VyaT=(.*?); p', ctx2.call("Search_First_DetialPage",win_ts,innerjs,content,cookie))[0] data = {'cookie':cookie} return data class GeetestParamsModel_202(BaseModel): content:str innerjs:str win_ts:str class UpdateCookie(BaseModel): content:str innerjs:str win_ts:str cookie: str @app.post("/rs_update_cookie") def geetest_cookie(params: UpdateCookie): result = GeetestCaptcha.up_cookie(params.content,params.innerjs,params.win_ts,params.cookie) return result @app.post("/rs_202") def geetest_202(params: GeetestParamsModel_202): result = GeetestCaptcha.get_cookie_202(params.content,params.innerjs,params.win_ts) return result if __name__ == '__main__': uvicorn.run("run:app", reload=True, host="127.0.0.1", port=8006)