有赞云 SDK 如何调用海淘跨境 API 接口

说明:

经常会有开发者跟我们反馈说:为什么下载有赞云的 SDK 后,调用跨境支付报关接口找不到相关的类,无法使用等问题。那么本文将以跨境报关接口举例说明,详细说明如何用有赞云的 SDK 调用海淘跨境的相关接口。

SDK 下载:

1. 有赞云 SDK 下载地址:https://doc.youzanyun.com/doc#/content/27032/27651
2.Java Maven 方式引用(推荐使用)

<dependency>
<groupId>com.youzan.cloud</groupId>
<artifactId>open-sdk-core</artifactId>
<version>1.0.5-RELEASE</version>
</dependency>
<dependency>
<groupId>com.youzan.cloud</groupId>
<artifactId>open-sdk-gen</artifactId>
<version>1.0.5.201906171456-RELEASE</version>
</dependency>

注意:
引入 maven 直接按照上面的代码示例即可;请在 settings.xml 中引入有赞云 maven 仓库

<repository>
<id>baymax-releases</id>
<name>Nexus Release Repository</name>
<url>http://maven.youzanyun.com/repository/maven-releases/</url>
</repository>

接口调用

Example1.
接口名称:支付报关接口
API 接口:youzan.pay.customs.declaration.reportpayment.report.1.0.1
API 文档地址:https://doc.youzanyun.com/doc#/content/API/1-444/detail/api/0/111
请求示例:

 public class TestCrossBorder {
    @Test
    public void test() {
  Token token = new Token("892e468edaef93c70f8e1845338xxxxxx");
  DefaultYZClient yzClient = new DefaultYZClient();
 //请求api
 YouzanPayCustomsDeclarationReportpaymentReport youzanPayCustomsDeclarationReportpaymentReport = new YouzanPayCustomsDeclarationReportpaymentReport();
 //创建参数对象,并设置参数
 YouzanPayCustomsDeclarationReportpaymentReportParams youzanPayCustomsDeclarationReportpaymentReportParams = new YouzanPayCustomsDeclarationReportpaymentReportParams();
 youzanPayCustomsDeclarationReportpaymentReportParams.setActionType(1);
 youzanPayCustomsDeclarationReportpaymentReportParams.setCustomsCode("HZ");
 youzanPayCustomsDeclarationReportpaymentReportParams.setTid("E20190610110416061100019");
 youzanPayCustomsDeclarationReportpaymentReportParams.setKdtId(42587152L);
 youzanPayCustomsDeclarationReportpaymentReportParams.setTransaction("190610110418262167");
 youzanPayCustomsDeclarationReportpaymentReport.setAPIParams(youzanPayCustomsDeclarationReportpaymentReportParams);
 //获取请求结果
 try {
 YouzanPayCustomsDeclarationReportpaymentReportResult result = yzClient.invoke(youzanPayCustomsDeclarationReportpaymentReport, token, YouzanPayCustomsDeclarationReportpaymentReportResult.class);
 System.out.println(JSON.toJSON(result));
       } catch (
        SDKException e) {
            e.printStackTrace();
        }

  响应示例:

{
    "code":200,
    "data":{
        "kdt_id":42587152,
        "customs_status":2,
        "declare_customs_no":"190610110418262167",
        "tid":"E20190610110416061100019",
        "transaction":"190610110418262167"
    },
    "success":true,
    "message":""
}

Example2.
接口名称:报关状态查询接口
API 接口:youzan.pay.customs.declaration.reportpayment.query.1.0.1
API 文档地址:https://doc.youzanyun.com/doc#/content/API/1-444/detail/api/0/110
请求示例:

  //请求api
  YouzanPayCustomsDeclarationReportpaymentQuery youzanPayCustomsDeclarationReportpaymentQuery = new YouzanPayCustomsDeclarationReportpaymentQuery();
  //创建参数对象,并设置参数
  YouzanPayCustomsDeclarationReportpaymentQueryParams youzanPayCustomsDeclarationReportpaymentQueryParams = new YouzanPayCustomsDeclarationReportpaymentQueryParams();
  youzanPayCustomsDeclarationReportpaymentQuery.setAPIParams(youzanPayCustomsDeclarationReportpaymentQueryParams);
  youzanPayCustomsDeclarationReportpaymentQueryParams.setKdtId(42587152L);
  youzanPayCustomsDeclarationReportpaymentQueryParams.setTid("E20190610110416061100019");
  youzanPayCustomsDeclarationReportpaymentQueryParams.setTransaction("190610110418262167");
  //获取请求结果
   try {
   YouzanPayCustomsDeclarationReportpaymentQueryResult result = yzClient.invoke(youzanPayCustomsDeclarationReportpaymentQuery, token, YouzanPayCustomsDeclarationReportpaymentQueryResult.class);
        System.out.println(JSON.toJSON(result));
       } catch (
        SDKException s) {
            s.printStackTrace();
        }

响应示例:

{
    "code":200,
    "data":{
        "customs_info":"发送海关成功",
        "customs_status":2,
        "customs_time":1560137400000,
        "declare_customs_no":"190610110418262167",
        "tid":"E20190610110416061100019",
        "transaction":"190610110418262167"
    },
    "success":true,
    "message":""
}

Example3.
接口名称:海淘电子口岸列表查询接口
API 接口:youzan.shop.crossborder.list.1.0.0
API 文档地址:https://doc.youzanyun.com/doc#/content/API/1-354/detail/api/0/297
请求示例:

public class TestCrossBorder {
    @Test
    public void test() {
        Token token = new Token("892e468edaef93c70f8e184533xxxx5");
        DefaultYZClient yzClient = new DefaultYZClient();
        //请求api
        YouzanShopCrossborderList youzanShopCrossborderList = new YouzanShopCrossborderList();
        //创建参数对象,并设置参数
        YouzanShopCrossborderListParams youzanShopCrossborderListParams = new YouzanShopCrossborderListParams();
        youzanShopCrossborderList.setAPIParams(youzanShopCrossborderListParams);
        //获取请求结果
        try {
            YouzanShopCrossborderListResult result = yzClient.invoke(youzanShopCrossborderList, token, YouzanShopCrossborderListResult.class);
            System.out.println(JSON.toJSON(result));
        } catch (
                SDKException e) {
            e.printStackTrace();
        }

响应示例:

{
    "code":200,
    "data":[
        {
            "port_name":"郑州海关",
            "port_code":"ZZ"
        },
        {
            "port_name":"广州白云",
            "port_code":"GZ"
        },
        {
            "port_name":"广州黄埔",
            "port_code":"GH"
        },
        {
            "port_name":"广州南沙",
            "port_code":"GN"
        },
        {
            "port_name":"上海海关",
            "port_code":"SH"
        },
        {
            "port_name":"杭州海关",
            "port_code":"HZ"
        },
        {
            "port_name":"杭州金义",
            "port_code":"JY"
        },
        {
            "port_name":"义乌海关",
            "port_code":"YW"
        },
        {
            "port_name":"福州海关",
            "port_code":"FZ"
        },
        {
            "port_name":"重庆海关",
            "port_code":"CQ"
        },
        {
            "port_name":"宁波栎社",
            "port_code":"NB"
        },
        {
            "port_name":"宁波北仑",
            "port_code":"NN"
        },
        {
            "port_name":"宁波梅山",
            "port_code":"NM"
        },
        {
            "port_name":"深圳海关",
            "port_code":"SZ"
        },
        {
            "port_name":"北京海关",
            "port_code":"BJ"
        },
        {
            "port_name":"天津海关",
            "port_code":"TJ"
        },
        {
            "port_name":"江苏太仓",
            "port_code":"TC"
        },
        {
            "port_name":"成都海关",
            "port_code":"CD"
        },
        {
            "port_name":"西安海关",
            "port_code":"XA"
        }
    ],
    "success":true,
    "message":"successful"
}