自研系统对接京东宙斯平台JOS网址:http://jos.jd.com/
对接青龙系统对外开放接口:AppKey AppSecret 需要去开放平台申请 才能获取到
通过code获取access_token:
https://open-oauth.jd.com/oauth2/access_token?app_key= XXXXX &app_secret= XXXXX &grant_type=authorization_code&code= XXXXX
详细介绍可以查看:
https://jos.jd.com/commondoc?listId=306
下面展示一些 内联代码片
。
import hashlib
import json
import pymysql
import requests
import smtplib
import datetime
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
TimeStamp = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
AppKey='###'
AppSecret='###'
token='###' #token 需要去京东授权才能拿到
def JDlog(lpid):
buy_param_json={
"customerCode":"021K***",#注册的时候会有商家编码
"waybillCode":lpid
}
buy_param_json_string = json.dumps(buy_param_json)
#print(buy_param_json_string)
#print(buy_param_json.get('waybillCode'))
access_token=token
app_key=AppKey
method='jingdong.ldop.receive.trace.get'
timestamp=TimeStamp
v=2.0
param = AppSecret+'360buy_param_json'+buy_param_json_string+'access_token'+access_token+'app_key'+app_key+'method'+method+'timestamp'+timestamp+'v'+str(v)+AppSecret
sign_md5 = hashlib.md5(str(param).encode("utf-8")).hexdigest().upper() #MD5加密
#print(sign_md5)
data_value = []
url = 'https://api.jd.com/routerjson'
Params = {
'access_token':token,
'app_key':AppKey,
'method':'jingdong.ldop.receive.trace.get',
'v':'2.0',
'sign':sign_md5,
'360buy_param_json':buy_param_json_string,
'timestamp':TimeStamp
}
r = requests.post(url, data=Params)
#print(r.text)
if list(r.json().keys())[0] == 'error_response' :
if r.json()["error_response"]["code"] == '19':
print(r.json()["error_response"]["zh_desc"])
####如果token过期的话 会有邮件预警#####
"""
'JD——koen过期',"需要重新去授权具体的获取查看页面:https://oauth.jd.com/oauth/authorize?response_type=code&client_id=#########&redirect_uri=urn:ietf:wg:oauth:2.0:oob&state=1212")
print("京东提示的错误码:" + r.json()["error_response"]["code"] + " " + r.json()["error_response"]["zh_desc"]
"""
elif list(r.json().keys())[0] == 'jingdong_ldop_receive_trace_get_responce':#执行成功的判断
#已经拿到了物流轨迹 需要进行分析
data = r.json()["jingdong_ldop_receive_trace_get_responce"]["querytrace_result"]
#print(data)
for i in range(len(data.get('data'))):
# print(ll.get('data')[i])
dict = {}
dict["lpid"] = data.get('data')[i].get('waybillCode')
dict["rema"] = data.get('data')[i].get('opeTitle')
dict["tims"] = data.get('data')[i].get('opeTime')
dict["desb"] = data.get('data')[i].get('opeRemark')
data_value.append(dict)
#print(data_value)
else:
pass
#print(list(r.json().keys())[0])
return data_value
// 输入快递单号进行校验是否已经刷新成功
a = JDlog('JDV*******')
print(a)