【SF顺丰】顺丰开放平台API对接(Java对接篇)

对接前置篇:

【SF顺丰】顺丰开放平台API对接(注册、API测试篇)_顺丰api接口对接指南-CSDN博客

1.实现效果展示

2.SF顺丰开放平台,JDK资源下载。

下载地址:顺丰开放平台

3.将下载的JDK放入项目中。

4.将JDK资源引入pom.xml文件中。

java 复制代码
<!-- 顺丰丰桥 SDK -->
<dependency>
   <groupId>com.sf</groupId>
   <artifactId>SF-CSIM-EXPRESS-SDK</artifactId>
   <version>2.1.7</version>
   <scope>system</scope>
   <systemPath>${project.basedir}/lib/SF-CSIM-EXPRESS-SDK-V2.1.7.jar</systemPath>
</dependency>

注:项目启动pom.xml文件中配置打包将外部SDK引入项目包中,否则发布后依然是失效。

java 复制代码
<build>
   <plugins>
      <plugin>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-maven-plugin</artifactId>
         <configuration>
            <!-- 在打包时将引用的外部jar引入到当前项目包中	-->
            <fork>true</fork>
            <includeSystemScope>true</includeSystemScope>
         </configuration>
      </plugin>
   </plugins>
</build>

5.测试DEMO

接下来是一个详细的示例,演示如何使用顺丰丰桥API进行路由信息查询。

顺丰丰桥Api参考文档:顺丰开放平台

java 复制代码
public class SFTestDemo {

    private static final String CLIENT_CODE = "替换自己应用的顾客编码";  //顾客编码

    //沙箱环境的地址
    private static final String CALL_URL_BOX = "https://sfapi-sbox.sf-express.com/std/service";//请求接口
    private static final String CHECK_WORD_BOX = "替换自己应用的沙箱校验码";//沙箱校验码

    //生产环境的地址
    private static final String CALL_URL_PROD = "https://sfapi.sf-express.com/std/service";//请求接口
    private static final String CHECK_WORD = "替换自己的应用的生产校验码";//生产校验码


    /**
     * 查询顺丰路由信息
     * <p>
     * 顺丰快递单号
     * 收件人手机号后四位
     *
     * @return
     * @throws UnsupportedEncodingException
     */
    public static void main(String[] args) throws UnsupportedEncodingException {

        IServiceCodeStandard standardService = ExpressServiceCodeEnum.EXP_RECE_SEARCH_ROUTES;//路由查询

        String timeStamp = String.valueOf(System.currentTimeMillis());//时间戳

        CallExpressServiceTools tools = CallExpressServiceTools.getInstance();//数字签名,API文档有说明

        // set common header
        Map<String, String> params = new HashMap<String, String>();

        //封装查询msgData数据
        Map<String, Object> map = new HashMap<>();
        List<String> list = new ArrayList();
        list.add("替换自己顺丰单号");
        map.put("language", "0");
        map.put("trackingType", "1");
        map.put("methodType", "1");
        map.put("trackingNumber", list);
        map.put("checkPhoneNo", "替换快递单手机号后四位");
        String msgData = JSONObject.toJSONString(map);


//        params.put("Content-type", "application/x-www-form-urlencoded");
        params.put("partnerID", CLIENT_CODE);  // 顾客编码
        params.put("requestID", UUID.randomUUID().toString().replace("-", ""));
        params.put("serviceCode", standardService.getCode());// 接口服务码
        params.put("timestamp", timeStamp);
        params.put("msgData", msgData);
        params.put("msgDigest", tools.getMsgDigest(msgData, timeStamp, CHECK_WORD));

        String result = HttpClientUtil.post(CALL_URL_PROD, params);

        System.out.println("===调用地址 ===" + CALL_URL_PROD);
        System.out.println("===顾客编码 ===" + CLIENT_CODE);
        System.out.println("===返回结果:" + result);

    }
}
相关推荐
M1A11 小时前
小红书重磅升级!公众号文章一键导入,深度内容轻松入驻
后端
0wioiw02 小时前
Go基础(④指针)
开发语言·后端·golang
gnip2 小时前
Jst执行上下文栈和变量对象
前端·javascript
excel2 小时前
🐣 最简单的卷积与激活函数指南(带示例)
前端
醉方休3 小时前
npm/pnpm软链接的优点和使用场景
前端·npm·node.js
拉不动的猪3 小时前
简单回顾下Weakmap在vue中为何不能去作为循环数据源,以及替代方案
前端·javascript·vue.js
How_doyou_do3 小时前
数据传输优化-异步不阻塞处理增强首屏体验
开发语言·前端·javascript
奇舞精选3 小时前
超越Siri的耳朵:ASR与Whisper零代码部署实战指南
前端·人工智能·aigc
奇舞精选3 小时前
Nano Banana 如何为前端注入 AI 控制力
前端·aigc
一支鱼3 小时前
基于 Node.js 的短视频制作神器 ——FFCreator
前端·node.js·音视频开发