imoutaiAccountHelper.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. import hashlib
  2. import json
  3. import time
  4. import requests
  5. """
  6. 获取地点信息,这里用的高德 api,需要自己去高德开发者平台申请自己的 key
  7. """
  8. AMAP_KEY = "0b7675f60ca63b9d7071b0b96e0d0095"
  9. SALT = "2af72f100c356273d46284f6fd1dfc08"
  10. CURRENT_TIME = str(int(time.time() * 1000))
  11. headers = {}
  12. mt_version = json.loads(
  13. requests.get("https://itunes.apple.com/cn/lookup?id=1600482450").text
  14. )["results"][0]["version"]
  15. header_context = """
  16. MT-Lat: 28.499562
  17. MT-K: 1675213490331
  18. MT-Lng: 102.182324
  19. Host: app.moutai519.com.cn
  20. MT-User-Tag: 0
  21. Accept: */*
  22. MT-Network-Type: WIFI
  23. MT-Token: 1
  24. MT-Team-ID: 1
  25. MT-Info: 028e7f96f6369cafe1d105579c5b9377
  26. MT-Device-ID: 2F2075D0-B66C-4287-A903-DBFF6358342A
  27. MT-Bundle-ID: com.moutai.mall
  28. Accept-Language: en-CN;q=1, zh-Hans-CN;q=0.9
  29. MT-Request-ID: 167560018873318465
  30. MT-APP-Version: 1.3.7
  31. User-Agent: iOS;16.3;Apple;?unrecognized?
  32. MT-R: clips_OlU6TmFRag5rCXwbNAQ/Tz1SKlN8THcecBp/HGhHdw==
  33. Content-Length: 93
  34. Accept-Encoding: gzip, deflate, br
  35. Connection: keep-alive
  36. Content-Type: application/json
  37. userId: 2
  38. """
  39. # 初始化请求头
  40. def init_headers(
  41. user_id: str = "1", token: str = "2", lat: str = "29.83826", lng: str = "119.74375"
  42. ):
  43. for k in header_context.strip().split("\n"):
  44. temp_l = k.split(": ")
  45. dict.update(headers, {temp_l[0]: temp_l[1]})
  46. dict.update(headers, {"userId": user_id})
  47. dict.update(headers, {"MT-Token": token})
  48. dict.update(headers, {"MT-Lat": lat})
  49. dict.update(headers, {"MT-Lng": lng})
  50. dict.update(headers, {"MT-APP-Version": mt_version})
  51. # 用高德api获取地图信息
  52. def select_geo(i: str):
  53. # 校验高德api是否配置
  54. if AMAP_KEY is None:
  55. print("!!!!请配置 AMAP_KEY (高德地图的MapKey)")
  56. raise ValueError
  57. resp = requests.get(
  58. f"https://restapi.amap.com/v3/geocode/geo?key={AMAP_KEY}&output=json&address={i}"
  59. )
  60. geocodes: list = resp.json()["geocodes"]
  61. return geocodes
  62. def signature(data: dict):
  63. keys = sorted(data.keys())
  64. temp_v = ""
  65. for item in keys:
  66. temp_v += data[item]
  67. text = SALT + temp_v + CURRENT_TIME
  68. hl = hashlib.md5()
  69. hl.update(text.encode(encoding="utf8"))
  70. md5 = hl.hexdigest()
  71. return md5
  72. # 获取登录手机验证码
  73. def get_vcode(mobile: str):
  74. params = {"mobile": mobile}
  75. md5 = signature(params)
  76. dict.update(
  77. params, {"md5": md5, "timestamp": CURRENT_TIME, "MT-APP-Version": mt_version}
  78. )
  79. responses = requests.post(
  80. "https://app.moutai519.com.cn/xhr/front/user/register/vcode",
  81. json=params,
  82. headers=headers,
  83. )
  84. if responses.status_code != 200:
  85. print(
  86. f"get v_code : params : {params}, response code : {responses.status_code}, response body : {responses.text}"
  87. )
  88. # 执行登录操作
  89. def login(mobile: str, v_code: str):
  90. params = {"mobile": mobile, "vCode": v_code, "ydToken": "", "ydLogId": ""}
  91. md5 = signature(params)
  92. dict.update(
  93. params, {"md5": md5, "timestamp": CURRENT_TIME, "MT-APP-Version": mt_version}
  94. )
  95. responses = requests.post(
  96. "https://app.moutai519.com.cn/xhr/front/user/register/login",
  97. json=params,
  98. headers=headers,
  99. )
  100. if responses.status_code != 200:
  101. print(
  102. f"login : params : {params}, response code : {responses.status_code}, response body : {responses.text}"
  103. )
  104. dict.update(headers, {"MT-Token": responses.json()["data"]["token"]})
  105. dict.update(headers, {"userId": responses.json()["data"]["userId"]})
  106. return responses.json()["data"]["token"], responses.json()["data"]["userId"]
  107. def get_location():
  108. while 1:
  109. location = input(
  110. "请输入精确小区位置,例如[小区名称],为你自动预约附近的门店:"
  111. ).strip()
  112. selects = select_geo(location)
  113. a = 0
  114. for item in selects:
  115. formatted_address = item["formatted_address"]
  116. province = item["province"]
  117. print(f"{a} : [地区:{province},位置:{formatted_address}]")
  118. a += 1
  119. user_select = input("请选择位置序号,重新输入请输入[-]:").strip()
  120. if user_select == "-":
  121. continue
  122. select = selects[int(user_select)]
  123. formatted_address = select["formatted_address"]
  124. province = select["province"]
  125. print(f"已选择 地区:{province},[{formatted_address}]附近的门店")
  126. return select
  127. if __name__ == "__main__":
  128. items = []
  129. while 1:
  130. init_headers()
  131. location_select: dict = get_location()
  132. province = location_select["province"]
  133. city = location_select["city"]
  134. location: str = location_select["location"]
  135. mobile = input("输入手机号[18888888888]:").strip()
  136. get_vcode(mobile)
  137. code = input(f"输入 [{mobile}] 验证码[8888]:").strip()
  138. token, userId = login(mobile, code)
  139. item = {
  140. "city": str(city),
  141. "lat": location.split(",")[1],
  142. "lng": location.split(",")[0],
  143. "mobile": str(mobile),
  144. "province": province,
  145. "token": str(token),
  146. "userid": str(userId),
  147. "reserve_rule": 0,
  148. "item_codes": ["10941", "10942"],
  149. }
  150. items.append(item)
  151. condition = input("是否继续添加账号[y/n]:").strip()
  152. with open("account.json", "w") as f:
  153. f.write(json.dumps(items, ensure_ascii=False, indent=4))
  154. if condition.lower() == "n":
  155. break