# Python自动签到

**URL:** <https://forum.rainyun.com/t/topic/7221>\
**Category:** 软件分享\
**Created:** [2024 年3 月 14 日 15:11 UTC](https://forum.rainyun.com/t/topic/7221 "2024-03-14T15:11:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

作者： ![3067510479](https://forum.rainyun.com/user_avatar/forum.rainyun.com/3067510479/32/9880_2.png) [@3067510479](https://forum.rainyun.com/u/3067510479)\
发布日期： [2024 年3 月 14 日 15:11 UTC](https://forum.rainyun.com/t/topic/7221/1 "2024-03-14T15:11:46Z")

</div>

这段代码是一个用于实现Rainyun网站自动签到功能的简单Python程序。通过使用tkinter库创建了一个用户友好的GUI界面，让用户可以轻松输入他们的API Key并进行手动签到操作。同时，程序还提供了每天定时自动签到的功能，确保用户不会错过每日的签到奖励。  
 ![image](https://forum.rainyun.com/uploads/default/original/2X/5/50293335836520dc3cca48312436ae90a5e12df8.png)

```auto
import tkinter as tk
from tkinter import messagebox
import requests
import schedule

def sign_in(api_key):
    url = "https://api.v2.rainyun.com/user/reward/tasks"
    data = {"task_name": "每日签到"}
    headers = {
        "x-api-key": api_key,
        "User-Agent": "curl",
        "Content-Type": "application/json",
        "Accept": "*/*",
        "Cache-Control": "no-cache",
        "Host": "api.v2.rainyun.com",
        "Accept-Encoding": "gzip, deflate, br",
        "Connection": "keep-alive"
    }

    response = requests.post(url, json=data, headers=headers)
    if response.status_code == 200:
        messagebox.showinfo("签到成功", "签到成功！")
    else:
        messagebox.showerror("签到失败", "签到失败，请重试！")

def save_api_key(api_key_entry):
    api_key = api_key_entry.get()
    with open("api_key.txt", 'w') as file:
        file.write(api_key)
    messagebox.showinfo("保存成功", "API Key 已保存！")

def read_api_key_from_file(file_path, api_key_entry):
    try:
        with open(file_path, 'r') as file:
            api_key = file.read().strip()
            api_key_entry.insert(0, api_key)
    except FileNotFoundError:
        messagebox.showerror("错误", "找不到API Key文件！")

def on_submit(api_key_entry):
    api_key = api_key_entry.get()
    sign_in(api_key)
    # 设置每天自动签到定时器
    schedule.every().day.at("08:00:00").do(sign_in, api_key)

# 创建 GUI 界面
root = tk.Tk()
root.title("Rainyun 自动签到")
root.geometry("400x200")

api_key_label = tk.Label(root, text="API Key:")
api_key_label.pack()

api_key_entry = tk.Entry(root, width=40)
api_key_entry.pack()

save_button = tk.Button(root, text="保存", command=lambda: save_api_key(api_key_entry))
save_button.pack()

read_api_key_from_file("api_key.txt", api_key_entry)

submit_button = tk.Button(root, text="签到", command=lambda: on_submit(api_key_entry))
submit_button.pack()

root.mainloop()

```

主要特点和优势包括：

1. **用户友好界面：** 使用tkinter库创建GUI界面，让用户可以直观地进行操作。
2. **自动化签到：** 提供每天定时自动签到的功能，节省用户的时间和精力。
3. **简洁高效：** 代码结构清晰简洁，易于理解和修改。
4. **网络请求处理：** 使用requests库处理HTTP请求，确保与Rainyun网站的通信顺畅可靠。
5. **定时任务调度：** 使用schedule库实现定时任务调度，保证每天在指定时间自动执行签到操作。

推广时可以强调该程序能够帮助用户简化每日签到流程，提高效率，同时提供了定时自动签到功能，让用户无需手动干预即可获得签到奖励。适合那些希望节省时间又想获取网站签到奖励的用户使用。

您可以将其推广为一款方便实用的工具，吸引用户体验和时间管理等方面的需求。希望这个介绍对您有帮助，如有任何其他问题或需要进一步帮助，请随时告诉我。

---

<div class="post-metadata">

作者： ![3067510479](https://forum.rainyun.com/user_avatar/forum.rainyun.com/3067510479/32/9880_2.png) [@3067510479](https://forum.rainyun.com/u/3067510479)\
发布日期： [2024 年3 月 15 日 15:01 UTC](https://forum.rainyun.com/t/topic/7221/2 "2024-03-15T15:01:32Z")

</div>

更新了记录key

---

<div class="post-metadata">

作者： ![3067510479](https://forum.rainyun.com/user_avatar/forum.rainyun.com/3067510479/32/9880_2.png) [@3067510479](https://forum.rainyun.com/u/3067510479)\
发布日期： [2024 年3 月 15 日 15:17 UTC](https://forum.rainyun.com/t/topic/7221/3 "2024-03-15T15:17:58Z")

</div>

import tkinter as tk  
from tkinter import messagebox  
import requests  
import schedule

def sign\_in(api\_key):  
url = “[https://api.v2.rainyun.com/user/reward/tasks](https://api.v2.rainyun.com/user/reward/tasks)”  
data = {“task\_name”: “每日签到”}  
headers = {  
“x-api-key”: api\_key,  
“User-Agent”: “curl”,  
“Content-Type”: “application/json”,  
“Accept”: “_/_”,  
“Cache-Control”: “no-cache”,  
“Host”: “[api.v2.rainyun.com](http://api.v2.rainyun.com)”,  
“Accept-Encoding”: “gzip, deflate, br”,  
“Connection”: “keep-alive”  
}

```
response = requests.post(url, json=data, headers=headers)
if response.status_code == 200:
    messagebox.showinfo("签到成功", "签到成功！")
else:
    messagebox.showerror("签到失败", "签到失败，请重试！")

```

def save\_api\_key(api\_key\_entry):  
api\_key = api\_key\_entry.get()  
with open(“api\_key.txt”, ‘w’) as file:  
file.write(api\_key)  
messagebox.showinfo(“保存成功”, “API Key 已保存！”)

def read\_api\_key\_from\_file(file\_path, api\_key\_entry):  
try:  
with open(file\_path, ‘r’) as file:  
api\_key = file.read().strip()  
api\_key\_entry.insert(0, api\_key)  
except FileNotFoundError:  
messagebox.showerror(“错误”, “找不到API Key文件！”)

def on\_submit(api\_key\_entry):  
api\_key = api\_key\_entry.get()  
sign\_in(api\_key)

# 创建 GUI 界面

root = tk.Tk()  
root.title(“Rainyun 自动签到”)  
root.geometry(“400x200”)

api\_key\_label = tk.Label(root, text=“API Key:”)  
api\_key\_label.pack()

api\_key\_entry = tk.Entry(root, width=40)  
api\_key\_entry.pack()

save\_button = tk.Button(root, text=“保存”, command=lambda: save\_api\_key(api\_key\_entry))  
save\_button.pack()

read\_api\_key\_from\_file(“api\_key.txt”, api\_key\_entry)

submit\_button = tk.Button(root, text=“签到”, command=lambda: on\_submit(api\_key\_entry))  
submit\_button.pack()

root.mainloop()

---

<div class="post-metadata">

作者： ![luyii](https://forum.rainyun.com/user_avatar/forum.rainyun.com/luyii/32/5047_2.png) [@luyii](https://forum.rainyun.com/u/luyii)\
发布日期： [2024 年3 月 16 日 02:17 UTC](https://forum.rainyun.com/t/topic/7221/4 "2024-03-16T02:17:57Z")

</div>

建议托管GitHub或gitee再发链接，直接扔代码未必有些太粗暴力

---

<div class="post-metadata">

作者： ![3067510479](https://forum.rainyun.com/user_avatar/forum.rainyun.com/3067510479/32/9880_2.png) [@3067510479](https://forum.rainyun.com/u/3067510479)\
发布日期： [2024 年3 月 16 日 06:40 UTC](https://forum.rainyun.com/t/topic/7221/5 "2024-03-16T06:40:25Z")

</div>

没有账号。
