#-*-coding:utf8;-*-
#qpy:console
import asyncio
import websockets as ws
import json
from websockets import ConnectionClosed
async def hello():
uri = "ws://127.0.0.1:6700"
while True:
try:
async with ws.connect(uri) as websocket:
await websocket.send(json.dumps({
"echo":"11111","action":"send_group_msg","params":{
"group_id":588093810,"message":"Hello你好"}}))
while True:
try:
data = await websocket.recv()
print(json.loads(data))
#await websocket.send(json.dumps({"echo":"11111","action":"send_group_msg","params":{"group_id":5880938010,"message":"Hello"}}))
if "12580" in data:
await websocket.send(json.dumps({
"echo":"11111","action":"send_group_msg","params":{
"group_id":5880938010,"message":"Hello你好"}}))
print(""+data)
except ConnectionClosed as e:
print(e.code)
break
except:
pass
if __name__=="__main__":
asyncio.get_event_loop().run_until_complete(hello())