本帖最后由 Fujj 于 2022-4-6 09:03 编辑
封装了青龙版面的一些方法:
get_token():获取token;
match_ck():比对ck进行更新,如果未启用,进行启用;
get_all_ck():获取青龙面板的所有变量(ck);
update_ck():更新青龙面板的单个变量(ck);
add_ck():添加变量(ck);
start_ck():启用变量(ck);
[Python] 纯文本查看 复制代码
#更新到青龙面板
import requests
import json
import re
import time
import configparser
class Update():
def __init__(self,ck=None,phone=None):
#青龙面板地址、账号密码
conf = configparser.ConfigParser()
conf.read("./config.ini", encoding='UTF-8')
self.host = conf["ql"].get('host')
self.client_id = conf["ql"].get('client_id')
self.client_secret = conf["ql"].get('client_secret')
self.ck = ck
self.token = self.get_token()
self.phone = phone
def get_token(self):
url = self.host + "open/auth/token?client_id={}&client_secret={}".format(self.client_id,self.client_secret)
response = requests.request("GET", url).json()
print("获取青龙面板的token:",response)
return response["data"]["token"]
# 比对ck进行更新,如果未启用,进行启用
def match_ck(self):
pt_pin = str(re.findall(r"pt_pin=(.+?);", self.ck)[0])
print("手机号码{}的pt_pin:".format(self.phone),pt_pin)
cklist = self.get_all_ck()
for i in cklist:
if pt_pin in str(i["value"]):
print("匹配成功,匹配到当前变量:",i)
id = i["_id"]
remark = i["remarks"]
print("-------------------")
print("开始更新{}的ck".format(remark))
self.update_ck(remark,id)
if i["status"] == 1:
print("{}启用成功".format(remark))
self.start_ck(id)
return
self.add_ck()
print("新增{}手机号码的ck".format(self.phone))
return
# 获取所有的变量
def get_all_ck(self):
t = int(round(time.time() * 1000))
url = self.host + "open/envs?searchValue=&t="+str(t)
payload = ""
headers = {
'Authorization': 'Bearer '+self.token
}
response = requests.request("GET", url, headers=headers, data=payload).json()
print("获取青龙面板所有的变量进行比对")
return response["data"]
# 更新变量
def update_ck(self,remark=None,id=None):
t = int(round(time.time() * 1000))
url = self.host+"open/envs?t="+str(t)
payload = json.dumps({
"name": "JD_COOKIE",
"value": self.ck,
"remarks": remark,
"_id": id
})
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer '+self.token
}
print("更新变量")
response = requests.request("PUT", url, headers=headers, data=payload)
return
def add_ck(self):
t = int(round(time.time() * 1000))
url = self.host+"open/envs?t="+str(t)
payload = json.dumps([
{
"value": self.ck,
"name": "JD_COOKIE",
"remarks": self.phone
}
])
headers = {
'Authorization': 'Bearer '+self.token,
'Content-Type': 'application/json'
}
print("添加变量")
response = requests.request("POST", url, headers=headers, data=payload)
return
def start_ck(self,id):
t = int(round(time.time() * 1000))
url = self.host+"open/envs/enable?t="+str(t)
print(id)
list=[]
list.append(id)
payload = json.dumps(
list
)
headers = {
'Authorization': 'Bearer '+self.token,
'Content-Type': 'application/json'
}
print("启用ck:",payload)
response = requests.request("PUT", url, headers=headers, data=payload)
return
使用方法:
[Python] 纯文本查看 复制代码 if __name__ == '__main__':
ck = 'pt_key=33JiC5lOADBAJIqAX8UDhNHkh_qypfyAyQkqWu5ADdZgHkudbNtdlSkBEOIMxO73oT_npf__Hvc;pt_pin=jd_67r828540e7yd;'
如果知道手机号码,可以传phone作为标记,不然账号太多会比较乱
Update(ck=ck).match_ck()
归档.zip
(2.14 KB, 下载次数: 66)
|