rpa_JD_getExpressInfo
获取订单物流信息
1. 函数
rpa_JD_parseExpressInfo(expressInfo)
- expressInfo:字符串类型,rpa_JD_getExpressInfo返回的数据;
2. 返回值
LogisticsInfo类型,对象数组:不为空表示成功,为空表示失败或无效的物流信息数据,通过rpa_getLastErrorCode()获取错误码,rpa_getLastErrorMsg()获取错误信息。 LogisticsInfo类定义如下:
class TraceInfo:
def __init__(self, jsonInfo):
self.processInfo = jsonInfo['processInfo']
self.processDate = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(jsonInfo['processDate'] / 1000))
self.processTimestamp = jsonInfo['processDate']
def __str__(self):
return self.processDate + " " + self.processInfo + "\n"
class LogisticsInfo:
def __init__(self, jsonInfo):
self.thirdId = jsonInfo['thirdId'] # 物流ID
self.thirdName = jsonInfo['thirdName'] # 物流名称
self.status = self.__translateStatus(jsonInfo['status']) # 物流状态
self.shipId = jsonInfo['shipId'] # 运单号
tempListTrace = []
for traceJsonInfo in jsonInfo['listTrace']:
tempListTrace.append(TraceInfo(traceJsonInfo))
self.listTrace = tempListTrace # 跟踪信息
def __translateStatus(self, statusCode):
if statusCode == 0:
return "可跟踪"
elif statusCode == 1:
return "跟踪完成"
elif statusCode == 2:
return "强制完成跟踪"
elif statusCode == 3:
return "有未签收原因的完成跟踪订单"
elif statusCode == 100:
return "正在跟踪"
elif statusCode == 220:
return "取件单揽收成功"
elif statusCode == 229:
return "送达成功"
elif statusCode == 230:
return "送达未成功"
3. 示例
# 订单ID
orderId = "1000000000"
# 获取订单物流信息
resultData = rpa_JD_getExpressInfo(orderId)
if resultData == "" or resultData.isspace():
rpa_log("订单号{0}返回数据为空,错误信息:{1}。".format(orderId, rpa_getLastErrorMsg()))
rpa_exit()
# 解析物流信息
infoList = rpa_JD_parseExpressInfo(resultData)
if len(infoList) == 0:
rpa_log("订单号{0}物流信息为空。".format(orderId))
rpa_exit()
# 每个对象对应一个运单号的物流信息
for info in infoList:
# 输出物流ID
print(info.thirdId)
# 输出物流名称
print(info.thirdName)
# 输出物流状态
print(info.status)
# 输出运单号
print(info.shipId)
# 输出跟踪信息
for traceInfo in info.listTrace:
print(traceInfo)