From a18bb38626c0c2a8de2d8495a6ee8166166fe52b Mon Sep 17 00:00:00 2001 From: y1ndan <53508617+y1ndan@users.noreply.github.com> Date: Wed, 18 Nov 2020 11:13:11 +0800 Subject: [PATCH] Fix known issue --- genshin.py | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/genshin.py b/genshin.py index fd3a4a9..3a04d46 100755 --- a/genshin.py +++ b/genshin.py @@ -4,8 +4,10 @@ import requests import json import uuid import logging -from time import sleep -from random import randint +import time +import random +import hashlib +import string from requests.exceptions import * logging.basicConfig( @@ -19,10 +21,14 @@ class ConfMeta(type): def index_url(self): return 'https://webstatic.mihoyo.com/bbs/event/signin-ys/index.html' + @property + def app_version(self): + return '2.1.0' + @property def ua(self): return 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_0_1 like Mac OS X) ' \ - 'AppleWebKit/605.1.15 (KHTML, like Gecko) miHoYoBBS/2.1.0' + 'AppleWebKit/605.1.15 (KHTML, like Gecko) miHoYoBBS/%s' %(self.app_version) class Conf(metaclass=ConfMeta): @@ -114,6 +120,19 @@ class Sign(object): self._cookie = cookie + # Provided by Steesha + def md5(self, text): + md5 = hashlib.md5() + md5.update(text.encode()) + return (md5.hexdigest()) + + def get_DS(self): + n = self.md5(Conf.app_version) + i = str(int(time.time())) + r = ''.join(random.sample(string.ascii_lowercase + string.digits, 6)) + c = self.md5("salt=" + n + "&t="+ i + "&r=" + r) + return i + "," + r + "," + c + def get_header(self): actid = 'e202009291139501' ref = "%s?bbs_auth_required=%s&act_id=%s&utm_source=%s" \ @@ -121,12 +140,15 @@ class Sign(object): Conf.index_url, 'true', actid, 'bbs', 'mys', 'icon') return { + 'x-rpc-device_id': str(uuid.uuid3( + uuid.NAMESPACE_URL, self._cookie)).replace('-','').upper(), + 'x-rpc-client_type': '5', + 'Accept-Encoding': 'gzip, deflate, br', 'User-Agent': Conf.ua, 'Referer': ref, - 'Accept-Encoding': 'gzip, deflate, br', - 'Cookie': self._cookie, - 'x-rpc-device_id': str(uuid.uuid3( - uuid.NAMESPACE_URL, self._cookie)).replace('-','').upper() + 'x-rpc-app_version': Conf.app_version, + 'DS': self.get_DS(), + 'Cookie': self._cookie } def run(self): @@ -159,10 +181,10 @@ def makeResult(result:str, data=None): if __name__ == "__main__": - seconds = randint(10, 300) + seconds = random.randint(10, 300) logging.info('Sleep for %s seconds ...' %(seconds)) - sleep(seconds) + time.sleep(seconds) try: jdict = Sign(input().strip()).run()