本帖最后由 苏半仙儿 于 2021-1-4 23:20 编辑
米游社时不时的就忘记签到,虽然奖励也不咋地,但蚊子腿也是肉呀,哈哈哈
打开米游社,自己抓几个包就行了。
关于act_id,region,uid和cookie,点开米游社首页的签到福利,里面会有很多请求,有部分GET请求带有这些参数
推荐PC抓手机的包
我用的抓包工具是:Charles,论坛有很多,自行搜索。
2020.11.19日更新说明:米游社搞了签到的头信息验证,18号之后开始签到失败,重新复制py脚本替换自己的信息即可。
2020.11.26日更新说明:米游社头信息DS信息生成(修复签到请求异常)本次更新参考了Github作者的DS生成算法
2021.1.4日更新说明:更新DS算法,根据米游社版本生成不同的DS信息(修复”请在米游社App内打开~“)
Python新手,代码很丑。
这是腾讯云函数版本,直接复制代码到腾讯云函数即可
[Python] 纯文本查看 复制代码 # -*- coding: utf-8 -*-
import json
import requests
import time
import hashlib
import string
import random
def main_handler(event, context):
buildHearders()
# 签到
signResult = sign()
# 游戏信息
totalSignDay = getTotalSignDay()["data"]
totalSignDay = totalSignDay["total_sign_day"]
gameInfo = getGameInfo()["data"]["list"][0]
signInfo = getSignInfo()["data"]
award = signInfo["awards"][totalSignDay - 1]
# 方糖message内容,请不要格式化这段字符串
message = '''>{}
##### 游戏昵称:{}
##### 冒险等级:{}
##### 签到结果:{}
##### 签到奖励:{} x {}
##### {}月累计签到:**{}** 天'''.format(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()+28800)), gameInfo["nickname"],
gameInfo["level"],
signResult['message'], award['name'], award['cnt'], signInfo["month"],
totalSignDay)
return notify(message)
# 设置请求头
def buildHearders():
headers["Cookie"] = cookie
headers["x-rpc-device_id"] = device_id
headers["Host"] = "api-takumi.mihoyo.com"
headers["Content-type"] = "application/json;charset=utf-8"
headers["Accept"] = "application/json, text/plain, */*"
headers["x-rpc-client_type"] = "5"
headers["x-rpc-app_version"] = app_version
headers["DS"] = getDS()
def md5(text):
md5 = hashlib.md5()
md5.update(text.encode())
return md5.hexdigest()
def getDS():
# n = 'cx2y9z9a29tfqvr1qsq6c7yz99b5jsqt' # v2.2.0 @Womsxd
n = 'h8w582wxwgqvahcdkpvdhbh2w9casgfl' # v2.3.0 web @povsister & @journey-ad
i = str(int(time.time()))
r = ''.join(random.sample(string.ascii_lowercase + string.digits, 6))
c = md5("salt=" + n + "&t=" + i + "&r=" + r)
return "{},{},{}".format(i, r, c)
# 签到
def sign():
signUrl = "https://api-takumi.mihoyo.com/event/bbs_sign_reward/sign"
param = {"act_id": act_id, "region": region, "uid": uid}
result = requests.request("POST", signUrl, headers=headers, data=json.dumps(param))
return json.loads(result.content)
# 获取签到信息
def getSignInfo():
url = "https://api-takumi.mihoyo.com/event/bbs_sign_reward/home?act_id={}"
userInfoResult = requests.get(url.format(act_id), headers=headers)
return json.loads(userInfoResult.content)
# 获取签到天数
def getTotalSignDay():
url = "https://api-takumi.mihoyo.com/event/bbs_sign_reward/info?region={}&act_id={}&uid={}"
userInfoResult = requests.get(url.format(region, act_id, uid), headers=headers)
return json.loads(userInfoResult.content)
# 获取游戏信息
def getGameInfo():
url = "https://api-takumi.mihoyo.com/binding/api/getUserGameRolesByCookie?game_biz=hk4e_cn"
userInfoResult = requests.get(url, headers=headers)
return json.loads(userInfoResult.content)
# 微信推送
def notify(message):
snedKey = "替换方糖通知key,度娘:server酱"
notifyUrl = "http://sc.ftqq.com/{}.send"
param = {'text': '米游社签到',
'desp': message}
notifyResult = requests.request("POST", notifyUrl.format(snedKey), headers={}, data=param, files=[])
return json.loads(notifyResult.text)
app_version = "2.3.0"
act_id = "e202009291139501"
region = "cn_gf01"
uid = "替换 uid"
cookie = "替换 cookie"
# 设备号随意,但不能为空
device_id = "94581081EDD446EFAA3A45B8CC636CCF"
headers = {
"User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 13_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) miHoYoBBS/2.3.0"
}
这个签到时间和实际时间差8小时,我弄不来py的时区问题。如果有大佬知道怎么搞,还请私我哦~~~
|