Merge pull request #21 from Arondight/master

Update README.md; Change error code to -1 (as we usually do in Unix programs)
This commit is contained in:
y1ndan 2020-11-19 09:56:46 +08:00 committed by GitHub
commit b37ef3040a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 65 additions and 36 deletions

View File

@ -76,33 +76,60 @@ JSON.stringify({
## 🔍结果
当你完成上述流程,可以在`Actions`页面点击`Genshin Impact Helper`-->`build`-->`run sign`查看结果。
当你完成上述流程,可以在`Actions`页面点击`Genshin Impact Helper`-->`build`-->`Run sign`查看结果。
### 签到成功
如果成功,会输出类似`"result": "Success"`的信息:
```
2020-10-30T11:30:08 INFO sleep for 214 seconds ...
2020-10-30T11:30:08 INFO UID is 100***001
2020-10-30T11:30:09 INFO {
2020-11-18T22:11:45 INFO Sleep for 100 seconds ...
2020-11-18T22:13:26 INFO UID is 102***054
2020-11-18T22:13:27 INFO {
"result": "Success",
"message": "{'data': None, 'message': '旅行者,你已经签到过了', 'retcode': -5003}"
"message": "{\"retcode\": 0, \"message\": \"OK\", \"data\": {\"code\": \"ok\"}}"
}
```
### 签到失败
如果失败,会输出类似`"result": "Failed"`的信息:
```
2020-10-30T11:14:26 INFO sleep for 207 seconds ...
2020-10-30T11:14:26 ERROR get uid failed, request is "{'data': None, 'message': '登录失效,请重新登录', 'retcode': -100}"
2020-10-30T11:14:26 INFO {
2020-11-17T22:11:33 INFO Sleep for 54 seconds ...
2020-11-17T22:12:28 INFO UID is 102***054
2020-11-17T22:12:29 INFO {
"result": "Failed",
"message": ""{'data': None, 'message': '登录失效,请重新登录', 'retcode': -100}""
"message": "{\"data\": null, \"message\": \"请求异常\", \"retcode\": -401}"
}
Error: Process completed with exit code 255.
```
同时你会收到一封来自GitHub、标题为`Run failed: Genshin Impact Helper - master`的邮件。
## 更新
因为请求上可能发生一些变化,所以上游源代码需要作出更改来适配这些变化,如果你没有更新项目源代码,会导致签到失败。更新的步骤如下。
```
git clone https://github.com/<Your GitHub ID>/genshin-impact-helper.git
cd ./genshin-impact-helper
git pull https://github.com/y1ndan/genshin-impact-helper.git master
git push origin master
```
以上步骤可以在任意[Linux](https://zh.wikipedia.org/wiki/Linux)中执行,或者在[Windows](https://zh.wikipedia.org/wiki/Microsoft_Windows)中通过安装[Git](https://zh.wikipedia.org/wiki/Git),之后在`Git Bash`软件中完成。
> 1. Git可以在[此处](https://git-scm.com/downloads)下载,更多信息可以查阅[此处](https://git-scm.com/book/)。
> 2. 更新完毕后不需要重新部署Actions。
## 说明
此代码通过模拟浏览器使用Cookies登录米游社网页点击页面完成签到来实现功能。签到功能通过官方公开的API实现非游戏外挂。
## ❗️注意
1. 程序会在每天早上自动执行签到流程,也可以随时通过上述`步骤4`手动触发
1. 程序会在每天早上自动执行签到流程,也可以随时通过上述`步骤4`手动触发,具体时间参照[此处](.github/workflows/main.yml)
2. 登录失效时,尝试重新更换`Cookie`
3. 支持多账号,不同`Cookie`之间用`#`分开即可
4. 支持官服和 B 服

View File

@ -39,7 +39,7 @@ class Roles(object):
def __init__(self, cookie:str=None):
if type(cookie) is not str:
raise TypeError("%s want a %s but got %s" %(
self.__class__, type(__name__), type(cookie)))
self.__class__, type(__name__), type(cookie)))
self._cookie = cookie
self._url = "https://api-takumi.mihoyo.com/binding/api/" \
@ -52,17 +52,17 @@ class Roles(object):
Conf.index_url, 'true', actid, 'bbs', 'mys', 'icon')
return {
'User-Agent': Conf.ua,
'Referer': ref,
'Accept-Encoding': 'gzip, deflate, br',
'Cookie': self._cookie
'User-Agent': Conf.ua,
'Referer': ref,
'Accept-Encoding': 'gzip, deflate, br',
'Cookie': self._cookie
}
def get_roles(self):
try:
jdict = json.loads(
requests.Session().get(
self._url, headers = self.get_header()).text)
self._url, headers = self.get_header()).text)
except Exception as e:
logging.error(e)
raise HTTPError
@ -74,7 +74,7 @@ class Sign(object):
def __init__(self, cookie:str=None):
if type(cookie) is not str:
raise TypeError("%s want a %s but got %s" %(
self.__class__, type(__name__), type(cookie)))
self.__class__, type(__name__), type(cookie)))
self._url = 'https://api-takumi.mihoyo.com/event/bbs_sign_reward/sign'
@ -140,30 +140,30 @@ 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,
'x-rpc-app_version': Conf.app_version,
'DS': self.get_DS(),
'Cookie': self._cookie
'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,
'x-rpc-app_version': Conf.app_version,
'DS': self.get_DS(),
'Cookie': self._cookie
}
def run(self):
logging.info('UID is %s' %(str(self._uid).replace(str(self._uid)[3:6],'***',1)))
data = {
'act_id': 'e202009291139501',
'region': self._region,
'uid': self._uid
'act_id': 'e202009291139501',
'region': self._region,
'uid': self._uid
}
try:
jdict = json.loads(requests.Session().post(
self._url, headers = self.get_header(),
data = json.dumps(data, ensure_ascii=False)).text)
self._url, headers = self.get_header(),
data = json.dumps(data, ensure_ascii=False)).text)
except Exception as e:
raise
@ -182,8 +182,9 @@ def makeResult(result:str, data=None):
if __name__ == "__main__":
seconds = random.randint(10, 300)
logging.info('Sleep for %s seconds ...' %(seconds))
ret = -1
logging.info('Sleep for %s seconds ...' %(seconds))
time.sleep(seconds)
try:
@ -204,7 +205,8 @@ if __name__ == "__main__":
# -5003: already signed in
if code in [0, -5003]:
result = makeResult('Success', jstr)
logging.info(result)
else:
logging.info(result)
exit(-100)
ret = 0
logging.info(result)
exit(ret)