- 注册时间
- 2017-4-7
- 最后登录
- 2017-6-23
- 回帖
- 2
- 主题
- 113
- 精华
- 2
- 金币
- 293
- 威望
- 0
- 股份
- 0
- 热心值
- 1
- 积分
- 307
宝藏初中生
- 回帖
- 2
- 金币
- 293
- 威望
- 0
- 积分
- 307
- 股份
- 0
- 热心值
- 1
- 宝藏币
- 0
|
将以下代码按注释复制进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()) |
|