from hashlib import md5
from urllib import parse
class DglSign(object):
def __init__(self,vendorId,data):
self.vendorId = str(vendorId)
self.data = data
self.get_vendor_id()
self.data_encode()
def my_md5(self,str):
md = md5()
md.update(str.encode())
return md.hexdigest()
def get_vendor_id(self):
first = self.my_md5(self.vendorId)
self.Astr = self.my_md5(first)
def data_encode(self):
self.urlEncodeStr = parse.unquote(self.data)
def get_sign(self):
src = self.Astr + self.urlEncodeStr
sign = self.my_md5(src)
return sign
mysign = DglSign(1697, 'vendorId=1697&posCode=pos006&ip=127.0.0.test1&posVersion=2.test1.167-A2-9A-06-05')
res = mysign.get_sign()
print(res)