gpt4 book ai didi

ups - Fedex 和 UPS 的追踪 API

转载 作者:行者123 更新时间:2023-12-02 05:11:56 25 4
gpt4 key购买 nike

是否有任何 JavaScript API 可用于跟踪 Fedex 和 UPS 包裹?

最佳答案

我用谷歌搜索了类似的东西,但找不到任何东西。然后我决定在 ROR 中的服务器端进行。

这里介绍了如何从测试服务器获取 UPS 和 Fedex xml 请求和响应。

对于 FedEx express :

track_no = '111111111111'  # This is a test tracking number

# This XML Request body for fedex
xml_req =

"<TrackRequest xmlns='http://fedex.com/ws/track/v3'><WebAuthenticationDetail><UserCredential><Key>YOUR_ACC_KEY</Key>
<Password>YOUR_ACC_PASSWORD</Password></UserCredential></WebAuthenticationDetail><ClientDetail>
<AccountNumber>YOUR_ACC_NUMBER</AccountNumber><MeterNumber>YOUR_ACC_METER_NUMBER</MeterNumber></ClientDetail>
<TransactionDetail><CustomerTransactionId>ActiveShipping</CustomerTransactionId></TransactionDetail>
<Version><ServiceId>trck</ServiceId><Major>3</Major><Intermediate>0</Intermediate><Minor>0</Minor></Version>
<PackageIdentifier><Value>#{track_no}</Value><Type>TRACKING_NUMBER_OR_DOORTAG</Type></PackageIdentifier>
<IncludeDetailedScans>1</IncludeDetailedScans></TrackRequest>"

path = "https://gatewaybeta.fedex.com:443/xml"

#this url connects to the test server of fedex
# for live server url is:"https://gateway.fedex.com:443/xml"

url = URI.parse(path)
http = Net::HTTP.new(url.host,url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

response = http.post(url.path, xml_req)
response_body = response.body
res = response_body.gsub(/<(\/)?.*?\:(.*?)>/, '<\1\2>')
hash = Hash.from_xml(res.to_s)

就是这样!您将在哈希变量中获得响应,我将 xml 响应转换为 Hash,因为我们可以轻松地在 View 中使用 Hash 对象来显示响应数据。

对于 UPS:

track_no = '1Z12345E1512345676'  # This is a test tracking number

# This XML Request body for UPS
xml_req =

'<?xml version="1.0"?><AccessRequest xml:lang="en-US"><AccessLicenseNumber>YOUR_ACC_LICENCE_NUMBER</AccessLicenseNumber>
<UserId>YOUR_ACC_USER_ID</UserId><Password>YOUR_ACC_PASSWORD</Password></AccessRequest>
<?xml version="1.0"?><TrackRequest xml:lang="en-US"><Request><TransactionReference>
<CustomerContext>QAST Track</CustomerContext><XpciVersion>1.0</XpciVersion></TransactionReference>
<RequestAction>Track</RequestAction><RequestOption>activity</RequestOption></Request>
<TrackingNumber>#{track_no}</TrackingNumber></TrackRequest>'

path = "https://www.ups.com/ups.app/xml/Track"
url = URI.parse(path)
http = Net::HTTP.new(url.host,url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

response = http.post(url.path, xml_req)
response_body = response.body
hash = Hash.from_xml(response_body.to_s)

此哈希变量包含哈希格式的 UPS 跟踪请求的响应。

关于ups - Fedex 和 UPS 的追踪 API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5879953/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com