main.py 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. import base64
  2. import datetime
  3. import json
  4. import logging
  5. import os.path
  6. import time
  7. import requests
  8. import ddddocr
  9. # 配置日志
  10. logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
  11. # 配置文件路径
  12. CONFIG_FILE = "config.json"
  13. # 初始化配置
  14. def init_config():
  15. if not os.path.exists(CONFIG_FILE):
  16. with open(CONFIG_FILE, "w", encoding="utf-8") as f:
  17. json.dump({}, f)
  18. # 读取配置
  19. def load_config():
  20. with open(CONFIG_FILE, "r", encoding="utf-8") as f:
  21. return json.load(f)
  22. # 保存配置
  23. def save_config(config):
  24. with open(CONFIG_FILE, "w", encoding="utf-8") as f:
  25. json.dump(config, f, indent=4)
  26. # 获取版本号
  27. def get_version(config):
  28. if "version" not in config:
  29. # 这里可以添加获取版本号的逻辑
  30. config["version"] = "1.1.3"
  31. save_config(config)
  32. return config["version"]
  33. # 获取App ID
  34. def get_app_id(config):
  35. if "appid" not in config:
  36. response = requests.get(
  37. f"https://www.aeropres.in/chromeapi/dawn/v1/appid/getappid?app_v={get_version(config)}",
  38. proxies=config.get("proxy"),
  39. headers={
  40. "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"},
  41. verify=False,
  42. timeout=15
  43. )
  44. if response.status_code != 200:
  45. raise Exception("获取appid失败")
  46. config["appid"] = response.json()["data"]["appid"]
  47. save_config(config)
  48. return config["appid"]
  49. # 获取Puzzle ID
  50. def get_puzzle_id(config):
  51. app_id = get_app_id(config)
  52. headers = {
  53. "Accept": "*/*",
  54. "Accept-Encoding": "gzip, deflate, br, zstd",
  55. "Accept-Language": "zh-CN,zh;q=0.9",
  56. "Origin": "chrome-extension://fpdkjdnhkakefebpekbdhillbhonfjjp",
  57. "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36",
  58. "priority": "u=1, i",
  59. "sec-ch-ua": '"Not(A:Brand";v="99", "Google Chrome";v="133", "Chromium";v="133"',
  60. "sec-ch-ua-mobile": "?0",
  61. "sec-ch-ua-platform": '"Windows"',
  62. "sec-fetch-dest": "empty",
  63. "sec-fetch-mode": "cors",
  64. "sec-fetch-site": "cross-site",
  65. }
  66. response = requests.get(
  67. f"https://www.aeropres.in/chromeapi/dawn/v1/puzzle/get-puzzle?appid={app_id}",
  68. proxies=config.get("proxy"),
  69. headers=headers,
  70. verify=False,
  71. timeout=15
  72. )
  73. if response.status_code not in [200, 201]:
  74. raise Exception("获取puzzle_id失败")
  75. res_json = response.json()
  76. if not res_json.get('success', False):
  77. raise Exception("获取puzzle_id结果失败")
  78. return res_json["puzzle_id"]
  79. # 获取Puzzle Code
  80. def get_puzzle_code(config):
  81. puzzle_id = get_puzzle_id(config)
  82. headers = {
  83. "Accept": "*/*",
  84. "Accept-Encoding": "gzip, deflate, br, zstd",
  85. "Accept-Language": "zh-CN,zh;q=0.9",
  86. "Origin": "chrome-extension://fpdkjdnhkakefebpekbdhillbhonfjjp",
  87. "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36",
  88. "priority": "u=1, i",
  89. "sec-ch-ua": '"Not(A:Brand";v="99", "Google Chrome";v="133", "Chromium";v="133"',
  90. "sec-ch-ua-mobile": "?0",
  91. "sec-ch-ua-platform": '"Windows"',
  92. "sec-fetch-dest": "empty",
  93. "sec-fetch-mode": "cors",
  94. "sec-fetch-site": "cross-site",
  95. }
  96. response = requests.get(
  97. f"https://www.aeropres.in/chromeapi/dawn/v1/puzzle/get-puzzle-image?puzzle_id={puzzle_id}&appid={get_app_id(config)}",
  98. proxies=config.get("proxy"),
  99. headers=headers,
  100. verify=False,
  101. timeout=15
  102. )
  103. if response.status_code != 200:
  104. raise Exception("获取puzzle_url失败")
  105. res_json = response.json()
  106. if not res_json.get('success', False):
  107. raise Exception("获取puzzle_url结果失败")
  108. imgBase64 = res_json["imgBase64"]
  109. data = base64.b64decode(imgBase64)
  110. return get_code_with_img(puzzle_id, img_data=data)
  111. # 获取验证码
  112. def get_code_with_img(puzzle_id, img_data):
  113. print(puzzle_id)
  114. with open(f'{str(int(time.time()))}.jpg', 'wb') as file:
  115. file.write(img_data)
  116. return False
  117. # 获取Token
  118. def get_token(config):
  119. if "token" not in config:
  120. retry_count = config.get('retry', 3)
  121. code = ""
  122. puzzle_id = ""
  123. while retry_count > 0:
  124. try:
  125. puzzle_id = get_puzzle_id(config)
  126. code = get_puzzle_code(config)
  127. break
  128. except Exception as e:
  129. logging.error(f"获取token失败,{e}")
  130. retry_count -= 1
  131. if not code or not puzzle_id:
  132. return False
  133. data = {
  134. "username": config.get("username", ""),
  135. "password": config.get("password", ""),
  136. "logindata": {"_v": {"version": get_version(config)},
  137. "datetime": datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S.%fZ")[:-3]},
  138. "puzzle_id": puzzle_id,
  139. "ans": code,
  140. "appid": get_app_id(config),
  141. }
  142. headers = {
  143. "Accept": "*/*",
  144. "Accept-Encoding": "gzip, deflate, br, zstd",
  145. "Accept-Language": "zh-CN,zh;q=0.9",
  146. "Origin": "chrome-extension://fpdkjdnhkakefebpekbdhillbhonfjjp",
  147. "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36",
  148. "priority": "u=1, i",
  149. "sec-ch-ua": '"Not(A:Brand";v="99", "Google Chrome";v="133", "Chromium";v="133"',
  150. "sec-ch-ua-mobile": "?0",
  151. "sec-ch-ua-platform": '"Windows"',
  152. "sec-fetch-dest": "empty",
  153. "sec-fetch-mode": "cors",
  154. "sec-fetch-site": "cross-site",
  155. }
  156. retry_count = config.get('retry', 3)
  157. while retry_count > 0:
  158. try:
  159. response = requests.post(
  160. f"https://www.aeropres.in/chromeapi/dawn/v1/user/login/v2?appid={get_app_id(config)}",
  161. json=data,
  162. proxies=config.get("proxy"),
  163. verify=False,
  164. timeout=15,
  165. headers=headers
  166. )
  167. if response.status_code != 200:
  168. raise Exception("获取token失败")
  169. res_json = response.json()
  170. if not res_json.get('success', False):
  171. raise Exception("获取token结果失败")
  172. config["token"] = res_json["data"]["token"]
  173. save_config(config)
  174. break
  175. except Exception as e:
  176. logging.error(f"获取token失败,{e}")
  177. retry_count -= 1
  178. return config.get("token", "")
  179. # 获取积分
  180. def get_point(config):
  181. headers = {
  182. "Authorization": f"Bearer {config.get('token', '')}",
  183. "Content-Type": "application/json",
  184. "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36",
  185. "sec-ch-ua": '"Not(A:Brand";v="99", "Google Chrome";v="133", "Chromium";v="133"',
  186. "sec-ch-ua-mobile": "?0",
  187. "sec-ch-ua-platform": '"Windows"',
  188. }
  189. response = requests.get(
  190. f"https://www.aeropres.in/api/atom/v1/userreferral/getpoint?appid={get_app_id(config)}",
  191. headers=headers,
  192. proxies=config.get("proxy"),
  193. verify=False,
  194. timeout=15
  195. )
  196. if response.status_code != 200:
  197. raise Exception(f"获取积分失败,{response.text}")
  198. if not response.json().get('success', False):
  199. raise Exception(f"获取积分失败,{response.json()}")
  200. # 保持活跃
  201. def keep_alive(config):
  202. headers = {
  203. "Authorization": f"Bearer {config.get('token', '')}",
  204. "Content-Type": "application/json",
  205. "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36",
  206. }
  207. data = {
  208. "username": config.get("username", ""),
  209. "extensionid": "fpdkjdnhkakefebpekbdhillbhonfjjp",
  210. "numberoftabs": 0,
  211. "_v": get_version(config)
  212. }
  213. response = requests.post(
  214. f"https://www.aeropres.in/chromeapi/dawn/v1/userreward/keepalive?appid={get_app_id(config)}",
  215. json=data,
  216. headers=headers,
  217. proxies=config.get("proxy"),
  218. verify=False,
  219. timeout=15
  220. )
  221. if response.status_code != 200:
  222. raise Exception(f"保持活跃失败,{response.text}")
  223. if not response.json().get('success', False):
  224. raise Exception(f"保持活跃失败,{response.json()}")
  225. # 主函数
  226. def main():
  227. init_config()
  228. config = load_config()
  229. while True:
  230. token = get_token(config)
  231. if not token:
  232. time.sleep(60)
  233. del config['token']
  234. save_config(config)
  235. continue
  236. retry_count = 5
  237. while retry_count > 0:
  238. err = False
  239. try:
  240. get_point(config)
  241. except Exception as e:
  242. logging.error(f"获取积分失败,{e}")
  243. err = True
  244. try:
  245. keep_alive(config)
  246. except Exception as e:
  247. logging.error(f"保持活跃失败,{e}")
  248. err = True
  249. if not err:
  250. retry_count = 5
  251. else:
  252. retry_count -= 1
  253. if retry_count <= 0:
  254. break
  255. time.sleep(5 * 60)
  256. if __name__ == '__main__':
  257. main()