Skip to content

Instantly share code, notes, and snippets.

@sumimakito
Last active October 14, 2019 08:15
Show Gist options
  • Save sumimakito/47b6ddd83695039f2e18feb2e7b40b37 to your computer and use it in GitHub Desktop.
Save sumimakito/47b6ddd83695039f2e18feb2e7b40b37 to your computer and use it in GitHub Desktop.
Run with Python 3
#!/usr/bin/env python
import hashlib
import json
from getpass import getpass
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
mi_username = input('Mi Username: ')
mi_password = getpass('Mi Password: ')
mi_password = hashlib.md5(mi_password.encode()).hexdigest().upper()
http = urllib3.PoolManager()
data = {
'user': mi_username,
'hash': mi_password,
'_json': 'true',
'sid': 'xiaomiio',
'callback': 'https://sts.api.io.mi.com/sts',
'qs': '%3Fsid%3Dxiaomiio%26_json%3Dtrue',
'_sign': '0psXfr43eNI0IX6q9Suk3qWbRqU='
}
headers = {
'Host': "account.xiaomi.com",
'Accept': "*/*",
'Cookie': "deviceId=5CF146345B326306; sdkVersion=3.4.1",
'User-Agent': "APP/com.xiaomi.mihome APPV/4.21.3 iosPassportSDK/3.4.1 iOS/13.0 miHSTS",
'Accept-Language': "zh-tw",
}
print('Logging in...')
r = http.request(
'POST', 'https://account.xiaomi.com/pass/serviceLoginAuth2',
data,
headers
)
data = json.loads(r.data[11:])
for key in ['ssecurity', 'userId']:
print(f'{key}: {data[key]}')
print('Fetching cookie...')
r = http.request('GET', data['location'])
for item in r.headers['Set-Cookie'].split(', '):
item = item.split('; ')[0]
parts = item.split('=', maxsplit=1)
if parts[0] == 'serviceToken':
serviceToken = parts[1]
print(f'serviceToken: {serviceToken}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment