经过一些工作,我终于能够让Shippo连接到eclipse。然而,在尝试了他们的例子之后,我意识到从他们的代码中获取费率的方式是不一样的。将getRates更改为getRateList后,费率列表上的返回值为空。即使打印出货件返回单也不能给我任何USPS费率,只有DHL、UPS和LPS,所有这些都不是费率,而是打印出为什么他们不能给我一个费率的不同问题。我想知道,为什么即使用Shippo的例子(是的,我尝试了本地地址),我也不能拿回任何价格。它只需要USPS,因为我不想通过其他服务提供商,但我想问的问题是我的代码,我是否遗漏了什么,或是否需要改变我的Shippo帐户。我已经阅读了他们的所有文件,查阅了这个问题很多,似乎没有人有相同的问题,我有。我还在测试令牌和由我的shippo帐户提供的实时令牌上尝试了这一点。另外,在我的运营商帐户中,我设置USPS以允许使用我的测试API的测试标签。
下面是我在Eclipse Scout中的代码:
// TEST API NO CHARGE
Shippo.setApiKey("shippo_test_XXXXXXXXXXXXXXXXXXXXXXXXXX");
// Shippo.setDEBUG(true);
Map<String, Object> toAddressMap = new HashMap<String, Object>();
toAddressMap.put("name", "Mr Hippo");
toAddressMap.put("company", "Shippo");
toAddressMap.put("street1", "215 Clayton St.");
toAddressMap.put("city", "San Francisco");
toAddressMap.put("state", "CA");
toAddressMap.put("zip", "94117");
toAddressMap.put("country", "US");
toAddressMap.put("phone", "+1 555 341 9393");
toAddressMap.put("email", "mrhippo@goshipppo.com");
// toAddressMap.put("is_residential", true);
// from address
Map<String, Object> fromAddressMap = new HashMap<String, Object>();
fromAddressMap.put("name", "Ms Hippo");
fromAddressMap.put("company", "San Diego Zoo");
fromAddressMap.put("street1", "2920 Zoo Drive");
fromAddressMap.put("city", "San Diego");
fromAddressMap.put("state", "CA");
fromAddressMap.put("zip", "92101");
fromAddressMap.put("country", "US");
fromAddressMap.put("email", "mshippo@goshipppo.com");
fromAddressMap.put("phone", "+1 619 231 1515");
fromAddressMap.put("metadata", "Customer ID 123456");
// fromAddressMap.put("is_residential", true);
// parcel
Map<String, Object> parcelMap = new HashMap<String, Object>();
parcelMap.put("length", "5");
parcelMap.put("width", "5");
parcelMap.put("height", "5");
parcelMap.put("distance_unit", "in");
parcelMap.put("weight", "2");
parcelMap.put("mass_unit", "lb");
List<Map<String, Object>> parcels = new ArrayList<Map<String, Object>>();
parcels.add(parcelMap);
Map<String, Object> shipmentMap = new HashMap<String, Object>();
shipmentMap.put("address_to", toAddressMap);
shipmentMap.put("address_from", fromAddressMap);
shipmentMap.put("parcels", parcels);
shipmentMap.put("async", false);
try {
Shipment shipment = Shipment.create(shipmentMap);
System.out.println(shipment);
} catch (AuthenticationException | InvalidRequestException | APIConnectionException | APIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}在运行我的代码之后,这里是我得到的JSON返回:
"object_state": null,
"object_status": null,
"object_purpose": null,
"object_id": "b4c380bbe17d4b0d9a468e91ddc247a3",
"object_owner": "reeseohouseknecht@gmail.com",
"object_created": "2022-03-20T09:19:28.505Z",
"object_updated": "2022-03-20T09:19:28.649Z",
"address_from": {
"object_id": "311925ff01fe4514b9229d9145227a09",
"is_complete": true,
"name": "Ms Hippo",
"company": "San Diego Zoo",
"street_no": "",
"street1": "2920 Zoo Drive",
"validation_results": {},
"street2": "",
"street3": "",
"city": "San Diego",
"state": "CA",
"zip": "92101",
"country": "US",
"phone": "0016192311515",
"email": "mshippo@goshipppo.com",
"is_residential": null,
"test": true
},
"address_to": {
"object_id": "c0fe7b3cc2684fa9bef7177259aba099",
"is_complete": true,
"name": "Mr Hippo",
"company": "Shippo",
"street_no": "",
"street1": "215 Clayton St.",
"validation_results": {},
"street2": "",
"street3": "",
"city": "San Francisco",
"state": "CA",
"zip": "94117",
"country": "US",
"phone": "0015553419393",
"email": "mrhippo@goshipppo.com",
"is_residential": null,
"test": true
},
"address_return": {
"object_id": "311925ff01fe4514b9229d9145227a09",
"is_complete": true,
"name": "Ms Hippo",
"company": "San Diego Zoo",
"street_no": "",
"street1": "2920 Zoo Drive",
"validation_results": {},
"street2": "",
"street3": "",
"city": "San Diego",
"state": "CA",
"zip": "92101",
"country": "US",
"phone": "0016192311515",
"email": "mshippo@goshipppo.com",
"is_residential": null,
"test": true
},
"parcel": null,
"submission_type": null,
"submission_date": null,
"insurance_amount": null,
"insurance_currency": null,
"extra": {},
"customs_declaration": null,
"reference_1": null,
"reference_2": null,
"rates_url": null,
"metadata": "",
"messages": [
{
"source": "UPS",
"code": "110920",
"text": "RatedShipmentAlert: Ship To Address Classification is changed from Commercial to Residential"
},
{
"source": "UPS",
"code": "110971",
"text": "RatedShipmentAlert: Your invoice may vary from the displayed reference rates"
},
{
"source": "ShippoCommon",
"code": "",
"text": "Shipment origin or destination state is out of the service area for LSO."
},
{
"source": "DHLExpress",
"code": "",
"text": "Shippo\u0027s DHL Express master account doesn\u0027t support shipments to inside of the US"
}
],
"rates_list": null
} 发布于 2022-04-10 02:12:13
查看以JSON发送回来的结果集,并将它们粘贴到JSON到string转换器中,可以看到,尽管我实际上无法对它们做任何事情,但我仍然收到了相应的结果。将Maven更新为3.1.0允许我使用相同的代码并将费率返回。
https://stackoverflow.com/questions/71545529
复制相似问题