服务器与服务器之间的交互
import os import socket import hmac key = '芝麻开门' def auth(x,y): hm = hmac.new(x,y) res = hm.hexdigest() return res sk = socket.socket() sk.bind(('127.0.0.1',9000)) sk.listen() conn,addr = sk.accept() msg = os.urandom(32) conn.send(msg) res = conn.recv(32).decode('utf8') res_local = auth(key.encode('utf8'),msg) if res == res_local: msg = '接入支付接口!' conn.send(msg.encode('utf8'))server_ali
import socket import hmac key = '芝麻开门' def auth(x,y): hm = hmac.new(x,y) res = hm.hexdigest() return res sk = socket.socket() sk.connect(('127.0.0.1',9000)) msg = sk.recv(32) res = auth(key.encode('utf8'),msg) sk.send(res.encode('utf8')) msg = sk.recv(1024) print(msg.decode('utf8'))server_pc