原神-米游社签到
通过python实现,需要手动传入cookie值。
经测试,米游社的cookie有效期很长
- 一些必要的参数
ACT_ID = 'e202009291139501'
USER_AGENT = 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_0_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) miHoYoBBS/{}'
REFERER_URL = 'https://webstatic.mihoyo.com/bbs/event/signin-ys/index.html?bbs_auth_required={}&act_id={}&utm_source={}&utm_medium={}&utm_campaign={}'.format('true', ACT_ID, 'bbs', 'mys', 'icon')
ROLES_INFO = {}
INFO_URL = ''
ROLE_URL = 'https://api-takumi.mihoyo.com/binding/api/getUserGameRolesByCookie?game_biz={}'.format('hk4e_cn')
_INFO_URL = 'https://api-takumi.mihoyo.com/event/bbs_sign_reward/info?region={}&act_id={}&uid={}'
REWARD_URL = 'https://api-takumi.mihoyo.com/event/bbs_sign_reward/home?act_id={}'.format(ACT_ID)
SIGN_URL = 'https://api-takumi.mihoyo.com/event/bbs_sign_reward/sign'
act_id = "e202009291139501"
region = "cn_gf01"
- 初始化请求头
该处需要传入两个参数
- cookie -> 需要填入自己的cookie
- USER_AGENT ->上一步已经初始化
def get_header(self):
ds = getDS()
header = {
'Cookie': self._cookie,
'User-Agent': self.USER_AGENT,
'Accept-Encoding': 'gzip, deflate, br',
'x-rpc-device_id': '94581081EDD446EFAA3A45B8CC636CCF',
'Content-type': 'application/json;charset=utf-8',
'Accept': 'application/json, text/plain, */*',
'x-rpc-client_type': '5',
'x-rpc-app_version': "2.3.0",
'DS': ds
}
return header
- 根据请求头,对不同的内容进行请求
# 获取游戏信息json.loads(userInfoResult.content)
def getGameInfo(self):
url = "https://api-takumi.mihoyo.com/binding/api/getUserGameRolesByCookie?game_biz=hk4e_cn"
response = requests.get(url, headers=self.get_header()).json()
return response
# 签到
def sign(self):
signUrl = "https://api-takumi.mihoyo.com/event/bbs_sign_reward/sign"
param = {"act_id": self.act_id, "region": self.region, "uid": self.uid}
result = requests.request("POST", signUrl, headers=self.get_header(), data=json.dumps(param))
return json.loads(result.content)
# 获取签到天数
def getTotalSignDay(self):
url = "https://api-takumi.mihoyo.com/event/bbs_sign_reward/info?region={}&act_id={}&uid={}"
userInfoResult = requests.get(url.format(self.region, self.act_id, self.uid), headers=self.get_header())
return json.loads(userInfoResult.content)
# 获取签到信息
def getSignInfo(self):
url = "https://api-takumi.mihoyo.com/event/bbs_sign_reward/home?act_id={}"
userInfoResult = requests.get(url.format(self.act_id), headers=self.get_header())
return json.loads(userInfoResult.content)
完整代码如下。
点击展开
class Yuanshen(object):
ACT_ID = 'e202009291139501'
USER_AGENT = 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_0_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) miHoYoBBS/{}'
REFERER_URL = 'https://webstatic.mihoyo.com/bbs/event/signin-ys/index.html?bbs_auth_required={}&act_id={}&utm_source={}&utm_medium={}&utm_campaign={}'.format('true', ACT_ID, 'bbs', 'mys', 'icon')
ROLES_INFO = {}
INFO_URL = ''
ROLE_URL = 'https://api-takumi.mihoyo.com/binding/api/getUserGameRolesByCookie?game_biz={}'.format('hk4e_cn')
_INFO_URL = 'https://api-takumi.mihoyo.com/event/bbs_sign_reward/info?region={}&act_id={}&uid={}'
REWARD_URL = 'https://api-takumi.mihoyo.com/event/bbs_sign_reward/home?act_id={}'.format(ACT_ID)
SIGN_URL = 'https://api-takumi.mihoyo.com/event/bbs_sign_reward/sign'
act_id = "e202009291139501"
region = "cn_gf01"
def __init__(self, cookie: str = None):
self._cookie = cookie
self.gameInfo = self.getGameInfo()["data"]["list"][0]
self.uid = self.gameInfo['game_uid']
def get_header(self):
ds = getDS()
header = {
'Cookie': self._cookie,
'User-Agent': self.USER_AGENT,
'Accept-Encoding': 'gzip, deflate, br',
'x-rpc-device_id': '94581081EDD446EFAA3A45B8CC636CCF',
'Content-type': 'application/json;charset=utf-8',
'Accept': 'application/json, text/plain, */*',
'x-rpc-client_type': '5',
'x-rpc-app_version': "2.3.0",
'DS': ds
}
return header
# 获取游戏信息json.loads(userInfoResult.content)
def getGameInfo(self):
url = "https://api-takumi.mihoyo.com/binding/api/getUserGameRolesByCookie?game_biz=hk4e_cn"
response = requests.get(url, headers=self.get_header()).json()
return response
# 签到
def sign(self):
signUrl = "https://api-takumi.mihoyo.com/event/bbs_sign_reward/sign"
param = {"act_id": self.act_id, "region": self.region, "uid": self.uid}
result = requests.request("POST", signUrl, headers=self.get_header(), data=json.dumps(param))
return json.loads(result.content)
# 获取签到天数
def getTotalSignDay(self):
url = "https://api-takumi.mihoyo.com/event/bbs_sign_reward/info?region={}&act_id={}&uid={}"
userInfoResult = requests.get(url.format(self.region, self.act_id, self.uid), headers=self.get_header())
return json.loads(userInfoResult.content)
# 获取签到信息
def getSignInfo(self):
url = "https://api-takumi.mihoyo.com/event/bbs_sign_reward/home?act_id={}"
userInfoResult = requests.get(url.format(self.act_id), headers=self.get_header())
return json.loads(userInfoResult.content)
def run(self):
sign_result = self.sign() # 签到,更新签到信息
sign_info = self.getSignInfo()['data'] # 签到总体信息
sign_day = self.getTotalSignDay()['data'] # 获取签到天数以及是否签到
award_list = sign_info['awards'] # 签到奖励list
is_sign = sign_day['is_sign']
total_sign_day = sign_day['total_sign_day']
sign_award = award_list[total_sign_day - 1]