我在使用FedEx API时遇到问题,我已阅读有关跟踪包的文档。我已经获得了填写URL所需的所有数字(测试跟踪编号,帐号,帐户密钥,计量表编号,用户名和密码)。
我获得了使用FedEx的URL,“生产服务器URL为”https://ws.fedex.com:443/web-services“,但是,我也被告知用我的实际信息替换凭证(测试跟踪号,帐号,帐号)密钥,仪表编号,用户名和密码)。
我在另一个StackOverflow帖子上发现了这个代码,我看到有一个用户评论说这种访问FedEx xml的方式已经过时了。无论如何,我包括了由Harshal_m_joshi发布并由houbysoft在此编辑的代码(原始帖子Tracking API for Fedex and UPS)。
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)
and that's it you will get response in hash variable, I converted xml response in to Hash because we can easily use Hash object at our view to display response data.
我想知道是否有人知道这样做的新方法,或者至少可以指出我正确的方向。我是API的新手,只与USPS和WUnderground一起工作,它们都很容易作为pi;)任何帮助都将非常感谢。
答案 0 :(得分:0)
您要将数据发布到https://ws.fedex.com:443/web-services
您的POST数据应如下所示......
<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns=\"http://fedex.com/ws/track/v5\">
<soapenv:Header/>
<soapenv:Body>
<TrackRequest xmlns:ns=\"http://fedex.com/ws/track/v5\"
xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">
<WebAuthenticationDetail>
<UserCredential>
<Key>" .$CFG["fedex_key"] ."</Key>
<Password>" .$CFG["fedex_password"] ."</Password>
</UserCredential>
</WebAuthenticationDetail>
<ClientDetail>
<AccountNumber>" . $CFG["fedex_acct"] ."</AccountNumber>
<MeterNumber>" . $CFG["fedex_meter"] ."</MeterNumber>
“。$ tracknum。”
TRCK
五
0
0
“。$ tracknum。”
TRACKING_NUMBER_OR_DOORTAG
真正