直接提供核心源代碼
\# 請求數據處理方法
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