服务器校验

服务器与服务器之间的交互

服务器校验

 

服务器校验
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

 

上一篇:从linux源码看socket的阻塞和非阻塞


下一篇:web框架的本质