USPS的运费报价api仅适用于美国邮政编码。加拿大,英国和其他国际邮政编码会导致此错误:Microsoft VBScript运行时错误“800a01a8”所需对象:xmlRate.selectSingleNode(...)'/ folder / pubfolder / usps_plugin.asp,第32行。
以下是该文件的代码:
<%
function GetUSPSRate(SourceZip, DestZip, Weight, Method)
dim xml
dim post
post = "<RateV4Request USERID='MYUSPSUSERNAME'>" & _
"<Revision/>" & _
"<Package ID='1ST'>" & _
"<Service>" & Method & "</Service>" & _
"<ZipOrigination>" & SourceZip & "</ZipOrigination>" & _
"<ZipDestination>" & DestZip & "</ZipDestination>" & _
"<Pounds>" & Weight & "</Pounds>" & _
"<Ounces>0</Ounces>" & _
"<Container>RECTANGULAR</Container>" & _
"<Size>LARGE</Size>" & _
"<Width>12</Width>" & _
"<Length>12</Length>" & _
"<Height>12</Height>" & _
"<Girth>12</Girth>" & _
"</Package>" & _
"</RateV4Request>"
set xml = CreateObject("MSXML2.ServerXMLHTTP")
xml.open "GET", "http://production.shippingapis.com/ShippingAPI.dll?API=RateV4&XML=" & post
xml.send("")
dim xmlRate
set xmlRate = xml.responseXML
GetUSPSRate = xmlRate.selectSingleNode("//Rate").text
end function
function GetUSPSRates(SourceZip, DestZip, Weight)
dim rates
set rates = CreateObject("Scripting.Dictionary")
rates.add "USPS Express", GetUSPSRate(SourceZip, DestZip, Weight, "EXPRESS")
rates.add "USPS Priority", GetUSPSRate(SourceZip, DestZip, Weight, "PRIORITY")
' rates.add "USPS First Class", GetUSPSRate(SourceZip, DestZip, Weight, "FIRST CLASS")
set GetUSPSRates = rates
end function
%>
此外,这是调用该请求的代码:
dim uspsRates
dim uspsKey
set uspsRates = GetUSPSRates("02196", receiverpostalcode, shipmentweight)
for each uspsKey in uspsRates
dim uspsValue
uspsValue = uspsRates.item(uspsKey)
%>
<input name="shipinfo" type="radio" value="<%= uspsValue %>|<%= uspsKey %>">$<%= uspsValue + stone_handlingfee %> <%= uspsKey %>
<br>
<% next
%>
对于国内邮政编码而言,它完美无瑕地工作,然而,国际邮政编码何时出现。非常感谢建设性的投入。
答案 0 :(得分:1)
并非所有变量都用于生成国际报价。国家,城市和邮编是最重要的。如果没有这些,api就无法返回结果。