发生USPS异常时会填充什么消息? API名称为Tracking & Delivery Information.
我已在我的机器上成功集成USPS API。我能够获得带有跟踪号的产品状态,但是可能存在API中发生异常的情况,我想管理该条件的警报,以便我可以获知该情况。我想知道如何检测异常?
答案 0 :(得分:2)
我使用EasyPost API获取更详细的跟踪和投放信息?那可能有帮助吗?我发现USPS异常通知并不是非常有用。
否则,您可以设置例外通知服务,以便在API异常发生时提醒您。
答案 1 :(得分:2)
我自己找到了结果
但经过大量研究后,我找到了解决问题的方法。如下:
在USPS“跟踪和交付信息”API集成中,我们可以向USPS服务器发送两种类型的XML请求格式,以便以两种不同的方式通过其跟踪号检索包裹运输响应。
1)跟踪/确认Web工具: - 这仅用于显示目的,作为响应,它仅返回文本消息(摘要和详细信息)。
API签名(URL):
http://production.shippingapis.com/ShippingAPI.dll?API=TrackV2 //直播服务器
或者
http://production.shippingapis.com/ShippingAPITest.dll?API=TrackV2 //测试服务器
请求参数:
<TrackRequest USERID=”xxxxxxxx”>
<TrackID ID="EJ123456780US"></TrackID>
</TrackRequest>
它返回响应参数:仅摘要和详细信息
<TrackResponse>
<TrackInfo ID="E123456780US">
<TrackSummary>
Your item was delivered at 6:50 am on February 6 in BARTOW FL 33830.
</TrackSummary>
<TrackDetail>February 6 6:49 am NOTICE LEFT BARTOW FL 33830</TrackDetail>
<TrackDetail>February 6 6:48 am ARRIVAL AT UNIT BARTOW FL 33830</TrackDetail>
<TrackDetail>February 6 3:49 am ARRIVAL AT UNIT LAKELAND FL 33805</TrackDetail>
<TrackDetail>February 5 7:28 pm ENROUTE 33699</TrackDetail>
<TrackDetail>February 5 7:18 pm ACCEPT OR PICKUP 33699</TrackDetail>
</TrackInfo>
</TrackResponse>
2)跟踪/确认字段Web工具: - 这是对我有用的请求格式,我通过实现它来测试它。此请求返回包裹跟踪号码的完整信息,如: - API签名(URL):与第一个相同
请求示例:
<TrackFieldRequest USERID=" xxxxxxxx">
<TrackID ID="01805213907042762274"></TrackID>
</TrackFieldRequest>
响应示例:
<TrackResponse>
<TrackInfo ID="01805213907042762274">
<TrackSummary>
<EventTime>12:12 pm</EventTime>
<EventDate>May 21, 2001</EventDate>
<Event>DELIVERED</Event>
<EventCity>NEWTON</EventCity>
<EventState>IA</EventState>
<EventZIPCode>50208</EventZIPCode>
<EventCountry/>
<FirmName></FirmName>
<Name></Name>
<AuthorizedAgent></AuthorizedAgent>
</TrackSummary>
<TrackDetail>
<EventTime>9:24 pm</EventTime>
<EventDate>March 28, 2001</EventDate>
<Event>ENROUTE</Event>
<EventCity>DES MOINES</EventCity>
<EventState>IA</EventState>
<EventZIPCode>50395</EventZIPCode>
<EventCountry/>
<FirmName/>
<Name/>
<AuthorizedAgent/>
</TrackDetail>
.
.
.
</TrackResponse>
注意:我已将此XML响应转换为简单的PHP数组,并使用“事件”字段来管理所有条件的警报 与ENROUTE / DELIVERED等一样。并管理由其错误ID发生的错误/异常,该错误ID在其响应数组中返回。
答案 2 :(得分:1)
我注意到此API的另一种形式,您可以在响应中获得更多信息。将此XML文档传递到“XML”查询字符串参数:
<TrackFieldRequest USERID="XXXXXXXX">
<Revision>1</Revision>
<ClientIp>x.x.x.x</ClientIp>
<SourceId>customer / company name</SourceId>
<TrackID ID="9102xxxxxxxxx"></TrackID>
</TrackFieldRequest>
此XML文档的响应如下:
<TrackResponse>
<TrackInfo ID="9102xxxxxx">
<Class>Priority Mail 3-Day<SUP>™</SUP></Class>
<ClassOfMailCode>PM</ClassOfMailCode>
<DestinationCity>TOMAHAWK</DestinationCity>
<DestinationState>WI</DestinationState>
<DestinationZip>54487</DestinationZip>
<EmailEnabled>true</EmailEnabled>
<ExpectedDeliveryDate>March 4, 2014</ExpectedDeliveryDate>
<KahalaIndicator>false</KahalaIndicator>
<MailTypeCode>DM</MailTypeCode>
<MPDATE>2014-03-01 20:19:24.000000</MPDATE>
<MPSUFFIX>121219566</MPSUFFIX>
<OriginCity>EAST FALMOUTH</OriginCity>
<OriginState>MA</OriginState>
<OriginZip>02536</OriginZip>
<PodEnabled>false</PodEnabled>
<RestoreEnabled>false</RestoreEnabled>
<RreEnabled>false</RreEnabled>
<Service>$50 insurance included</Service>
<Service>USPS Tracking<SUP>™</SUP></Service>
<ServiceTypeCode>055</ServiceTypeCode>
<Status>Processed at USPS Origin Sort Facility</Status>
<StatusCategory>In Transit</StatusCategory>
<StatusSummary>Your item has been processed at the origin sort facility at 11:45 pm on March 1, 2014 in NASHUA, NH 03063.</StatusSummary>
<TABLECODE>T</TABLECODE>
<TrackSummary>
<EventTime>11:45 pm</EventTime>
<EventDate>March 1, 2014</EventDate>
<Event>Processed at USPS Origin Sort Facility</Event>
<EventCity>NASHUA</EventCity>
<EventState>NH</EventState>
<EventZIPCode>03063</EventZIPCode>
<EventCountry/>
<FirmName/><Name/><AuthorizedAgent>false</AuthorizedAgent>
<EventCode>10</EventCode>
</TrackSummary>
<TrackDetail>
<EventTime/>
<EventDate>March 1, 2014</EventDate>
<Event>Electronic Shipping Info Received</Event>
. . .