from urllib.parse import urlencode
from urllib.request import Request, urlopen
import hashlib
import base64

company_id='your_company_id'
digest_key='your_key'
url = 'http://japi.zto.cn/traceInterfaceNewTraces'
post_fields = {'company_id': company_id,'data':'["728350000001"]','msg_type':'NEW_TRACES'}

str_to_digest = ''
for key, value in post_fields.items():
  str_to_digest+=(key+'='+value+'&')
str_to_digest = str_to_digest[:-1] + digest_key

m = hashlib.md5()
m.update(str_to_digest.encode("UTF-8"))

data_digest=base64.b64encode(m.digest())

request = Request(url, urlencode(post_fields).encode())
request.add_header('x-companyid',company_id)
request.add_header('x-datadigest',data_digest)
json = urlopen(request).read().decode()
print(json)

results matching ""

    No results matching ""