【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);

    }
}
相关推荐
会飞的架狗师11 分钟前
【SpringBoot实战】优雅关闭服务
java·spring boot·后端
江城开朗的豌豆20 分钟前
JavaScript篇:构造函数 vs Class:谁才是对象创建的王者?
前端·javascript·面试
江城开朗的豌豆23 分钟前
JavaScript篇:数组找不同:如何快速找出两个数组间的'单身狗'元素?
前端·javascript·面试
不吃鱼的羊1 小时前
ISOLAR软件生成报错处理(七)
java·前端·javascript
TE-茶叶蛋1 小时前
React-props
前端·javascript·react.js
安分小尧1 小时前
[特殊字符] 超强 Web React版 PDF 阅读器!支持分页、缩放、旋转、全屏、懒加载、缩略图!
前端·javascript·react.js
EndingCoder1 小时前
React从基础入门到高级实战:React 高级主题 - React Concurrent 特性:深入探索与实践指南
前端·javascript·react.js·前端框架
EndingCoder1 小时前
React从基础入门到高级实战:React 生态与工具 - React Query:异步状态管理
前端·javascript·react.js·前端框架
TE-茶叶蛋1 小时前
ReactJS 中的 JSX工作原理
前端·react.js·前端框架
水煮白菜王1 小时前
React 编译器
前端·react.js·前端框架