first commit
This commit is contained in:
51
model/McBind.py
Normal file
51
model/McBind.py
Normal file
@@ -0,0 +1,51 @@
|
||||
import requests
|
||||
import json
|
||||
import logging
|
||||
import toml
|
||||
|
||||
class McBind:
|
||||
def __init__(self,qid,code):
|
||||
self.qid = qid
|
||||
self.code = code
|
||||
|
||||
def main(self):
|
||||
with open('./config.toml', 'r', encoding='utf-8') as f:
|
||||
config = toml.load(f)
|
||||
|
||||
# 获取所需字段
|
||||
velocity_ip = config.get("velocity_ip")
|
||||
velocity_port = config.get("velocity_port")
|
||||
velocity_token = config.get("velocity_token")
|
||||
# API URL
|
||||
url = f"http://{velocity_ip}:{velocity_port}/vc/blind" # 替换为实际的 API 地址
|
||||
|
||||
# 请求头
|
||||
headers = {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": velocity_token # 替换为你的 API 密钥
|
||||
}
|
||||
|
||||
# 请求体
|
||||
payload = {
|
||||
"qqID": self.qid,
|
||||
"code": self.code
|
||||
}
|
||||
|
||||
# 发送 POST 请求
|
||||
try:
|
||||
response = requests.post(url, headers=headers, data=json.dumps(payload))
|
||||
|
||||
# 检查响应状态码
|
||||
if response.status_code == 200:
|
||||
return "您已成功绑定MCUNC游戏账户"
|
||||
elif response.status_code == 403:
|
||||
logging.info("授权码不存在或过期")
|
||||
return "授权码不存在或过期"
|
||||
else:
|
||||
logging.error("请求失败!状态码: {response.status_code}")
|
||||
logging.error(f"错误信息: {response.text}") # 打印错误信息
|
||||
return "服务器繁忙,请稍后再逝"
|
||||
|
||||
except Exception as e:
|
||||
logging.error(f"请求过程中出现异常: {e}")
|
||||
return "服务器繁忙,请稍后再逝"
|
||||
Reference in New Issue
Block a user