upload
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
import json
|
||||
import websockets
|
||||
import asyncio
|
||||
#
|
||||
# async def py_client(datas,client_id):
|
||||
# # uri = "ws://localhost:5001"
|
||||
# uri = "wss://mtworker.tech:5003/"
|
||||
#
|
||||
# async with websockets.connect(uri) as websocket:
|
||||
# # 发送客户端ID
|
||||
# client_id2 = client_id+'_pc'
|
||||
# await websocket.send(client_id2)
|
||||
# target_client_id = client_id+"_web"
|
||||
#
|
||||
# msg = f"{target_client_id}: {datas}"
|
||||
# # 发送消息
|
||||
# await websocket.send(msg)
|
||||
#
|
||||
# # 接收响应
|
||||
# response = await websocket.recv()
|
||||
# print(f"Received: {response}")
|
||||
#
|
||||
# # 关闭连接
|
||||
# await websocket.close()
|
||||
# return response
|
||||
#
|
||||
# def get_mtg(datas,dfpid):
|
||||
# kkk = asyncio.get_event_loop().run_until_complete(py_client(json.dumps(datas), dfpid))
|
||||
# # kkk = py_client_sync(datas,dfpid)
|
||||
# data = json.loads(kkk)
|
||||
# return data
|
||||
|
||||
import asyncio
|
||||
import websockets
|
||||
import json
|
||||
|
||||
async def py_client(datas, client_id):
|
||||
uri = "wss://mtworker.tech:5003/"
|
||||
async with websockets.connect(uri) as websocket:
|
||||
# 发送客户端ID
|
||||
client_id2 = client_id + '_pc'
|
||||
await websocket.send(client_id2)
|
||||
target_client_id = client_id + "_web"
|
||||
|
||||
msg = f"{target_client_id}: {datas}"
|
||||
# 发送消息
|
||||
await websocket.send(msg)
|
||||
|
||||
# 接收响应
|
||||
response = await websocket.recv()
|
||||
print(f"Received: {response}")
|
||||
|
||||
# 关闭连接
|
||||
await websocket.close()
|
||||
return response
|
||||
|
||||
def get_mtg(datas, dfpid):
|
||||
try:
|
||||
loop = asyncio.get_event_loop()
|
||||
except RuntimeError:
|
||||
# 如果没有事件循环,则创建一个新的
|
||||
loop = asyncio.new_event_loop()
|
||||
asyncio.set_event_loop(loop)
|
||||
kkk = loop.run_until_complete(py_client(json.dumps(datas), dfpid))
|
||||
data = json.loads(kkk)
|
||||
return data
|
||||
|
||||
def get_sign_wss(url, data33,dfpid):
|
||||
daa = {'cache': False, 'dataType': 'json', 'url': url, 'type': 'POST', 'doNotShowToastr': True, 'data': data33,
|
||||
'observe': {'key': 'code', 'expect': [0, -401]}, 'context': None, 'global': True,
|
||||
'accepts': {'script': 'text/javascript, application/javascript, application/x-javascript',
|
||||
'json': 'application/json', 'xml': 'application/xml, text/xml', 'html': 'text/html',
|
||||
'text': 'text/plain'}, 'crossDomain': True, 'timeout': 0, 'processData': True,
|
||||
'method': 'POST'}
|
||||
|
||||
datas = {
|
||||
"group": "mtgsig1",
|
||||
"action": "mtgsig1",
|
||||
"datas": json.dumps(daa),
|
||||
|
||||
}
|
||||
mt = get_mtg(datas,dfpid)
|
||||
print(type(mt))
|
||||
cookie , userAgent , mtgsig = mt['cookie'],mt['userAgent'],mt['mtgsig']
|
||||
print(cookie)
|
||||
print(userAgent)
|
||||
print(mtgsig['headers']['mtgsig'])
|
||||
# return cookie , userAgent , mtgsig['headers']['mtgsig']
|
||||
return mtgsig['headers']['mtgsig']
|
||||
Reference in New Issue
Block a user