青龙面板一些公用方法的封装……
封装了青龙版面的一些方法:
get_token():获取token;
match_ck():比对ck进行更新,如果未启用,进行启用;
get_all_ck():获取青龙面板的所有变量(ck);
update_ck():更新青龙面板的单个变量(ck);
add_ck():添加变量(ck);
start_ck():启用变量(ck);
[Python] 纯文本查看 复制代码
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
#更新到青龙面板 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] 纯文本查看 复制代码
1
2
3
4
5
6
|
if __name__ = = '__main__' : ck = 'pt_key=33JiC5lOADBAJIqAX8UDhNHkh_qypfyAyQkqWu5ADdZgHkudbNtdlSkBEOIMxO73oT_npf__Hvc;pt_pin=jd_67r828540e7yd;' 如果知道手机号码,可以传phone作为标记,不然账号太多会比较乱 Update(ck = ck).match_ck() |