⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uspsservices.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        return packages;    }    // lifted from UpsServices with no changes - 2004.09.06 JFE    private static double calcPackageWeight(Map packageMap, List shippableItemInfo, double additionalWeight) {        double totalWeight = 0.00;        Iterator i = packageMap.keySet().iterator();        while (i.hasNext()) {            String productId = (String) i.next();            Map productInfo = getProductItemInfo(shippableItemInfo, productId);            double productWeight = ((Double) productInfo.get("weight")).doubleValue();            double quantity = ((Double) packageMap.get(productId)).doubleValue();            totalWeight += (productWeight * quantity);        }        return totalWeight + additionalWeight;    }    // lifted from UpsServices with no changes - 2004.09.06 JFE    private static Map getProductItemInfo(List shippableItemInfo, String productId) {        if (shippableItemInfo != null) {            Iterator i = shippableItemInfo.iterator();            while (i.hasNext()) {                Map testMap = (Map) i.next();                String id = (String) testMap.get("productId");                if (productId.equals(id)) {                    return testMap;                }            }        }        return null;    }    /*    Track/Confirm Samples: (API=TrackV2)    Request:    <TrackRequest USERID="xxxxxxxx" PASSWORD="xxxxxxxx">        <TrackID ID="EJ958083578US"></TrackID>    </TrackRequest>    Response:    <TrackResponse>        <TrackInfo ID="EJ958083578US">            <TrackSummary>Your item was delivered at 8:10 am on June 1 in Wilmington DE 19801.</TrackSummary>            <TrackDetail>May 30 11:07 am NOTICE LEFT WILMINGTON DE 19801.</TrackDetail>            <TrackDetail>May 30 10:08 am ARRIVAL AT UNIT WILMINGTON DE 19850.</TrackDetail>            <TrackDetail>May 29 9:55 am ACCEPT OR PICKUP EDGEWATER NJ 07020.</TrackDetail>        </TrackInfo>    </TrackResponse>    */    public static Map uspsTrackConfirm(DispatchContext dctx, Map context) {        Document requestDocument = createUspsRequestDocument("TrackRequest");        Element trackingElement = UtilXml.addChildElement(requestDocument.getDocumentElement(), "TrackID", requestDocument);        trackingElement.setAttribute("ID", (String) context.get("trackingId"));        Document responseDocument = null;        try {            responseDocument = sendUspsRequest("TrackV2", requestDocument);        } catch (UspsRequestException e) {            Debug.log(e, module);            return ServiceUtil.returnError("Error sending request for USPS Tracking service: " + e.getMessage());        }        Element trackInfoElement = UtilXml.firstChildElement(responseDocument.getDocumentElement(), "TrackInfo");        if (trackInfoElement == null) {            return ServiceUtil.returnError("Incomplete response from USPS Tracking service: no TrackInfo element found");        }        Map result = ServiceUtil.returnSuccess();        result.put("trackingSummary", UtilXml.childElementValue(trackInfoElement, "TrackSummary"));        List detailElementList = UtilXml.childElementList(trackInfoElement, "TrackDetail");        if (UtilValidate.isNotEmpty(detailElementList)) {            List trackingDetailList = new ArrayList();            for (Iterator iter = detailElementList.iterator(); iter.hasNext();) {                trackingDetailList.add(UtilXml.elementValue((Element) iter.next()));            }            result.put("trackingDetailList", trackingDetailList);        }        return result;    }    /*    Address Standardization Samples: (API=Verify)    Request:    <AddressValidateRequest USERID="xxxxxxx" PASSWORD="xxxxxxx">        <Address ID="0">            <Address1></Address1>            <Address2>6406 Ivy Lane</Address2>            <City>Greenbelt</City>            <State>MD</State>            <Zip5></Zip5>            <Zip4></Zip4>        </Address>    </AddressValidateRequest>    Response:    <AddressValidateResponse>        <Address ID="0">            <Address2>6406 IVY LN</Address2>            <City>GREENBELT</City>            <State>MD</State>            <Zip5>20770</Zip5>            <Zip4>1440</Zip4>        </Address>    </AddressValidateResponse>    Note:        The service parameters address1 and addess2 follow the OFBiz naming convention,        and are converted to USPS conventions internally        (OFBiz address1 = USPS address2, OFBiz address2 = USPS address1)    */    public static Map uspsAddressValidation(DispatchContext dctx, Map context) {        Document requestDocument = createUspsRequestDocument("AddressValidateRequest");        Element addressElement = UtilXml.addChildElement(requestDocument.getDocumentElement(), "Address", requestDocument);        addressElement.setAttribute("ID", "0");        // 38 chars max        UtilXml.addChildElementValue(addressElement, "FirmName", (String) context.get("firmName"), requestDocument);        // 38 chars max        UtilXml.addChildElementValue(addressElement, "Address1", (String) context.get("address2"), requestDocument);        // 38 chars max        UtilXml.addChildElementValue(addressElement, "Address2", (String) context.get("address1"), requestDocument);        // 15 chars max        UtilXml.addChildElementValue(addressElement, "City", (String) context.get("city"), requestDocument);        UtilXml.addChildElementValue(addressElement, "State", (String) context.get("state"), requestDocument);        UtilXml.addChildElementValue(addressElement, "Zip5", (String) context.get("zip5"), requestDocument);        UtilXml.addChildElementValue(addressElement, "Zip4", (String) context.get("zip4"), requestDocument);        Document responseDocument = null;        try {            responseDocument = sendUspsRequest("Verify", requestDocument);        } catch (UspsRequestException e) {            Debug.log(e, module);            return ServiceUtil.returnError("Error sending request for USPS Address Validation service: " + e.getMessage());        }        Element respAddressElement = UtilXml.firstChildElement(responseDocument.getDocumentElement(), "Address");        if (respAddressElement == null) {            return ServiceUtil.returnError("Incomplete response from USPS Address Validation service: no Address element found");        }        Element respErrorElement = UtilXml.firstChildElement(respAddressElement, "Error");        if (respErrorElement != null) {            return ServiceUtil.returnError("The following error was returned by the USPS Address Validation service: " +                    UtilXml.childElementValue(respErrorElement, "Description"));        }        Map result = ServiceUtil.returnSuccess();        // Note: a FirmName element is not returned if empty        String firmName = UtilXml.childElementValue(respAddressElement, "FirmName");        if (UtilValidate.isNotEmpty(firmName)) {            result.put("firmName", firmName);        }        // Note: an Address1 element is not returned if empty        String address1 = UtilXml.childElementValue(respAddressElement, "Address1");        if (UtilValidate.isNotEmpty(address1)) {            result.put("address2", address1);        }        result.put("address1", UtilXml.childElementValue(respAddressElement, "Address2"));        result.put("city", UtilXml.childElementValue(respAddressElement, "City"));        result.put("state", UtilXml.childElementValue(respAddressElement, "State"));        result.put("zip5", UtilXml.childElementValue(respAddressElement, "Zip5"));        result.put("zip4", UtilXml.childElementValue(respAddressElement, "Zip4"));        return result;    }    /*    City/State Lookup Samples: (API=CityStateLookup)    Request:    <CityStateLookupRequest USERID="xxxxxxx" PASSWORD="xxxxxxx">        <ZipCode ID="0">            <Zip5>90210</Zip5>        </ZipCode>    </CityStateLookupRequest>    Response:    <CityStateLookupResponse>        <ZipCode ID="0">            <Zip5>90210</Zip5>            <City>BEVERLY HILLS</City>            <State>CA</State>        </ZipCode>    </CityStateLookupResponse>    */    public static Map uspsCityStateLookup(DispatchContext dctx, Map context) {        Document requestDocument = createUspsRequestDocument("CityStateLookupRequest");        Element zipCodeElement = UtilXml.addChildElement(requestDocument.getDocumentElement(), "ZipCode", requestDocument);        zipCodeElement.setAttribute("ID", "0");        String zipCode = ((String) context.get("zip5")).trim(); // trim leading/trailing spaces        // only the first 5 digits are used, the rest are ignored        UtilXml.addChildElementValue(zipCodeElement, "Zip5", zipCode, requestDocument);        Document responseDocument = null;        try {            responseDocument = sendUspsRequest("CityStateLookup", requestDocument);        } catch (UspsRequestException e) {            Debug.log(e, module);            return ServiceUtil.returnError("Error sending request for USPS City/State Lookup service: " + e.getMessage());        }        Element respAddressElement = UtilXml.firstChildElement(responseDocument.getDocumentElement(), "ZipCode");        if (respAddressElement == null) {            return ServiceUtil.returnError("Incomplete response from USPS City/State Lookup service: no ZipCode element found");        }        Element respErrorElement = UtilXml.firstChildElement(respAddressElement, "Error");        if (respErrorElement != null) {            return ServiceUtil.returnError("The following error was returned by the USPS City/State Lookup service: " +                    UtilXml.childElementValue(respErrorElement, "Description"));        }        Map result = ServiceUtil.returnSuccess();        String city = UtilXml.childElementValue(respAddressElement, "City");        if (UtilValidate.isEmpty(city)) {            return ServiceUtil.returnError("Incomplete response from USPS City/State Lookup service: no City element found");        }        result.put("city", city);        String state = UtilXml.childElementValue(respAddressElement, "State");        if (UtilValidate.isEmpty(state)) {            return ServiceUtil.returnError("Incomplete response from USPS City/State Lookup service: no State element found");        }        result.put("state", state);        return result;    }    /*    Service Standards Samples:    Priority Mail: (API=PriorityMail)        Request:        <PriorityMailRequest USERID="xxxxxxx" PASSWORD="xxxxxxx">            <OriginZip>4</OriginZip>            <DestinationZip>4</DestinationZip>        </PriorityMailRequest>        Response:        <PriorityMailResponse>            <OriginZip>4</OriginZip>            <DestinationZip>4</DestinationZip>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -