API de seguimiento para FedEx y UPS [cerrado
Pregunta
¿Hay alguna API de JavaScript disponible para rastrear paquetes de FedEx y UPS?
Solución
Busqué en Google por lo mismo, pero no pude encontrar ninguno. Entonces lo decido por el lado del servidor en ROR
Aquí es cómo obtener la solicitud y la respuesta de FedEx XML de FedEx de sus servidores de prueba
Para FedEx:
track_no = '111111111111' (This is test track no)
Este cuerpo de solicitud de XML para 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)
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.
Para UPS:
track_no = '1Z12345E1512345676' (This is test track no)
Este cuerpo de solicitud de XML para 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)
Esta variable hash contiene la respuesta de la solicitud de seguimiento de UPS en formato hash
Otros consejos
Otra manera fácil de hacerlo: simplemente cree un hipervínculo con el siguiente href
UPS:
http://wwwapps.ups.com/webtracking/track?loc=en_us&track.x=track&tracknums=put_tracking_number_here
FedEx:
(¡No es tan elegante, pero rápido, fácil y hace el trabajo!)
O puedes usar el activo_shipping GEM para una forma más agradable y limpia de rastrear sus paquetes para FedEx y UPS