class ReqCtrl: join_v4_ctrl = Ctrl(extend=( { 'code': -401, 'msg': In('登录') }, JsonRspType.LOGOUT, { 'code': 0 }, JsonRspType.OK, { 'code': -405 }, JsonRspType.OK, # 奖品都被领完啦 { 'code': -403, 'msg': In('已') }, JsonRspType.OK, # 'code': -403, 'msg': '您已参加抽奖~' { 'code': -403, 'msg': In('拒绝') }, JsonRspType.OK, # 'code': -403, 'msg': '访问被拒绝' { 'code': -401, 'msg': In('没开始') }, JsonRspType.OK, # 抽奖还没开始哦 ))
class ReqCtrl: check_ctrl = Ctrl(extend=( { 'code': -500 }, JsonRspType.LOGOUT, { 'code': 0 }, JsonRspType.OK, { 'code': -400 }, JsonRspType.OK, )) join_ctrl = Ctrl(extend=( { 'code': -500, 'msg': In('登录') }, JsonRspType.LOGOUT, { 'code': -500, 'msg': In('非法') }, JsonRspType.OK, { 'code': 0 }, JsonRspType.OK, { 'code': -1 }, JsonRspType.OK, # 未开始抽奖 { 'code': -400 }, JsonRspType.OK, # 不存在/已经过期 { 'code': -3 }, JsonRspType.OK, # 已抽过 { 'code': 400, 'msg': In('拒绝') }, JsonRspType.OK, # 小黑屋 ))
class ReqCtrl: join_v4_ctrl = Ctrl( BaseCtrl( logout_verifiers=[CtrlElem(code=-401, others=[In('msg', '登录')])], ok_verifiers=[ CtrlElem(code=0), CtrlElem(code=-405), # 奖品都被领完啦 CtrlElem(code=-403, others=[In('msg', '已')]), # 'code': -403, 'msg': '您已参加抽奖~' CtrlElem(code=-403, others=[In('msg', '拒绝')]), # 'code': -403, 'msg': '访问被拒绝' CtrlElem(code=-401, others=[In('msg', '没开始')]) # 抽奖还没开始哦 ]))
class ReqCtrl: check_ctrl = Ctrl( BaseCtrl(logout_verifiers=[CtrlElem(code=-500)], ok_verifiers=[CtrlElem(code=0), CtrlElem(code=-400)])) join_ctrl = Ctrl( BaseCtrl( logout_verifiers=[CtrlElem(code=-500)], ok_verifiers=[ CtrlElem(code=0), CtrlElem(code=-1), # 未开始抽奖 CtrlElem(code=-400), # 不存在/已经过期 CtrlElem(code=-3), # 已抽过 CtrlElem(code=400, others=[In('msg', '拒绝')]) # 小黑屋 ]))
from json_rsp_ctrl import Ctrl, JsonRspType, In # 为 login 的相关请求专门设计,在登陆中返回"JsonRspType.LOGOUT"不管的。 # 其余和 BASE_CTRL 一样就行 LOGIN_CTRL = Ctrl( extend=( { 'code': 0 }, JsonRspType.OK, # 目前为止,0 肯定成功,如果例外,自己另写 { 'code': 1024 }, JsonRspType.IGNORE, { 'msg': In('操作太快') }, JsonRspType.IGNORE, { 'msg': In('系统繁忙') }, JsonRspType.IGNORE, { 'msg': In('过于频繁') }, JsonRspType.IGNORE, { 'message': In('服务繁忙') }, JsonRspType.IGNORE, ),
import base64 import requests import utils from json_rsp_ctrl import Ctrl, JsonRspType, In # 为 login 的相关请求专门设计,在登陆中返回"JsonRspType.LOGOUT"不管的。 # 其余和 BASE_CTRL 一样就行 LOGIN_CTRL = Ctrl( extend=( {'code': 0}, JsonRspType.OK, # 目前为止,0 肯定成功,如果例外,自己另写 {'code': 1024}, JsonRspType.IGNORE, {'msg': In('操作太快')}, JsonRspType.IGNORE, {'msg': In('系统繁忙')}, JsonRspType.IGNORE, {'msg': In('过于频繁')}, JsonRspType.IGNORE, {'message': In('服务繁忙')}, JsonRspType.IGNORE, ), base=None, default=JsonRspType.OK ) class LoginReq: @staticmethod async def logout(user): url = 'https://passport.bilibili.com/login?act=exit' json_rsp = await user.login_session.request_json('GET', url, headers=user.dict_bili['pcheaders'], ctrl=LOGIN_CTRL) return json_rsp @staticmethod
import utils from json_rsp_ctrl import Ctrl, JsonRspType, In, BASE_CTRL MANGA_SIGN_CTRL = Ctrl(extend=( { 'msg': In('uid must > 0') }, JsonRspType.LOGOUT, ), base=BASE_CTRL, default=JsonRspType.OK) class MangaSignReq: @staticmethod async def sign(user): url = 'https://manga.bilibili.com/twirp/activity.v1.Activity/ClockIn' extra_params = [ f'access_key={user.dict_bili["access_key"]}', f'ts={utils.curr_time()}' ] params = user.sort_and_sign(extra_params) json_rsp = await user.other_session.request_json( 'POST', url, # 不知道为啥必须这么做2333 headers={ **user.dict_bili['appheaders'], 'Content-Type': "application/x-www-form-urlencoded" },
import utils from json_rsp_ctrl import Ctrl, JsonRspType, In, BASE_CTRL MANGA_SIGN_CTRL = Ctrl( extend=( {'msg': In('uid must > 0')}, JsonRspType.LOGOUT, ), base=BASE_CTRL, default=JsonRspType.OK ) class MangaSignReq: @staticmethod async def sign(user): url = 'https://manga.bilibili.com/twirp/activity.v1.Activity/ClockIn' extra_params = { 'access_key': user.dict_bili['access_key'], 'ts': utils.curr_time(), } params = user.sort_and_sign(extra_params) json_rsp = await user.other_session.request_json( 'POST', url, headers=user.dict_bili['appheaders'], data=params, ctrl=MANGA_SIGN_CTRL, ok_status_codes=(200, 400,) ) return json_rsp