0组签到腾讯云函数部署

零组云函数签到

一:腾讯云函数签到

前言:0组公众号发布了一个文库的自动签到脚本

https://github.com/0-Xyao/Zero-box/blob/main/%E6%96%87%E5%BA%93%E7%AD%BE%E5%88%B0%E8%84%9A%E6%9C%AC/auto-check.py

最近从同学的签到打卡脚本中知道了云函数这种东西,可以在腾讯云上定时部署代码,很方便,所以想着改了一下云函数0组签到代码

1:首先先在腾讯云申请云函数,然后登录

img

2:选择python3.6和web静态托管

img

3:把代码复制上去

img

4:高级配置设置超时时间

img

 

5:触发器定时触发就可以了,当然你可以选择每天的签到时间

 

# 触发器设置使用的是cron表达式
# 0 0 6 * * * *
# 表示每天早上6点打卡,如果要改成8点打卡就改成
# 0 0 8 * * * *
# 如果想改其他的,自行使用在线生成器:https://cron.qqe2.com/

img

 

 

img

6:部署测试成功即可

二:代码

1:修改的代码
#!/usr/bin/env python
# -*- coding:utf-8 -*-

import requests
def main_handler(event, context):
    print("Received event: " + json.dumps(event, indent = 2)) 
import base64
import json
import os 

def b64_image(image):
    ##base64转image存储成图片
    strs = image
    imgdata = base64.b64decode(strs)
    file = open('kyxabc.jpg', 'wb')
    file.write(imgdata)
    file.close()

def get_code_uuid():
    ##获取image、UUID值
    code_url = "https://wiki.0-sec.org/api/user/captchaImage"
    code_image = requests.get(code_url)
    json_data = json.loads(code_image.content)
    base64_image = json_data['data']['img']
    base64_uuid = json_data['data']['uuid']
    b64_image(base64_image)

    return base64_uuid

def base64_api():
    #path = os.getcwd()
    img_path = "/tmp/kyxabc.jpg"
    print(img_path)
    with open(img_path, 'rb') as f:
        base64_data = base64.b64encode(f.read())
        b64 = base64_data.decode()
    data = {"username": "打码平台账号", "password": "平台密码", "image": b64}##你的验证码api账户
    result = json.loads(requests.post("http://api.ttshitu.com/base64", json=data).text)
    if result['success']:
        print("验证码识别成功")
        return result["data"]["result"]
    else:
        print("验证码识别抽风了,再执行一遍吧")

def login(uuid):
    username = "文库账号"
    password = "文库密码"
    headers = {'Accept': 'application/json, text/plain, */*','User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36','Content-Type': 'application/json;charset=UTF-8','Accept-Encoding': 'gzip, deflate','Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8'}
    url = "https://wiki.0-sec.org/api/user/login"
    login_data = {"account":username,"password":password,"code":base64_api(),"uuid":uuid}##字典
    data_json = json.dumps(login_data)##转json格式
    logins = requests.post(url=url,headers=headers,data=data_json)
    token = json.loads(logins.content)['data']['token']

    return token

def sign(token):
    headers = {'Zero-Token':token}
    url = "https://wiki.0-sec.org/api/profile"
    old_sign_data_json = requests.get(url=url,headers=headers)
    old_sign_data_credit = json.loads(old_sign_data_json.content)['data']['credit']

    url1 = "https://wiki.0-sec.org/api/front/user/sign"
    requests.post(url=url1, headers=headers)

    new_sign_data_json = requests.get(url=url, headers=headers)
    new_sign_data_credit = json.loads(new_sign_data_json.content)['data']['credit']

    if new_sign_data_credit > old_sign_data_credit:
        print("签到成功,您的当前积分为:",new_sign_data_credit)
    else:
        print("兄弟,你已经签到过了,你的积分为:",new_sign_data_credit)

def main_handler(event, context):
    main()

def main():
    uuid = get_code_uuid()
    tokens = login(uuid)
    sign(tokens)


if __name__ == '__main__':
    main_handler("","")







2:注意的几点

(1):云函数的写空间在/tmp,所以需要注意生成的图片文件需要的放在/tmp才能够进行读写

img

(2):云函数的函数格式有一定的要求,需要遵循官方文档来操作

img

(3):api账号识别次数需要购买,500次一元.可以签到一年了0.0.

(4):注意固定公网ip

 

 

三:参考博客:

官方文档:

https://cloud.tencent.com/document/product/583

https://zhuanlan.zhihu.com/p/145865033

 

 

 



去留无意,宠辱不惊