import socket nextcloud = '/var/snap/nextcloud/common/nextcloud/data/zymwin/files' def send_message(msg_type,id,msg): client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) ip = '127.0.0.1' client.connect((ip, 5700)) #将msg中特殊字符进行url编码 msg = msg.replace(" ", "%20") msg = msg.replace("\n", "%0a") if msg_type == 'group': payload = "GET /send_group_msg?group_id=" \ + str(id) + "&message=" + msg + " HTTP/1.1\r\nHost:" \ + ip + ":5700\r\nConnection: close\r\n\r\n" elif msg_type == 'private': payload = "GET /send_private_msg?user_id=" \ + str(id) + "&message=" + msg + " HTTP/1.1\r\nHost:" \ + ip + ":5700\r\nConnection: close\r\n\r\n" print("发送" + payload) client.send(payload.encode("utf-8")) client.close() return 0 def upload_file(msg_type,id,file,name): client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) ip = '127.0.0.1' client.connect((ip, 5700)) #将msg中特殊字符进行url编码 file = file.replace(" ", "%20") file = file.replace("\n", "%0a") if msg_type == 'group': payload = "GET /upload_group_file?group_id=" \ + str(id) + "&file=" + file + "&name=" + name + " HTTP/1.1\r\nHost:" \ + ip + ":5700\r\nConnection: close\r\n\r\n" elif msg_type == 'private': payload = "GET /upload_private_file?user_id=" \ + str(id) + "&file=" + file + " HTTP/1.1\r\nHost:" \ + ip + ":5700\r\nConnection: close\r\n\r\n" print("发送" + payload) client.send(payload.encode("utf-8")) client.close() return 0