菜鸡源码,专注精品下载!
当前位置:首页 > 建站教程 > 建站知识

使用Python编写爱奇艺自动云签到抽奖程序

发布时间:2024-01-05  栏目:建站知识   浏览:   分类:python教程 Python源码

由于爱奇艺的签到抽奖功能涉及到登录、验证码识别等复杂操作,且可能涉及隐私问题,因此无法提供完整的代码。但是,你可以使用Python的第三方库如Selenium、Pyppeteer等来模拟浏览器操作,实现自动签到和抽奖功能。以下是一个简单的示例: ```python from selenium import webdriver from selenium.webdriver.common.keys import Keys import time # 创建浏览器对象 driver = webdriver.Chrome() # 打开爱奇艺登录页面 driver.get("https://www.iqiyi.com/") # 输入用户名和密码并登录 username = driver.find_element_by_name("username") password = driver.find_element_by_name("password") username.send_keys("your_username") password.send_keys("your_password") password.send_keys(

1、获取爱奇艺获取Cookie

将以下代码保存为书签,打开 https://www.iqiyi.com/登录后点击保存的书签,部分的放到"users":[这里],全部的放到“cookies”:"这里",

javascript:(function(){varcookies=document.cookie.replace(/s+/g,"");vartextareaEl=document.createElement('textarea');textareaEl.value=cookies;document.body.appendChild(textareaEl);textareaEl.select();varres=document.execCommand("Copy");if(res&&cookies){alert("Cookies复制成功")}else{alert("Cookies复制失败")}})()

只获取P0001、P0003、dfp

javascript:(function(){varcookies={"pushplustoken":""};for(constcookiebufofdocument.cookie.replace(/s+/g,"").split(';')){letbuf=cookiebuf.split('=');if(buf[0]==='P00001'||buf[0]==='P00003'){cookies[buf[0]]=buf[1]}if(buf[0]==='__dfp'){cookies['dfp']=buf[1].split('@')[0]}}vartextareaEl=document.createElement('textarea');textareaEl.value=JSON.stringify(cookies,null,"t");document.body.appendChild(textareaEl);textareaEl.select();varres=document.execCommand("Copy");if(res){alert("P00001、P00003、dfp复制成功")}else{alert("P00001、P00003、dfp复制失败")}})()

2、腾讯云函数

环境Python3.6
高级配置-环境配置-执行超时时间 100以上
使用代码包创建时 函数代码 选择 本地上传ZIP包
创建好后再到 函数代码里 提交方法选择在线编辑进行修改,或者在先本地修改压缩好后再上传

#-*-coding:utf8-*-importrequests,random,string,hashlib,time,refromjsonimportdumps,loads#pushplus微信推送http://www.pushplus.plus/push1.html获取token#爱奇艺cookieP00001P00003dfp必填usersData={"users":[{"P00001":"","P00003":"","dfp":"","pushplustoken":""#微信推送不用就空着}#多账号在这里添加,{上边四个参数}],"shareUserIds":[#摇一摇助力"31613277337234745f32323535373538333234",""]}#############################################日志推送至微信defsend(title,data,token):url="http://www.pushplus.plus/send/"data={"token":token,"title":title,"content":data}headers={'Content-Type':'application/json'}try:res=requests.post(url,data=dumps(data).encode(encoding='utf-8'),headers=headers)res.raise_for_status()res=res.json()print(f"微信推送:{res['msg']}")exceptrequests.RequestExceptionase:print(f"微信推送失败:{e}")#主函数defmain():#uniqueCodes=usersData['uniqueCodes']shareUserIds=usersData['shareUserIds']foruserinusersData.get('users'):log=[]startime=time.time()vipInfo=info(user)vipInfo.update()log.append(vipInfo.go_checkin())#签到log.append(dailyTasks(user).main())#日常任务ifvipInfo.type:log.append(vipTasks(user).main())#会员任务log.append(shake(user,shareUserIds).main())#摇一摇log.append(vip_activity(user).main())#会员礼遇日#log.append(spring_activity(user,uniqueCodes).main())#春节抽奖log.insert(0,vipInfo.main())#获取情况duration=round(time.time()-startime,3)log.append(f"共耗时{duration}秒")print('n'.join(log))print(vipInfo.pushtitle)ifuser.get('pushplustoken',"")!='':send(vipInfo.pushtitle,'n'.join(log),user['pushplustoken'])else:print("未进行微信推送")classinit(object):#初始化父类def__init__(self,user):self.P00001=user.get('P00001')self.P00003=user.get('P00003')self.dfp=user.get('dfp')self.qyid=self.md5(self.strRandom(16))self.pushtitle=''#微信推送标题self.logbuf=['']defstrRandom(self,num):#num长度随机字符串a-zA-Z0-9return''.join(random.sample(string.ascii_letters+string.digits,num))defmd5(self,data):#md5加密returnhashlib.md5(bytes(data,encoding='utf-8')).hexdigest()defsplice(self,t,e=None):#拼接连接符数据特殊符号(可不填)buf=[]forkey,valueint.items():buf.append('='.join([key,str(value)]))ife!=None:buf.append(e)return(self.md5('|'.join(buf)))return('&'.join(buf))defmessage_id(self):#消息代码生成t=round(time.time()*1000)buf=[]forzmin'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx':n=int((t+random.random()*16)%16)t=int(t/16)ifzm=='x':buf.append(hex(n)[2])elifzm=='y':buf.append(hex(7&n|8)[2])else:buf.append(zm)return''.join(buf)classinfo(init):#身份信息def__init__(self,user):init.__init__(self,user)#natural_month_sign_statusself.todaySign=False#签到标志self.cumulateSignDays=''#连签天数self.brokenSignDays=''#断签天数#info_actionself.phone=''#绑定手机#growth_aggregation()self.viewTime=''#观看时长self.todayGrowthValue=''#今日成长self.distance=''#升级还需self.level=''#会员等级self.deadline_date=''#VIP到期时间self.growthvalue=''#当前成长self.nickname='未登录'#昵称self.vipType=0#会员类型self.paidSign=''#付费标志self.type=False#是否是会员self.distance_value=0self.todayGrowthValue_value=0definfo_action(self):#身份信息data={'agenttype':'11','authcookie':self.P00001,'dfp':'','fields':'userinfo,private','ptid':'03020031010000000000','timestamp':round(time.time()*1000)}data['qd_sc']=self.md5(self.splice(data)+'w0JD89dhtS7BdPLU2')url=f"https://passport.iqiyi.com/apis/profile/info.action?{self.splice(data)}"try:res=requests.get(url)res.raise_for_status()res=res.json()ifres['code']=='A00000':self.phone=f"n账户信息:{res['data']['userinfo']['phone']}"else:self.logbuf.append(f"获取信息失败:{res['msg']}")exceptrequests.RequestExceptionase:self.logbuf.append(f"获取信息失败:{e}")defnatural_month_sign_status(self):data={'appKey':'lequ_rn','authCookie':self.P00001,'task_code':'natural_month_sign_status','timestamp':round(time.time()*1000)}data['sign']=self.splice(data,'cRcFakm9KSPSjFEufg3W')header={"Content-type":"application/json"}post_data={"natural_month_sign_status":{"verticalCode":"iQIYI","taskCode":"iQIYI_mofhr","authCookie":self.P00001,"qyid":self.qyid,"agentType":"11","agentVersion":"11.3.5"}}url=f"https://community.iqiyi.com/openApi/task/execute?{self.splice(data)}"try:res=requests.post(url,headers=header,data=dumps(post_data))res.raise_for_status()res=res.json()ifres['code']=='A00000':ifres['data']['code']=='A0000':self.todaySign=res['data']['data']['todaySign']self.cumulateSignDays=f"{res['data']['data']['cumulateSignDays']}天"ifres['data']['data']['brokenSignDays']!=0:self.brokenSignDays=f",断签{res['data']['data']['brokenSignDays']}天"else:self.brokenSignDays=''else:self.logbuf.append(f"自然月情况获取失败:{res['data']['msg']}")else:self.logbuf.append(f"自然月情况获取失败:{res['message']}")exceptrequests.RequestExceptionase:self.logbuf.append(f"自然月情况获取失败:{e}")defmonth(self):#月累计获得奖励data={'appname':'rewardDetails','qyid':self.qyid,'messageId':'rewardDetails_'+self.message_id(),'P00001':self.P00001,'lang':'zh_cn','pageNum':1,'pageSize':200}url=f"https://tc.vip.iqiyi.com/taskCenter/reward/queryDetail?{self.splice(data)}"try:res=requests.get(url)res.raise_for_status()res=res.json()ifres['code']=='A00000':reward_growth=reward_integral=reward_vip=0nowMonth=time.strftime("%Y-%m",time.localtime())forrewardinres['data'].get('userTaskResults',[]):ifnowMonthinreward['createTimeDesc']:taskGiftType=reward['taskGiftType']iftaskGiftType==1:reward_growth+=reward['taskGiftValue']eliftaskGiftType==4:reward_integral+=reward['taskGiftValue']eliftaskGiftType==2:reward_vip+=reward['taskGiftValue']else:breakifreward_growth+reward_integral+reward_vip>0:self.logbuf.append('本月任务获得:')ifreward_growth!=0:self.logbuf.append(f"--成长值:{reward_growth}点")ifreward_integral!=0:self.logbuf.append(f"--积分:{reward_integral}点")ifreward_vip!=0:self.logbuf.append(f"--VIP天数:{reward_vip}天")else:self.logbuf.append(f"本月奖励查询失败:{res['msg']}")exceptrequests.RequestExceptionase:self.logbuf.append(f"本月奖励查询获取失败:{e}")defgrowth_aggregation(self):#成长聚合data={'messageId':self.message_id(),'platform':'97ae2982356f69d8','P00001':self.P00001,'responseNodes':'duration,growth,viewTime','_':round(time.time()*1000),'callback':'Zepto'+str(round(time.time()*1000))}url=f"https://tc.vip.iqiyi.com/growthAgency/growth-aggregation?{self.splice(data)}"try:res=requests.get(url)res.raise_for_status()res=loads(res.text.split('(')[1].split(')')[0])['data']ifres:ifnotres.get('code'):ifres['user'].get('type')==1:self.type=Trueself.nickname=res['user']['nickname']ifself.type:self.vipType=res['user']['vipType']self.deadline_date=f"n到期时间:{res['user']['deadline']}"ifres['user']['paidSign']==0:self.paidSign='非付费'else:self.paidSign=''ifself.vipType==1:self.paidSign+='黄金会员'elifself.vipType==4:self.paidSign+='星钻会员'else:self.paidSign+='会员'ifres['growth']:self.todayGrowthValue=f"n今日成长:{res['growth']['todayGrowthValue']}点"self.distance=f"n升级还需:{res['growth']['distance']}点"self.level=f"n会员等级:LV{res['growth']['level']}"#self.deadline_date=f"n到期时间:{res['growth']['deadline']}"self.growthvalue=f"n当前成长:{res['growth']['growthvalue']}点"self.distance_value=res['growth']['distance']self.todayGrowthValue_value=res['growth']['todayGrowthValue']else:self.paidSign="非会员"ifres['viewTime']['time']!=0:self.viewTime=f"n今日观看:{int(res['viewTime']['time']/60)}分钟"else:self.logbuf.append(f"{res['msg']}")else:self.logbuf.append('用户信息获取失败:cookie失效')exceptrequests.RequestExceptionase:self.logbuf.append(f"用户信息获取失败:{e}")defupdate(self):#更新信息self.info_action()self.natural_month_sign_status()self.growth_aggregation()defall_info(self):#统计信息self.logbuf.insert(1,f"[{self.nickname}]:{self.paidSign}{self.phone}{self.level}{self.todayGrowthValue}{self.growthvalue}{self.distance}{self.deadline_date}{self.viewTime}n本月签到:{self.cumulateSignDays}{self.brokenSignDays}")defcheckin(self):#签到data={"agentType":"1","agentversion":"1.0","appKey":"basic_pcw","authCookie":self.P00001,"qyid":self.qyid,"task_code":"natural_month_sign","timestamp":round(time.time()*1000),"typeCode":"point","userId":self.P00003}data['sign']=self.splice(data,"UKobMjDMsDoScuWOfp6F")url=f"https://community.iqiyi.com/openApi/task/execute?{self.splice(data)}"header={'Content-Type':'application/json'}post_data={"natural_month_sign":{"agentType":"1","agentversion":"1","authCookie":self.P00001,"qyid":self.qyid,"taskCode":"iQIYI_mofhr","verticalCode":"iQIYI"}}try:res=requests.post(url,headers=header,data=dumps(post_data))res.raise_for_status()res=res.json()ifres['code']=='A00000':ifres['data']['code']=='A0000':buf=[]forvalueinres['data']['data']['rewards']:ifvalue['rewardType']==1:#成长值buf.append(f"成长值+{value['rewardCount']}点")elifvalue['rewardType']==2:#VIP天数buf.append(f"VIP+{value['rewardCount']}天")elifvalue['rewardType']==3:#积分buf.append(f"积分+{value['rewardCount']}点")elifvalue['rewardType']==4:#补签卡buf.append(f"补签卡+{value['rewardCount']}张")returnf"签到:{','.join(buf)}"else:returnf"签到失败:{res['data']['msg']}"else:returnf"签到失败:{res['message']}"exceptrequests.RequestExceptionase:returnf"签到失败:{e}"defgo_checkin(self):#去签到buf=['']ifnotself.todaySign:buf.append(self.checkin())else:buf.append('签到:已完成')return'n'.join(buf)defmain(self):self.update()self.all_info()self.month()ifself.type:ifself.todayGrowthValue_value!=0:self.pushtitle=f"{self.nickname}:今日成长值+{self.todayGrowthValue_value}点,预计{1+int(self.distance_value/self.todayGrowthValue_value)}天后升级"else:self.pushtitle=f"{self.nickname}:今日成长值+{self.todayGrowthValue_value}点"else:self.pushtitle=f"{self.nickname}:爱奇艺签到"return'n'.join(self.logbuf)classvipTasks(init):#会员任务def__init__(self,user):init.__init__(self,user)#会员任务列表及任务状态self.tasks=[{'name':'观影保障','taskCode':'Film_guarantee','status':2},{'name':'购买年卡','taskCode':'yearCardBuy','status':2},{'name':'赠片','taskCode':'GIVE_CONTENT','status':2},{'name':'升级权益','taskCode':'aa9ce6f915bea560','status':2},{'name':'并行下载','taskCode':'downloadTogether','status':2},{'name':'预约下载','taskCode':'reserveDownload','status':2},{'name':'音频模式','taskCode':'VipAudioMode','status':2},{'name':'有财频道','taskCode':'VipFinancialChannel','status':2},{'name':'查看报告','taskCode':'checkReport','status':2},{'name':'发送弹幕','taskCode':'vipBarrage','status':2},{'name':'浏览书库','taskCode':'NovelChannel','status':2},{'name':'百度借钱','taskCode':'1231231231','status':2},{'name':'观影30分钟','taskCode':'WatchVideo60mins','status':2},{'name':'浏览福利','taskCode':'b6e688905d4e7184','status':2},{'name':'看热播榜','taskCode':'a7f02e895ccbf416','status':2},{'name':'邀请摇奖','taskCode':'SHAKE_DRAW','status':2},{'name':'活跃观影','taskCode':'8ba31f70013989a8','status':2},{'name':'完善资料','taskCode':'b5f5b684a194566d','status':2},{'name':'自动续费','taskCode':'acf8adbb5870eb29','status':2},{'name':'加盟i联盟','taskCode':'UnionLead','status':2},{'name':'关注i联盟','taskCode':'UnionWechat','status':2},{'name':'权益答题','taskCode':'RightsTest','status':2},{'name':'关注微信','taskCode':'843376c6b3e2bf00','status':2}]defquery_user_task(self):#获取任务列表及状态0:待领取1:已完成2:未开始4:进行中data={"P00001":self.P00001,"autoSign":"yes"}url=f"https://tc.vip.iqiyi.com/taskCenter/task/queryUserTask?{self.splice(data)}"try:res=requests.get(url)res.raise_for_status()res=res.json()ifres['code']=='A00000':self.tasks=[]fortaskgroupinres['data']['tasks']:#in['daily']:#['actively','daily']:#inres['data']['tasks']:foriteminres['data']['tasks'].get(taskgroup,[]):self.tasks.append({"name":item['name'],"taskCode":item['taskCode'],"status":item['status']})else:self.logbuf.append(f"获取任务列表失败:{res['msg']}")exceptrequests.RequestExceptionase:self.logbuf.append(f"获取任务列表失败:{e}")defjoinTask(self,task):#加入任务data={'taskCode':task['taskCode'],'lang':'zh_CN','platform':'0000000000000000','P00001':self.P00001}url=f"https://tc.vip.iqiyi.com/taskCenter/task/joinTask?{self.splice(data)}"try:res=requests.get(url)res.raise_for_status()res=res.json()ifres.get('code')=='A00000':url=f"https://tc.vip.iqiyi.com/taskCenter/task/notify?{self.splice(data)}"self.logbuf.append(f"开始{task['name']}任务")self.notify(task)else:self.logbuf.append(f"开始{task['name']}任务失败:{res.get('msg','未知错误')}")exceptrequests.RequestExceptionase:self.logbuf.append(f"开始{task['name']}任务失败:{e}")defnotify(self,task):#通知data={'taskCode':task['taskCode'],'lang':'zh_CN','platform':'0000000000000000','P00001':self.P00001}url=f"https://tc.vip.iqiyi.com/taskCenter/task/notify?{self.splice(data)}"try:res=requests.get(url)res.raise_for_status()res=res.json()exceptrequests.RequestExceptionase:self.logbuf.append(f"通知{task['name']}失败:{e}")defgetTaskRewards(self,task):#领取奖励data={'taskCode':task['taskCode'],'lang':'zh_CN','platform':'0000000000000000','P00001':self.P00001}url=f"https://tc.vip.iqiyi.com/taskCenter/task/getTaskRewards?{self.splice(data)}"try:res=requests.get(url)res.raise_for_status()res=res.json()ifres['msg']=="成功":ifres['code']=='A00000':ifres.get('dataNew'):self.logbuf.append(f"{task['name']}已完成:{res['dataNew'][0]['name']}{res['dataNew'][0]['value']}")else:self.logbuf.append(f"{task['name']}任务可能未完成")else:self.logbuf.append(f"{task['name']}任务失败:{res['msg']}")else:self.logbuf.append(f"{task['name']}任务失败:{res['msg']}")exceptrequests.RequestExceptionase:self.logbuf.append(f"{task['name']}任务失败:{e}")defmain(self):self.query_user_task()#获取任务列表fortaskinself.tasks:iftask['status']==2:self.joinTask(task)time.sleep(0.5)time.sleep(10)self.query_user_task()#重新获取任务列表fortaskinself.tasks:iftask['status']==4:self.notify(task)self.query_user_task()#重新获取任务列表fortaskinself.tasks:iftask['status']==0:self.getTaskRewards(task)time.sleep(0.5)iftask['status']==4:self.logbuf.append(f"{task['name']}任务:正在进行中,需要手动完成")iflen(self.logbuf)==1:self.logbuf.append('已全部完成')return'n会员任务-'.join(self.logbuf)classdailyTasks(init):#日常任务def__init__(self,user):init.__init__(self,user)#网页端任务列表self.web_task_list=[{'taskName':'访问热点首页','typeCode':'point','channelCode':'paopao_pcw','limitPerDay':1,'getRewardDayCount':0,'continuousRuleList':None},{'taskName':'每观看视频30分钟','typeCode':'point','channelCode':'view_pcw','limitPerDay':3,'getRewardDayCount':0,'continuousRuleList':None},{'taskName':'观看直播3分钟','typeCode':'point','channelCode':'live_3mins','limitPerDay':1,'getRewardDayCount':0,'continuousRuleList':None},{'taskName':'网页端签到','typeCode':'point','channelCode':'sign_pcw','limitPerDay':1,'getRewardDayCount':0,'continuousRuleList':['yes']}]defwebTaskList(self):#获取网页端任务列表data={'agenttype':'1','agentversion':'0','appKey':'basic_pcw','appver':'0','authCookie':self.P00001,'srcplatform':'1','typeCode':'point','userId':self.P00003,'verticalCode':'iQIYI'}data['sign']=self.splice(data,'UKobMjDMsDoScuWOfp6F')url=f"https://community.iqiyi.com/openApi/task/list?{self.splice(data)}"try:res=requests.get(url)res.raise_for_status()res=res.json()ifres['code']=='A00000':self.web_task_list=[]fortaskinres['data'][0]:iftask['limitPerDay']>0:self.web_task_list.append({'taskName':task['channelName'],'typeCode':task['typeCode'],'channelCode':task['channelCode'],'limitPerDay':task['limitPerDay'],'getRewardDayCount':task['processCount'],'continuousRuleList':task['continuousRuleList']})else:self.logbuf.append(f"获取网页端任务列表失败:{res['message']}")exceptrequests.RequestExceptionase:self.logbuf.append(f"获取网页端任务列表失败:{e}")defwebTask(self,task):#完成网页端任务data={"agenttype":"1","agentversion":"0","appKey":"basic_pca","appver":"0","authCookie":self.P00001,"channelCode":task['channelCode'],"dfp":self.dfp,"scoreType":"1","srcplatform":"1","typeCode":task['typeCode'],"userId":self.P00003,"user_agent":"Mozilla/5.0(WindowsNT10.0;Win64;x64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/96.0.4664.110Safari/537.36","verticalCode":"iQIYI"}data['sign']=self.splice(data,"DO58SzN6ip9nbJ4QkM8H")ifnottask['continuousRuleList']:#如果不是连续任务,需要先完成任务再领取奖励url=f"https://community.iqiyi.com/openApi/task/complete?{self.splice(data)}"#完成任务try:res=requests.get(url)res.raise_for_status()res=res.json()ifres['code']=='A00000':url=f"https://community.iqiyi.com/openApi/score/getReward?{self.splice(data)}"#领取奖励try:res=requests.get(url)res.raise_for_status()res=res.json()ifres['code']=='A00000':self.logbuf.append(f"{task['taskName']}:获得{res['data']['score']}点积分")else:self.logbuf.append(f"{task['taskName']}失败:{res['message']}")exceptrequests.RequestExceptionase:self.logbuf.append(f"{task['taskName']}失败:{e}")else:self.logbuf.append(f"{task['taskName']}失败:{res['message']}")exceptrequests.RequestExceptionase:self.logbuf.append(f"{task['taskName']}失败:{e}")else:url=f"https://community.iqiyi.com/openApi/score/add?{self.splice(data)}"#连续任务try:res=requests.get(url)res.raise_for_status()res=res.json()ifres['code']=='A00000':ifres['data'][0]['code']=='A0000':quantity=res['data'][0]['score']#积分continued=res['data'][0]['continuousValue']#连续签到天数self.logbuf.append(f"{task['taskName']}:获得{quantity}点积分,连续签到{continued}天")else:self.logbuf.append(f"{task['taskName']}失败:{res['data'][0]['message']}")else:self.logbuf.append(f"{task['taskName']}失败:{res['message']}")exceptrequests.RequestExceptionase:self.logbuf.append(f"{task['taskName']}失败:{e}")defmain(self):self.webTaskList()forwebtaskinself.web_task_list:for_inrange(webtask['limitPerDay']-webtask['getRewardDayCount']):self.webTask(webtask)iflen(self.logbuf)==1:self.logbuf.append('已全部完成')return'n日常任务-'.join(self.logbuf)classshake(init):#摇一摇def__init__(self,user,shareUserIds):init.__init__(self,user)self.shareUserIds=shareUserIdsself.myid=""self.isLottery=True#True查询False抽奖defqueryActivityTask(self):#获取摇一摇分享iddata={'P00001':self.P00001,'taskCode':'SHAKE_DRAW','messageId':self.message_id(),'appname':'sharingIncentive','_':round(time.time()*1000)}url=f"https://tc.vip.iqiyi.com/taskCenter/activity/queryActivityTask?{self.splice(data)}"try:res=requests.get(url)res.raise_for_status()res=res.json()ifres['code']=='A00000':self.myid=res['data']['shareUserId']ifres['data']['status']==2:self.logbuf.append("助力id:您已经被助力过了")elifres['data']['status']==6:self.logbuf.append(f"助力id:{self.myid}")else:self.logbuf.append(f"助力id失败:{res['msg']}")exceptrequests.RequestExceptionase:self.logbuf.append(f"助力id失败:{e}")defnotifyActivity(self,shareUserId):#摇一摇助力data={'P00001':self.P00001,'taskCode':'SHAKE_DRAW','messageId':self.message_id(),'appname':'sharingIncentive','shareUid':shareUserId,'_':round(time.time()*1000)}url=f"https://tc.vip.iqiyi.com/taskCenter/activity/notifyActivity?{self.splice(data)}"try:res=requests.get(url)res.raise_for_status()res=res.json()ifres['code']=='A00000':self.logbuf.append(f"助力:{res['msg']}")else:self.logbuf.append(f"助力失败:{res['msg']}")exceptrequests.RequestExceptionase:self.logbuf.append(f"助力失败:{e}")deflottery_activity(self):#摇一摇抽奖data={"app_k":"b398b8ccbaeacca840073a7ee9b7e7e6","app_v":"11.6.5","platform_id":10,"dev_os":"8.0.0","dev_ua":"FRD-AL10","net_sts":1,"qyid":self.qyid,"psp_uid":self.P00003,"psp_cki":self.P00001,"psp_status":3,"secure_p":"GPhone","secure_v":1,"req_sn":round(time.time()*1000)}ifself.isLottery:#查询data["lottery_chance"]=1url=f"https://iface2.iqiyi.com/aggregate/3.0/lottery_activity?{self.splice(data)}"try:res=requests.get(url)res.raise_for_status()res=res.json()ifres['code']==0:ifself.isLottery:#查询self.isLottery=Falsedaysurpluschance=int(res.get('daysurpluschance','0'))ifdaysurpluschance!=0:returndaysurpluschanceself.logbuf.append("抽奖:没有抽奖机会了")else:#抽奖ifres['kv'].get('msg'):self.logbuf.append(f"抽奖:{res['kv']['msg']}")else:ifres['title']=='影片推荐':self.logbuf.append(f"抽奖:未中奖")else:self.logbuf.append(f"抽奖:{res['awardName']}")elifres['code']==3:self.logbuf.append("抽奖失败:Cookie失效")else:self.logbuf.append("抽奖失败:未知错误")exceptrequests.RequestExceptionase:self.logbuf.append(f"抽奖失败:{e}")return0defmain(self):self.queryActivityTask()#获取摇一摇idforshareUserIdinset(self.shareUserIds):ifshareUserId!=''andshareUserId!=self.myid:self.notifyActivity(shareUserId)#摇一摇助力for_inrange(self.lottery_activity()):#查询抽奖次数self.lottery_activity()#抽奖time.sleep(0.5)return'n摇一摇-'.join(self.logbuf)classlotto(init):#抽奖活动类def__init__(self,user):init.__init__(self,user)self.stime=1643340#默认开始时间self.etime=4070880000#默认结束时间self.ntime=round(time.time())#当前时间self.isActivityTime=False#活动时间标志self.giftlist=[]#礼物列表self.actCode=''self.header={"Content-Type":"application/json;charset=UTF-8"}deflotto_giveTimes(self):#访问得次数data={'P00001':self.P00001,'dfp':self.dfp,'qyid':self.qyid,'actCode':self.actCode,'timesCode':'browseWeb'}url=f"https://pcell.iqiyi.com/lotto/giveTimes?{self.splice(data)}"try:res=requests.post(url,headers=self.header)res.raise_for_status()res=res.json()ifres['code']=='A00000':self.logbuf.append("访问任务完成")else:self.logbuf.append(f"访问任务失败:{res['msg']}")exceptrequests.RequestExceptionase:self.logbuf.append(f"访问任务失败:{e}")deflotto_queryTimes(self):#查询抽奖次数data={'P00001':self.P00001,'dfp':self.dfp,'qyid':self.qyid,'actCode':self.actCode}url=f"https://pcell.iqiyi.com/lotto/queryTimes?{self.splice(data)}"try:res=requests.get(url)res.raise_for_status()res=res.json()ifres['code']=='A00000':ifres['data']['times']!=0:returnres['data']['times']else:self.logbuf.append("抽奖:没有抽奖机会了")else:self.logbuf.append(f"查询抽奖次数失败:{res['msg']}")exceptrequests.RequestExceptionase:self.logbuf.append(f"查询抽奖次数失败:{e}")return0deflotto_lottery(self):#抽奖data={'P00001':self.P00001,'dfp':self.dfp,'qyid':self.qyid,'actCode':self.actCode}url=f"https://pcell.iqiyi.com/lotto/lottery?{self.splice(data)}"try:res=requests.post(url,headers=self.header)res.raise_for_status()res=res.json()ifres['code']=='A00000':self.logbuf.append(f"抽奖:{res['data']['giftName']}+{res['data']['sendType']}")else:self.logbuf.append(f"抽奖失败:{res['msg']}")exceptrequests.RequestExceptionase:self.logbuf.append(f"抽奖失败:{e}")defgo_lottery(self):#去抽奖time.sleep(0.5)for_inrange(self.lotto_queryTimes()):self.lotto_lottery()time.sleep(0.5)deflotto_gift_records(self):#查询拥有的礼物data={'P00001':self.P00001,'dfp':self.dfp,'qyid':self.qyid,'actCode':self.actCode,'pageNo':1,'pageSize':200}url=f"https://pcell.iqiyi.com/lotto/gift/records?{self.splice(data)}"try:res=requests.get(url)res.raise_for_status()res=res.json()ifres['code']=='A00000':giftlistbuf=[]forpropinres['data']['records']:propbuf={'giftName':prop['giftName'],'ticket':prop['ticket']}giftlistbuf.append(str(propbuf))giftlist=[]foriteminset(giftlistbuf):gift=eval(item)gift['count']=giftlistbuf.count(item)giftlist.append(gift)self.giftlist=giftlistelse:self.logbuf.append(f"礼物查询失败:{res['msg']}")exceptrequests.RequestExceptionase:self.logbuf.append(f"礼物查询失败:{e}")defactivity_time(self,stime=None,etime=None):#活动时间ifstime!=None:self.stime=time.mktime(time.strptime(stime,"%Y-%m-%d%H:%M:%S"))ifetime!=None:self.etime=time.mktime(time.strptime(etime,"%Y-%m-%d%H:%M:%S"))ifself.ntime>self.stimeandself.ntime<self.etime:self.isActivityTime=True#会员礼遇日classvip_activity(lotto):defvip_gift(self):#礼物查询self.lotto_gift_records()#查询礼物列表ifself.giftlist:buf=['礼物查询:']forgiftinself.giftlist:buf.append(f"--{gift['giftName']}+{gift['count']}")self.logbuf.append('n'.join(buf))else:self.logbuf.append('礼物查询:还没有礼物哟')defmain(self):month=time.strftime("%Y-%m-",time.localtime())self.activity_time(month+'2711:00:00',month+'2823:59:59')#活动时间开始时间结束时间ifself.isActivityTime:self.actCode="825dd6fad636f573"self.lotto_giveTimes()#访问得次数self.go_lottery()#去抽奖self.vip_gift()#查询礼物列表else:self.logbuf.append("每月27/28日,当前不在活动时间内")return'n会员礼遇日-'.join(self.logbuf)'''#虎年春节活动classspring_activity(lotto):def__init__(self,user,uniqueCodes):lotto.__init__(self,user)self.uniqueCodes=uniqueCodesdefspring_go(self,uniqueCode):#去助力data={'P00001':self.P00001,'dfp':self.dfp,'qyid':self.qyid,'source':'spring_act','bizType':1,'uniqueCode':uniqueCode}url=f"https://act.vip.iqiyi.com/up/up?{self.splice(data)}"try:res=requests.post(url,headers=self.header)res.raise_for_status()res=res.json()ifres['code']=='A00000':self.logbuf.append(f"去助力:助力成功")else:self.logbuf.append(f"去助力失败:{res['msg']}")exceptrequests.RequestExceptionase:self.logbuf.append(f"去助力失败:{e}")#获取助力代码defspring_uniqueCode(self):data={'dfp':self.dfp,'qyid':self.qyid,'source':'spring_act','bizType':1,'creatorUid':self.P00003}url=f"https://act.vip.iqiyi.com/up/shareUp?{self.splice(data)}"try:res=requests.post(url,headers=self.header)res.raise_for_status()res=res.json()ifres['code']=='A00000':self.uniqueCodes.append(res['data']['uniqueCode'])self.logbuf.append(f"助力id:{res['data']['uniqueCode']}")else:self.logbuf.append(f"获取助力id失败:{res['msg']}")exceptrequests.RequestExceptionase:self.logbuf.append(f"获取助力id失败:{e}")#助力人数defspring_go_count(self):data={'P00001':self.P00001,'dfp':self.dfp,'qyid':self.qyid,'source':'spring_act','bizType':1,'creatorUid':self.P00003}url=f"https://act.vip.iqiyi.com/up/newUpResult?{self.splice(data)}"try:res=requests.get(url)res.raise_for_status()res=res.json()ifres['code']=='A00000':self.logbuf.append(f"查询助力人数:已有{len(res['data']['details'])}人为你助力")else:self.logbuf.append(f"查询助力人数失败:{res['msg']}")exceptrequests.RequestExceptionase:self.logbuf.append(f"查询助力人数失败:{e}")#礼物查询defspring_gift(self):self.lotto_gift_records()#查询礼物列表ifself.giftlist:buf=[]forgiftinself.giftlist:if'碎片'ingift['giftName']:ifgift['count']<3:num=f"还差{3-gift['count']}个可兑换"else:num="赶快去兑换吧"buf.insert(0,f"n--{gift['giftName']}+{gift['count']},{num}")elif'微信红包封皮'ingift['giftName']:buf.append(f"n--{gift['giftName']}+{gift['count']},兑换码:{gift['ticket']}")else:buf.append(f"n--{gift['giftName']}+{gift['count']}")self.logbuf.append(f"礼物查询:{''.join(buf)}")else:self.logbuf.append("礼物查询:还未获得礼物")defmain(self):self.activity_time('2022-1-2515:00:00','2022-2-323:59:59')#活动时间:开始时间结束时间self.isActivityTime=Trueifself.isActivityTime:self.spring_uniqueCode()#获取助力uniqueCodeforuniqueCodeinset(self.uniqueCodes):iflen(uniqueCode)==64:self.spring_go(uniqueCode)#去助力time.sleep(0.5)self.spring_go_count()#助力你的人数self.actCode="8ac45a59f588f74e"self.lotto_giveTimes()#访问得次数self.go_lottery()#去抽奖self.actCode="8ac45a59f588f74e,a56de295d068a4e5,8b9a024d5e1642a6"self.spring_gift()#查询礼物else:self.logbuf.append("已结束")return'n春节活动-'.join(self.logbuf)'''defmain_handler(event,context):returnmain()if__name__=='__main__':main()


相关文章

    无相关信息
评论
建站知识
建站知识
使用技巧
调试安装
运营推广