999宝藏网

 找回密码
 

QQ登录

只需一步,快速开始

  • 1278阅读
  • 0回复

[经验分享] python签到打卡云函数——联想社区

[复制链接]

113

主题

2

回帖

307

积分

宝藏初中生

Rank: 5Rank: 5

回帖
2
金币
293
威望
0
积分
307
股份
0
热心值
1
宝藏币
0
发表于 2020-7-8 22:34:52 | 显示全部楼层 |阅读模式
将以下代码按注释复制进SCF云函数中,并修改相应内容即可。PS:看到好多小伙伴不知道获取哪里的cookie,故更新一下帖子(务必在该网址登录联想账号后再获取,同时联想社区账号一定要先绑定手机号,否则可能会提示出错)

PPS:Python3.6模板,超时时间应大于5s
[Python] 纯文本查看 复制代码# -*- coding: utf-8 -*-import configparserimport requestsimport randomimport jsonimport reimport timeimport pytzimport datetime# Python3.6模板,联想社区签到SCF-Cookie版,超时时间应大于5s# 20200618 添加并修复签到失败提醒,添加积分200以下的任务操作# 请依次修改 25、157 行中的需要修改的部分内容# Forked from "https://github.com/gxitm/Autocheckin"# 判断页面是否登陆正确返回jsondef is_json(myjson):    try:        json_object = json.loads(myjson)    except ValueError:        return False    return Truedef doCheckin():    myCookie = '*********复制Cookie进来*************(保留引号)'    if '复制Cookie' in myCookie:        print('获取Cookie失败')        return '获取Cookie失败\n\n---\n\n'    url_signlist = 'https://club.lenovo.com.cn/signlist'    url_checkin = 'https://club.lenovo.com.cn/sign'    url_joinchallenge = 'https://club.lenovo.com.cn/joinchallengetask'    signlist = {        'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',        'accept-encoding': 'gzip, deflate, br',        'accept-language': 'zh-CN,zh;q=0.9',        'cache-control': 'max-age=0',        'cookie': myCookie,        'referer': 'https://club.lenovo.com.cn/thread-1814833-1-1.html',        'upgrade-insecure-requests': '1',        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36'    }    headers = {        'accept': 'application/json, text/javascript, */*; q=0.01',        'accept-encoding': 'gzip, deflate, br',        'accept-language': 'zh-CN,zh;q=0.9',        'content-length': '47',        'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',        'cookie': myCookie,        'origin': 'https://club.lenovo.com.cn',        'referer': 'https://club.lenovo.com.cn/signlist',        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36',        'x-requested-with': 'XMLHttpRequest'    }    #headersdata=json.dumps(headers)  # 如遇特殊符号(:authority: club.lenovo.com.cn,:scheme: https) 需字典数据转为json,需要使用json.dumps    session = requests.session()    response_signlist = session.get(url_signlist,headers=signlist,verify=True)    token_utf8 = response_signlist.content.decode("utf-8")    result_token = re.search('CONFIG.token\s=\s"\w{40}',token_utf8) #获取随机token    if not result_token :        return '获取随机Token失败\n\n---\n\n'    myToken = result_token.group()[-40:]    #获取用户id用于打印用户名及用户id    result_userid = re.search('lenovoid":\d{11}',token_utf8)    if not result_userid :        return '获取用户ID失败\n\n---\n\n'    myId = result_userid.group()[-11:]    callbackParam1 = 'jQuery183048434872539258844_' + str(int(round(time.time() * 1000)))    callbackParam2 = str(int(round(time.time() * 1000)))    url_userinfo = 'https://i.lenovo.com.cn/mcenter/getUserNameAndUserLevel.jhtml?lenovoId=' + myId + '&sts=e40e7004-4c8a-4963-8564-31271a8337d8&callback=' + callbackParam1 + '&_=' + callbackParam2    response_userinfo = session.get(url_userinfo,headers=signlist,verify=True)    result_userinfo = json.loads(response_userinfo.text.replace(callbackParam1, '')[1:-1])    response_signlist = session.get(url_signlist, headers=signlist, verify=True)    token_utf8 = response_signlist.content.decode("utf-8")    data = {        '_token': myToken        }    div = re.search('id="coins">(\d+) 50:        if coin (\d+)进行中.{1,5}',token_utf8)            taskcontinue = result_taskcontinue.group()[-5:]        else:            result_taskcontinue = re.search('class="signInLiBottom">进行中.{1,4}',token_utf8)            taskcontinue = result_taskcontinue.group()[-4:]        cday = re.search('class="signInLiBottom">进行中.*/(\d+)
',token_utf8)        cday = cday.group(1)        if ( 'code' in result_joinchallenge):            dd = ("参加" + cday + "日连续签到挑战成功" + taskcontinue + '\n\n' + '当前积分:'+ str(curcoin))        else:            dd = (cday + "日连续签到挑战进行中" + taskcontinue + '\n\n' + '当前积分:'+ str(curcoin))    else:        result_taskcontinue = re.search('class="signInLiBottom">进行中 (.*)进行中.*/(\d+)
',token_utf8)            cday = cday.group(1)            taskcontinue = result_taskcontinue.group(1)            dd = (cday + "日连续签到挑战进行中" + taskcontinue + '\n\n' + '当前积分:'+ str(coin))        else:            dd = ("积分不足,暂不参加连续签到挑战任务" + '\n\n' + '当前积分:'+ str(coin))    response = session.post(url_checkin, headers=headers, data=data) #json=headers 转为json解决headers特殊符号':authority': 'club.lenovo.com.cn',':path': '/sign',':scheme': 'https',    result = response.content.decode("unicode_escape")# unicode编码转换为汉字    result0 = 0    try:        result_checkin = json.loads(result)        if result_checkin['code'] == 100000 :            print('用户名:'+ str(result_userinfo['data']['username']))            print('用户id:'+ myId)            print('签到成功,本次获得' + str(result_checkin['data']['data']['add_yb_tip']))            print('已持续签到' + str(result_checkin['data']['signCal']['continue_count']) + '天')            print('已累计获得延保' + str(result_checkin['data']['signCal']['user_yanbao_score']) + '天')            print(dd)            result0 = '\n\n用户名:'+ str(result_userinfo['data']['username']) + '\n\n' + '用户id:'+ myId + '\n\n' + '签到成功,本次获得' + str(result_checkin['data']['data']['add_yb_tip']) + '\n\n' + '已持续签到' + str(result_checkin['data']['signCal']['continue_count']) + '天' + '\n\n' + '已累计获得延保' + str(result_checkin['data']['signCal']['user_yanbao_score']) + '天\n\n' + dd + '\n\n---\n\n'        elif result_checkin['code'] == 100001 :            print('用户名:'+ str(result_userinfo['data']['username']))            print('用户id:'+ myId)            print(str(result_checkin['msg']))            result0 = '\n\n用户名:'+ str(result_userinfo['data']['username']) + '\n\n' + '用户id:'+ myId + '\n\n' + str(result_checkin['msg'] + '\n\n' + dd + '\n\n---\n\n')        else:            print ('签到失败')            result0 = '签到失败\n\n---\n\n'    except ValueError:        print ('网页打开失败,非json')        result0 = '网页打开失败,非json\n\n---\n\n'    return result0def pushWechat(desp):    SCKEY = '*********复制SERVER酱的SCKEY进来*************(保留引号)'    ssckey = SCKEY    if '复制SERVER' in ssckey:        print('请重新设置SERVER酱的SCKEY')        return    tz = pytz.timezone('Asia/Shanghai')    send_url='https://sc.ftqq.com/' + ssckey + '.send'    if '失败' in desp :        params = {            'text': '联想社区签到失败提醒' + datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S"),            'desp': desp            }    else:        params = {            'text': '联想社区签到提醒' + datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S"),            'desp': desp            }    requests.post(send_url,params=params)def main_handler(event, context):  return pushWechat(doCheckin())if __name__ == "__main__":    pushWechat(doCheckin())

1.发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;微笑

2.如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;微笑

3.如何回报帮助你解决问题的坛友,一个好办法就是给对方加【热心】和【金币】加分不会扣除自己的积分,做一个热心并受欢迎的人!微笑

回复

使用道具 举报

快速回复
您需要登录后才可以回帖 登录 | 立即加入

本版积分规则

返回列表

|999宝藏网|sitemap|手机版|举报|申请友情链接|  

免责声明:

拒绝任何人以任何形式在本论坛发表与中华人民共和国法律相抵触的言论,本站内容均为会员发表,并不代表999宝藏网立场!

999宝藏网论坛所发布的一切破解软件和补丁、注册机以及注册信息,仅限用于学习和研究目的。不得将上述内容用于商业或者非法途径!否则,一切后果请用户自负!

我们不生产软件,我们只是互联网上的搬运工,本站信息来自互联网,版权争议与本站无关,如果您喜欢该程序,请购买注册正版软件,获得正版优质服务!

请重视此声明,法律不容忽视!请支持正版,尊重版权!本站如有信息侵犯了您的权益,请联系:www@rin99.com及时删除!

Powered by Discuz! © 2001-2024 Comsenz Inc. (豫ICP备2021033223号) 备案图标 豫公网安备41142602000006号

Copyright © 2016-2024 999宝藏网 版权所有 All Rights Reserved.

GMT+8, 2024-3-29 03:29 , Processed in 0.101810 second(s), 33 queries .

快速回复 返回顶部 返回列表