1. 电商发货前提准备:
- 准备快递100企业账号,并充值快递订阅查询功能
- 发货数据准备物流单号和物流公司编码,快递100官网下载快递100快递公司编码文档
2. Java代码示例:
2.1 订阅快递100发货
快递100订阅返回结果:{“result”:true,“returnCode”:“200”,“message”:“提交成功”}
//订阅快递100
String key = mallConfigProperties.getLogisticsKey(); //企业授权key
String customer = mallConfigProperties.getCustomer(); //企业授权cstomer
String company = entity.getLogistics(); //快递公司编码
String number = entity.getLogisticsNo(); //快递单号
String phone = orderLogistics.getTelNum(); //手机号
String callbackurl = StrUtil.format("{}{}{}", mallConfigProperties.getNotifyHost(),
"/mallapi/orderinfo/notify-logisticsr?tenantId="+orderLogistics.getTenantId()+"&logisticsId=",orderLogistics.getId());//回调地址
String from = ""; //出发地城市
String to = ""; //目的地城市
String salt = ""; //加密串
int resultv2 = 1; //行政区域解析
int autoCom = 0; //单号智能识别
int interCom = 0; //开启国际版
String departureCountry = ""; //出发国
String departureCom = ""; //出发国快递公司编码
String destinationCountry = ""; //目的国
String destinationCom = ""; //目的国快递公司编码
Kuaidi100Utils kuaidi100Utils = new Kuaidi100Utils(key);
log.info("快递100回调地址"+callbackurl);
log.info("快递100企业授权key"+key);
log.info("快递100企业授权customer"+customer);
String result = kuaidi100Utils.subscribeData(company, number, from, to, callbackurl, salt, resultv2, autoCom, interCom, departureCountry, departureCom, destinationCountry, destinationCom, phone);
log.info("快递100订阅返回"+result);
JSONObject jSONObject = JSONUtil.parseObj(result);
if(!(Boolean)jSONObject.get("result") && !"501".equals(jSONObject.get("returnCode"))){
log.error("快递订阅失败:returnCode:{};message:{}",jSONObject.get("returnCode"),jSONObject.get("message"));
throw new RuntimeException(String.valueOf(jSONObject.get("message")));
}
2.2. 更新最新物流信息
返回结果:
//更新最新物流信息
String res = kuaidi100Utils.queryData(company, number, key, customer);
log.info(number+"更新最新物流信息"+res);
JSONObject jsonObject = JSONUtil.parseObj(res);
saveQueryLogisticsr(jsonObject);
2.3. 其他代码
- 快递100工具类:
package com.joolun.cloud.mall.common.util;
import cn.hutool.crypto.digest.DigestUtil;
import cn.hutool.crypto.digest.MD5;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
/**
* 快递100工具类
*/
@Slf4j
public class Kuaidi100Utils {
/**
* 实时查询请求地址
*/
private static final String SUBSCRIBE_URL = "http://poll.kuaidi100.com/poll";
private static final String QUERY_URL = "https://poll.kuaidi100.com/poll/query.do";
/**
*