main.py 9.8 KB

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