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
=
.
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
=
'h8w582wxwgqvahcdkpvdhbh2w9casgfl'
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"
}