发生 USPS 异常时会显示什么消息?API 名称是跟踪和交付信息。
我已经在我的机器上成功集成了 USPS API。我可以通过跟踪号获取产品状态,但在 API 中可能发生异常的情况下,我想管理该情况的警报,以便通知我这种情况。我想知道如何检测异常?
我注意到此 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>
. . .
我自己找到了结果
但经过大量研究,我找到了解决问题的方法。下面给出:
在 USPS“跟踪和交付信息”API 集成中,我们可以将两种类型的 XML 请求格式发送到 USPS 服务器,以便以两种不同的方式通过其跟踪号检索包裹运输响应。
1) 跟踪/确认网络工具:- 这仅用于显示目的,作为响应,它仅返回文本消息(摘要和详细信息)。
API Signature(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 发生的错误/异常。
我已经使用EasyPost API 来获取更详细的跟踪和交付信息?这可能有帮助吗?我发现 USPS 异常通知不是很有用。
否则,您可以设置异常通知服务以在 API 异常发生时提醒您。