当前位置: 首页 > 工具软件 > Open-XML-SDK > 使用案例 >

京东开放平台Java SDK jd-open-sdk 的引入与使用

公子昂
2023-12-01

京东开放平台Java SDK jd-open-sdk 的引入与使用。

从后台生成下载最新的Java SDK Jar 包“open-api-sdk-2.0-20xx-xx-xx.jar” ,保存到对应的项目的Lib目录中。
【pom.xml】中配置Maven的引入座标

<!--京东SDK引入-->
	<dependency>
            <groupId>com.jd</groupId>
            <artifactId>jd-open-sdk</artifactId>
            <version>1.0</version>
            <type>jar</type>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/open-api-sdk-2.0-2022-04-15.jar</systemPath>
        </dependency>
<!--jaskson引入-->
        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-mapper-asl</artifactId>
            <version>1.9.2</version>
        </dependency>

        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-core-asl</artifactId>
            <version>1.9.2</version>
        </dependency>


<build>
        <plugins>
            <plugin>
                <configuration>
<!-- 代表maven打包时会将外部引入的jar包(比如在根目录下或resource文件下新加外部jar包)打包到项目jar,在服务器上项目才能运行 -->
                    <includeSystemScope>true</includeSystemScope>
                </configuration>
            </plugin>
        </plugins>
    </build>
JdClient client=new DefaultJdClient("https://api.jd.com/routerjson","accessToken","appKey","appSecret");
        UnionOpenCategoryGoodsGetRequest request=new UnionOpenCategoryGoodsGetRequest();
        CategoryReq req=new CategoryReq();
        // 设置业务参数
        req.setParentId(0);
        req.setGrade(0);
        request.setReq(req);
        // 修改默认SDK中API协议版本
        request.setVersion("1.0");
        UnionOpenCategoryGoodsGetResponse response=client.execute(request);

        ObjectMapper mapper = new ObjectMapper();  // 新建一个ObjectMapper()
        String jsonString = mapper.writeValueAsString(response.getGetResult());
        System.out.println( jsonString );

        CategoryResp[] categoryList = response.getGetResult().getData();

        List<CategoryResp> cateList = Arrays.asList(categoryList);// 数组转为List对向


        testService.saveOrUpdateBatch(cateList);

        String responceName = request.getApiMethod();
        System.out.println("responceName:"+responceName);
 类似资料: