import asyncio import websockets async def connect(): uri = "wss://live-ws.immomo.com/ws/im" async with websockets.connect(uri) as websocket: print(f"链接websocket:[{uri}] 完成") client_time = "1711123627734" momoid = "1062302597" roomid = "15925755150740" token = "b458d6fd04ee38a9e5330e76a3802df9" data = '{{"msg_id":1,"client_time":{0},"type":"Sauth","data":{{"momoid":"{1}","roomid":"{2}","role":6,"isVisitor":false,"token":"{3}","ua":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36"}}}}'.format( client_time, momoid, roomid, token) await websocket.send(data) print("Send Hello") while True: try: response = await websocket.recv() print("收到消息=>" + response) except websockets.exceptions.ConnectionClosedError: print("与服务器断开链接") break async def main(): await connect() asyncio.run(main())