直接提供核心源代码
\# 请求数据处理方法
def before\_reqData(shipperCode, logisticCode):
"""请求报文"""
frs_reqData = { "OrderCode": "", # 可为空
"ShipperCode": shipperCode, "LogisticCode": logisticCode }
\# 数据转换为json格式
data = json.dumps(frs\_reqData)
\# 进行url编码
\# 替换内容
reqData = quote(data).replace("%20%", "%")
return reqData
def data\_sign(shipperCode, logisticCode):
"""签名datasign"""
frs\_reqData = { 'OrderCode': '', 'ShipperCode': shipperCode, 'LogisticCode': logisticCode }
APIKey = "554343b2-7252-439b-b4eb-1af42c8f2175";
//APIKey申请地址:http://kdniao.com/
\# 请求内容(未编码) + APIKey
\# MD5加密前去除空格
data = json.dumps(frs\_reqData).replace(": ", ":").replace(", ", ",") + APIKey
\# md5加密
sign\_md5 = hashlib.md5(data.encode("utf-8")).hexdigest()
\# Base64编码
data\_sign = base64.b64encode(sign\_md5.encode("utf-8")).decode("utf-8")
return data\_sign