通过 java 对接国内 1200 家快递公司进行快递寄件操作,该 Java 寄快递接口反对顺丰、京东、韵达、申通、圆通、邮政、天天、百世等支流快递公司。
以下是寄快递接口的具体示例代码,如果有疑难能够随时分割官网经营人员。
- 留神:
密钥须要注册快递 100API 企业版后能力获取,在测试前记得获取密钥,否则会调取失败。
https://api.kuaidi100.com/reg…
- 寄快递接口官网文档:
http://api.kuaidi100.com/docu…
package com.kuaidi100.sdk.api;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.kuaidi100.sdk.core.BaseClient;
import com.kuaidi100.sdk.request.BaseRequest;
import com.kuaidi100.sdk.contant.ApiInfoConstant;
import com.kuaidi100.sdk.pojo.HttpResult;
import com.kuaidi100.sdk.request.PrintReq;
import com.kuaidi100.sdk.response.BOrderQueryData;
import com.kuaidi100.sdk.response.BOrderResp;
import com.kuaidi100.sdk.response.PrintBaseResp;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpStatus;
import java.util.Map;
/**
* 商家寄件 (优选寄件)
*
* @Author: api.kuaidi100.com
* @Date: 2020-09-17 11:14
*/
public class BOrder extends BaseClient {
@Override
public String getApiUrl(BaseRequest request) {return ApiInfoConstant.B_ORDER_URL;}
public PrintBaseResp transportCapacity(PrintReq param) throws Exception{HttpResult httpResult = execute(param);
if (httpResult.getStatus() == HttpStatus.SC_OK && StringUtils.isNotBlank(httpResult.getBody())){return new Gson().fromJson(httpResult.getBody(),new TypeToken<PrintBaseResp<BOrderQueryData>>(){}.getType());
}
return null;
}
public PrintBaseResp order(PrintReq param) throws Exception{HttpResult httpResult = execute(param);
if (httpResult.getStatus() == HttpStatus.SC_OK && StringUtils.isNotBlank(httpResult.getBody())){return new Gson().fromJson(httpResult.getBody(),new TypeToken<PrintBaseResp<BOrderResp>>(){}.getType());
}
return null;
}
public PrintBaseResp getCode(PrintReq param) throws Exception{HttpResult httpResult = execute(param);
if (httpResult.getStatus() == HttpStatus.SC_OK && StringUtils.isNotBlank(httpResult.getBody())){return new Gson().fromJson(httpResult.getBody(),new TypeToken<PrintBaseResp<Map<String,String>>>(){}.getType());
}
return null;
}
public PrintBaseResp cancel(PrintReq param) throws Exception{HttpResult httpResult = execute(param);
if (httpResult.getStatus() == HttpStatus.SC_OK && StringUtils.isNotBlank(httpResult.getBody())){return new Gson().fromJson(httpResult.getBody(),new TypeToken<PrintBaseResp>(){}.getType());
}
return null;
}
}