用java接入国内1200家快递公司进行快递寄件

2021-07-14 16:44:19 浏览数 (1)

通过java对接国内1200家快递公司进行快递寄件操作,该Java寄快递接口支持顺丰、京东、韵达、申通、圆通、邮政、天天、百世等主流快递公司。

以下是寄快递接口的具体示例代码,如果有疑问可以随时联系官方运营人员。

  • 注意:

密钥需要注册快递100API企业版后才能获取,在测试前记得获取密钥,否则会调取失败。

https://api.kuaidi100.com/register/enterprise/

  • 寄快递接口官方文档:

http://api.kuaidi100.com/document/5f0ff0a5bc8da837cbd8aef7.html

代码语言:txt复制
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;
    }

}
java对接国内1200家快递公司进行快递寄件示例代码图例java对接国内1200家快递公司进行快递寄件示例代码图例

0 人点赞