获取快递公司列表
获取快递公司名称
1.请求参数:
参数名 | 类型 | 说明 | 示例 |
---|---|---|---|
appid | String | 合作伙伴AppId | uwkahf@jfs92 |
timestamp | String | 当前时间戳 | |
seller_nick | String | 拼多多商家账号,非店铺名称 | kingdo |
sign | String | 接口签名 | 如何计算生成见示例代码 |
2. 请求示例代码(Java)
@Test
public void getLogisticesCompany() throws Exception {
String result ="";
String sellerNick = Config.PddSellerNick ; // 拼多多卖家
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost( Config.PddLogisticesCompanyUrl );
//业务参数
Map<String, String> data = new HashMap<String, String>();
data.put("appid", Config.AppId);
data.put("seller_nick", sellerNick);
Long timestamp = System.currentTimeMillis() / 1000;
data.put("timestamp", timestamp.toString());
// 参数签名
data.put("sign", Utils.Sign(data,Config.AppSecret));
List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
for (Map.Entry<String, String> entry : data.entrySet()) {
params.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
}
//发起POST请求
try {
httpPost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
HttpResponse httpResponse = httpclient.execute(httpPost);
if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
result = EntityUtils.toString(httpResponse.getEntity());
} else {
result = ("doPost Error Response: " + httpResponse.getStatusLine().toString());
}
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(result);
}
3. 返回结果如下:
{
"code": 0,
"message": "ok",
"data": [
{
"available": 1,
"code": "STO",
"id": 1,
"logistics_company": "申通快递"
},
{
"available": 0,
"code": "SHHT",
"id": 2,
"logistics_company": "上海汇通"
},
{
"available": 1,
"code": "HT",
"id": 3,
"logistics_company": "百世快递"
},
{
"available": 1,
"code": "SF",
"id": 44,
"logistics_company": "顺丰快递"
},
{
"available": 1,
"code": "YTO",
"id": 85,
"logistics_company": "圆通快递"
},
{
"available": 0,
"code": "BBSD",
"id": 88,
"logistics_company": "奔奔速达"
},
{
"available": 0,
"code": "SAD",
"id": 89,
"logistics_company": "赛澳递"
},
{
"available": 0,
"code": "CHENGBANG",
"id": 90,
"logistics_company": "晟邦物流"
},
{
"available": 1,
"code": "ZTO",
"id": 115,
"logistics_company": "中通快递"
}
]
}
说明: code为0表示成功,非0为失败,message会包含失败原因。失败时一定要注意,可能商户授权过期,或是参数有误。 data为快递公司的集合,由于篇幅有限,省略部分数据。data集合中的对象关系如下:
code: 快递公司代码,logistics_company: 快递公司名称,id: 快递公司Id,发货接口使用此Id, available:是否有效,0-当前不支持的快递公司,1-支持的快递公司,注意:发货时必须入参支持的快递公司id,否则会报错。
文档更新时间: 2023-03-14 17:01 作者:admin