1.购买服务器
阿里云:
服务器购买地址
https://t.aliyun.com/U/kcrvBe若失效,可用地址
https://www.aliyun.com/activity/wuying/dj?source=5176.29345612&userCode=49hts92d腾讯云:
https://curl.qcloud.com/wJpWmSfU若失效,可用地址
https://cloud.tencent.com/act/cps/redirect?redirect=2446&cps_key=ad201ee2ef3b771157f72ee5464b1fea&from=console华为云
https://activity.huaweicloud.com/cps.html?fromacct=64b5cf7cc11b4840bb4ed2ea0b2f4468&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=2019052.部署教程
3.代码如下
import jsonimport osimport requestsimport urllib3from dailycheckin import CheckInurllib3.disable_warnings()class AliYun(CheckIn):name = "阿里云盘"def __init__(self, check_item: dict):self.check_item = check_itemdef update_token(self, refresh_token):url = "https://auth.aliyundrive.com/v2/account/token"data = {"grant_type": "refresh_token", "refresh_token": refresh_token}response = requests.post(url=url, json=data).json()access_token = response.get("access_token")return access_tokendef sign(self, access_token):url = "https://member.aliyundrive.com/v1/activity/sign_in_list"headers = {"Authorization": access_token, "Content-Type": "application/json"}result = requests.post(url=url, headers=headers, json={}).json()sign_days = result["result"]["signInCount"]data = {"signInDay": sign_days}url_reward = "https://member.aliyundrive.com/v1/activity/sign_in_reward"requests.post(url=url_reward, headers=headers, data=json.dumps(data))if "success" in result:print("签到成功")for i, j in enumerate(result["result"]["signInLogs"]):if j["status"] == "miss":day_json = result["result"]["signInLogs"][i - 1]if not day_json["isReward"]:msg = [{"name": "阿里云盘","value": "签到成功,今日未获得奖励",}]else:msg = [{"name": "累计签到","value": result["result"]["signInCount"],},{"name": "阿里云盘","value": "获得奖励:{}{}".format(day_json["reward"]["name"],day_json["reward"]["description"],),},]return msgdef main(self):refresh_token = self.check_item.get("refresh_token")access_token = self.update_token(refresh_token)if not access_token:return [{"name": "阿里云盘", "value": "token 过期"}]msg = self.sign(access_token)msg = "\n".join([f"{one.get('name')}: {one.get('value')}" for one in msg])return msgif __name__ == "__main__":with open(os.path.join(os.path.dirname(os.path.dirname(__file__)), "config.json"),encoding="utf-8",) as f:datas = json.loads(f.read())_check_item = datas.get("ALIYUN", [])[0]print(AliYun(check_item=_check_item).main())
解析
这个脚本是通过 阿里云盘 的 API 自动进行签到操作,并返回签到结果和奖励情况。继承自 CheckIn 类,用于每日自动签到并输出签到结果。
主要方法
update_token(refresh_token):该方法使用传入的
refresh_token获取新的access_token,用于后续的 API 请求。sign(access_token):使用获取到的
access_token进行签到,返回签到结果。如果当日未获得奖励,会显示"今日未获得奖励",否则会显示累计签到天数和奖励详情。
main():该方法是脚本的入口,获取配置中的
refresh_token,然后更新access_token,并调用sign方法进行签到。最后格式化输出签到信息。
该脚本自动更新 access_token,然后使用该令牌在 阿里云盘 完成签到任务,并返回签到的状态信息和奖励详情。如果 access_token 过期,则返回"token 过期"的提示。
[历史文章]
注意:
本文部分变量已做脱敏处理,仅用于测试和学习研究,禁止用于商业用途,不能保证其合法性,准确性,完整性和有效性,请根据情况自行判断。技术层面需要提供帮助,可以通过打赏的方式进行探讨。
没有评论:
发表评论