这里需要选择一个文件夹 随便 紫色为修改保存 记得ctrl+s保存
注入代码如下
(function() {var ws = new WebSocket("ws://127.0.0.1:8080")ws.onmessage = function(evt) {console.log("收到消息:" + evt.data);if (evt.data == "exit") {wx.close();} else {ws.send(encrypt(evt.data));}}}
)();
python调用代码如下(运行后刷新网页调用)
import sys
import asyncio
import websocketsasync def receive_message(websocket):while True:send_text = input("请输入要加密的字符串:")if send_text == "exit":print("退出!")await websocket.send(send_text)await websocket.close()sys.exit()else:await websocket.send(send_text)response_text = await websocket.recv()print("加密结果:", response_text)start_server = websockets.serve(receive_message, "127.0.0.1", 8080)
asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()