Compare commits

..

7 Commits

10 changed files with 170 additions and 57 deletions

8
.idea/.gitignore vendored
View File

@ -1,8 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/../../../../../:\Dev\PycharmProjects\Yuanshen\.idea/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/

View File

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -1,6 +0,0 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

View File

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (Yuanshen)" project-jdk-type="Python SDK" />
</project>

View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/Yuanshen.iml" filepath="$PROJECT_DIR$/.idea/Yuanshen.iml" />
</modules>
</component>
</project>

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -1,12 +1,16 @@
'''
"""
cron: 10 12 * * * *
new Env('米游社原神签到');
@File : genshin.py
@Github : https://github.com/y1ndan/genshin-impact-helper
@Last modified by : y1ndan
@Last modified time : 2021-01-13 11:10:30
'''
"""
import hashlib
import json
import random
import re
import string
import time
import uuid
@ -17,6 +21,7 @@ from requests.exceptions import HTTPError
from settings import log, CONFIG
from notify import Notify
from ql_api import get_envs, disable_env, post_envs, put_envs
def hexdigest(text):
@ -79,7 +84,7 @@ class Roles(Base):
continue
except KeyError as error:
log.error(
'Wrong response to get game roles, retry %s time(s)...'% i)
'Wrong response to get game roles, retry %s time(s)...' % i)
log.error('response is %s' % error)
continue
except Exception as error:
@ -93,7 +98,7 @@ class Roles(Base):
'Maximum retry times have been reached, error is %s ' % error)
raise Exception(error)
if response.get(
'retcode', 1) != 0 or response.get('data', None) is None:
'retcode', 1) != 0 or response.get('data', None) is None:
raise Exception(response['message'])
log.info('账号信息获取完毕')
@ -119,7 +124,7 @@ class Sign(Base):
def get_header(self):
header = super(Sign, self).get_header()
header.update({
'x-rpc-device_id':str(uuid.uuid3(
'x-rpc-device_id': str(uuid.uuid3(
uuid.NAMESPACE_URL, self._cookie)).replace('-', '').upper(),
# 1: ios
# 2: android
@ -145,7 +150,7 @@ class Sign(Base):
# cn_qd01: 世界树
self._region_list = [(i.get('region', 'NA')) for i in role_list]
self._region_name_list = [(i.get('region_name', 'NA'))
for i in role_list]
for i in role_list]
self._uid_list = [(i.get('game_uid', 'NA')) for i in role_list]
log.info('准备获取签到信息...')
@ -228,7 +233,21 @@ class Sign(Base):
return CONFIG.MESSGAE_TEMPLATE
def main_handler(event, context):
# 获取要执行兑换的cookie
def get_cookie():
ck_list = []
cookie = None
cookies = get_envs("MIHOYO_COOKIE")
for ck in cookies:
if ck.get('status') == 0:
ck_list.append(ck.get("value"))
if len(ck_list) == 0:
print('共配置{}条CK,请添加环境变量,或查看环境变量状态'.format(len(ck_list)))
return ck_list
if __name__ == '__main__':
# def main_handler(event, context):
log.info('任务开始')
notify = Notify()
msg_list = []
@ -237,7 +256,7 @@ def main_handler(event, context):
# 此处填米游社的COOKIE
# 注: Github Actions用户请到Settings->Secrets里设置,Name=COOKIE,Value=<获取的值>
# 多个账号的COOKIE值之间用 # 号隔开,例如: 1#2#3#4
COOKIE = ''
COOKIE = "#".join(get_cookie())
if os.environ.get('COOKIE', '') != '':
COOKIE = os.environ['COOKIE']
@ -261,4 +280,4 @@ def main_handler(event, context):
if ret != 0:
log.error('异常退出')
exit(ret)
log.info('任务结束')
log.info('任务结束')

View File

@ -4,16 +4,16 @@
@Last modified by : y1ndan
@Last modified time : 2021-01-13 11:01:10
'''
import base64
import hashlib
import hmac
import json
import os
import time
import hmac
import hashlib
import base64
from urllib import parse
import requests
from requests.exceptions import HTTPError
from urllib import parse
from settings import log
@ -121,6 +121,20 @@ class Notify(object):
# 注: Github Actions用户请到Settings->Secrets里设置,Name=PUSH_PLUS_USER,Value=<获取的值>
PUSH_PLUS_USER = ''
# ============================== go-cqhttp ====================================
# 官方文档https://docs.go-cqhttp.org/guide/quick_start.html#使用
# GO_CQHTTP_URL 服务器地址
# GO_CQHTTP_TOKEN 你的token
# GO_CQHTTP_GROUP 参数
# GO_CQHTTP_API 接口名
GO_CQHTTP_URL = ''
GO_CQHTTP_TOKEN = ''
GO_CQHTTP_GROUP_NO = ''
GO_CQHTTP_API = ''
if os.environ.get('PUSH_PLUS_TOKEN', '') != '':
PUSH_PLUS_TOKEN = os.environ['PUSH_PLUS_TOKEN']
if os.environ.get('PUSH_PLUS_USER', '') != '':
@ -314,6 +328,27 @@ class Notify(object):
log.info('您未配置pushplus推送所需的PUSH_PLUS_TOKEN,取消pushplus推送')
pass
def cqhttp(self, text, status, desp):
if Notify.GO_CQHTTP_URL != '':
url = '{}{}'.format(Notify.GO_CQHTTP_URL, Notify.GO_CQHTTP_API)
data = {
'access_token': Notify.GO_CQHTTP_TOKEN,
'message': '{} {}\n\n{}'.format(text, status, desp),
'group_id': Notify.GO_CQHTTP_GROUP_NO
}
try:
response = self.to_python(requests.get(url, params=data).text)
except Exception as e:
log.error(e)
raise HTTPError
else:
if response['status'] == 'ok':
log.info('go-cqhttp推送成功')
else:
log.error('go-cqhttp推送失败:\n{}'.format(response))
else:
log.info('您未配置go-cqhttp推送所需的GO_CQHTTP_URL,取消go-cqhttp推送')
pass
def send(self, **kwargs):
app = '原神签到小助手'
status = kwargs.get('status', '')
@ -332,6 +367,7 @@ class Notify(object):
self.wwBot(app, status, msg)
self.iGot(app, status, msg)
self.pushPlus(app, status, msg)
self.cqhttp(app, status, msg)
if __name__ == '__main__':

100
ql_api.py Normal file
View File

@ -0,0 +1,100 @@
import json
import time
import requests
ql_auth_path = '/ql/config/auth.json'
# ql_auth_path = r'D:\Docker\ql\config\auth.json'
ql_url = 'http://localhost:5600'
def __get_token() -> str or None:
with open(ql_auth_path, 'r', encoding='utf-8') as f:
j_data = json.load(f)
return j_data.get('token')
def __get__headers() -> dict:
headers = {
'Accept': 'application/json',
'Content-Type': 'application/json;charset=UTF-8',
'Authorization': 'Bearer ' + __get_token()
}
return headers
# 查询环境变量
def get_envs(name: str = None) -> list:
params = {
't': int(time.time() * 1000)
}
if name is not None:
params['searchValue'] = name
res = requests.get(ql_url + '/api/envs', headers=__get__headers(), params=params)
j_data = res.json()
if j_data['code'] == 200:
return j_data['data']
return []
# 新增环境变量
def post_envs(name: str, value: str, remarks: str = None) -> list:
params = {
't': int(time.time() * 1000)
}
data = [{
'name': name,
'value': value
}]
if remarks is not None:
data[0]['remarks'] = remarks
res = requests.post(ql_url + '/api/envs', headers=__get__headers(), params=params, json=data)
j_data = res.json()
if j_data['code'] == 200:
return j_data['data']
return []
# 修改环境变量
def put_envs(_id: str, name: str, value: str, remarks: str = None) -> bool:
params = {
't': int(time.time() * 1000)
}
data = {
'name': name,
'value': value,
'_id': _id
}
if remarks is not None:
data['remarks'] = remarks
res = requests.put(ql_url + '/api/envs', headers=__get__headers(), params=params, json=data)
j_data = res.json()
if j_data['code'] == 200:
return True
return False
# 禁用环境变量
def disable_env(_id: str) -> bool:
params = {
't': int(time.time() * 1000)
}
data = [_id]
res = requests.put(ql_url + '/api/envs/disable', headers=__get__headers(), params=params, json=data)
j_data = res.json()
if j_data['code'] == 200:
return True
return False
# 启用环境变量
def enable_env(_id: str) -> bool:
params = {
't': int(time.time() * 1000)
}
data = [_id]
res = requests.put(ql_url + '/api/envs/enable', headers=__get__headers(), params=params, json=data)
j_data = res.json()
if j_data['code'] == 200:
return True
return False

View File

@ -1,2 +1,2 @@
# 米游社原神签到(腾讯云函数)
> 源代码来着 [https://github.com/Alvin7an/genshin-impact-helper](https://github.com/Alvin7an/genshin-impact-helper) 仅作适配
# 米游社原神签到(青龙版)
> 源代码来着 [https://github.com/y1ndan/genshin-impact-helper](https://github.com/y1ndan/genshin-impact-helper) 仅作适配