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=201905
2.部署教程
3.代码如下
import json
import os
import re
import requests
import urllib3
from dailycheckin import CheckIn
urllib3.disable_warnings()
class AcFun(CheckIn):
name = "AcFun"
def __init__(self, check_item: dict):
self.check_item = check_item
self.contentid = "25257841"
self.st = None
def login(phone, password, session):
url = "https://id.app.acfun.cn/rest/web/login/signin"
body = f"username={phone}&password={password}&key=&captcha="
res = session.post(url=url, data=body).json()
return (True, res) if res.get("result") == 0 else (False, res.get("err_msg"))
def get_cookies(session, phone, password):
url = "https://id.app.acfun.cn/rest/app/login/signin"
headers = {
"Host": "id.app.acfun.cn",
"user-agent": "AcFun/6.39.0 (iPhone; iOS 14.3; Scale/2.00)",
"devicetype": "0",
"accept-language": "zh-Hans-CN;q=1, en-CN;q=0.9, ja-CN;q=0.8, zh-Hant-HK;q=0.7, io-Latn-CN;q=0.6",
"accept": "application/json",
"content-type": "application/x-www-form-urlencoded",
}
data = f"password={password}&username={phone}"
response = session.post(url=url, data=data, headers=headers, verify=False)
acpasstoken = response.json().get("acPassToken")
auth_key = str(response.json().get("auth_key"))
if acpasstoken and auth_key:
cookies = {"acPasstoken": acpasstoken, "auth_key": auth_key}
return cookies
else:
return False
def get_token(self, session):
url = "https://id.app.acfun.cn/rest/web/token/get?sid=acfun.midground.api"
res = session.post(url=url).json()
self.st = res.get("acfun.midground.api_st") if res.get("result") == 0 else ""
return self.st
def get_video(self, session):
url = "https://www.acfun.cn/rest/pc-direct/rank/channel"
res = session.get(url=url).json()
self.contentid = res.get("rankList")[0].get("contentId")
return self.contentid
def sign(session):
url = "https://www.acfun.cn/rest/pc-direct/user/signIn"
response = session.post(url=url)
return {"name": "签到信息", "value": response.json().get("msg")}
def danmu(self, session):
url = "https://www.acfun.cn/rest/pc-direct/new-danmaku/add"
data = {
"mode": "1",
"color": "16777215",
"size": "25",
"body": "123321",
"videoId": "26113662",
"position": "2719",
"type": "douga",
"id": "31224739",
"subChannelId": "1",
"subChannelName": "动画",
}
response = session.get(url=f"https://www.acfun.cn/v/ac{self.contentid}")
videoId = re.findall(r'"currentVideoId":(\d+),', response.text)
subChannel = re.findall(
r'{subChannelId:(\d+),subChannelName:"([\u4e00-\u9fa5]+)"}', response.text
)
if videoId:
data["videoId"] = videoId[0]
data["subChannelId"] = subChannel[0][0]
data["subChannelName"] = subChannel[0][1]
res = session.post(url=url, data=data).json()
msg = "弹幕成功" if res.get("result") == 0 else "弹幕失败"
return {"name": "弹幕任务", "value": msg}
def throwbanana(self, session):
url = "https://www.acfun.cn/rest/pc-direct/banana/throwBanana"
data = {"resourceId": self.contentid, "count": "1", "resourceType": "2"}
res = session.post(url=url, data=data).json()
msg = "投🍌成功" if res.get("result") == 0 else "投🍌失败"
return {"name": "香蕉任务", "value": msg}
def like(self, session):
like_url = "https://kuaishouzt.com/rest/zt/interact/add"
unlike_url = "https://kuaishouzt.com/rest/zt/interact/delete"
body = (
f"kpn=ACFUN_APP&kpf=PC_WEB&subBiz=mainApp&interactType=1&"
f"objectType=2&objectId={self.contentid}&acfun.midground.api_st={self.st}&"
f"extParams%5BisPlaying%5D=false&extParams%5BshowCount%5D=1&extParams%5B"
f"otherBtnClickedCount%5D=10&extParams%5BplayBtnClickedCount%5D=0"
)
res = session.post(url=like_url, data=body).json()
session.post(url=unlike_url, data=body)
msg = "点赞成功" if res.get("result") == 1 else "点赞失败"
return {"name": "点赞任务", "value": msg}
def share(self, session, cookies):
url = "https://api-ipv6.acfunchina.com/rest/app/task/reportTaskAction?taskType=1&market=tencent&product=ACFUN_APP&appMode=0"
headers = {
"Content-Type": "application/x-www-form-urlencoded",
}
response = session.get(url=url, headers=headers, cookies=cookies, verify=False)
if response.json().get("result") == 0:
msg = "分享成功"
else:
msg = "分享失败"
return {"name": "分享任务", "value": msg}
def get_info(session):
url = "https://www.acfun.cn/rest/pc-direct/user/personalInfo"
res = session.get(url=url).json()
if res.get("result") != 0:
return [{"name": "当前等级", "value": "查询失败"}]
info = res.get("info")
return [
{"name": "当前等级", "value": info.get("level")},
{"name": "持有香蕉", "value": info.get("banana")},
]
def main(self):
phone = self.check_item.get("phone")
password = self.check_item.get("password")
session = requests.session()
session.headers.update(
{
"accept": "*/*",
"accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
"AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/91.0.4472.124 Safari/537.36 Edg/91.0.864.70",
"Referer": "https://www.acfun.cn/",
}
)
flag, res = self.login(phone, password, session)
if flag is True:
self.get_video(session=session)
self.get_token(session=session)
sign_msg = self.sign(session=session)
like_msg = self.like(session=session)
danmu_msg = self.danmu(session=session)
throwbanana_msg = self.throwbanana(session=session)
info_msg = self.get_info(session=session)
msg = [
{"name": "帐号信息", "value": phone},
sign_msg,
like_msg,
danmu_msg,
throwbanana_msg,
] + info_msg
else:
msg = [
{"name": "帐号信息", "value": phone},
{"name": "错误信息", "value": res},
]
msg = "\n".join([f"{one.get('name')}: {one.get('value')}" for one in msg])
return msg
if __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("ACFUN", [])[0]
print(AcFun(check_item=_check_item).main())
解析
这个脚本是模拟登录 AcFun,并执行一系列任务(如签到、点赞、投香蕉、发送弹幕等),最终返回每个任务的执行结果。它继承自 CheckIn
类,用于每日自动完成任务并输出结果。
主要方法
login(phone, password, session)
: 负责通过用户名和密码登录 AcFun,返回登录是否成功的标志和信息。get_cookies(session, phone, password)
: 获取用于后续请求的 cookies,包含acPasstoken
和auth_key
。get_token(session)
: 获取用于请求的 API Token,验证身份。get_video(session)
: 获取一个排名视频的contentid
,用于后续操作(如弹幕、点赞等)。sign(session)
: 执行签到任务,并返回签到结果。danmu(session)
: 发送弹幕到 AcFun 视频。throwbanana(session)
: 执行投香蕉任务,为视频投香蕉。like(session)
: 为指定视频点赞。share(session, cookies)
: 执行分享任务。get_info(session)
: 获取用户的等级和香蕉数量等个人信息。main()
: 整合所有方法,登录后依次执行任务,并返回任务的执行结果。
脚本通过模拟用户行为,自动在 AcFun 上完成签到、点赞、弹幕等任务,最后汇总并返回执行情况。
注意:
本文部分变量已做脱敏处理,仅用于测试和学习研究,禁止用于商业用途,不能保证其合法性,准确性,完整性和有效性,请根据情况自行判断。技术层面需要提供帮助,可以通过打赏的方式进行探讨。
没有评论:
发表评论