7天内免登录 确 定
手机快捷登录 帐号密码登录
别担心,无账号自动注册不会导致手机号被泄露
手机号码注册
已有账号? 去登录
确 定
136-8731-4921
人工咨询
申请试用

# SDK使用说明

# 以SDK-JAVA 为例:

调用示例

获取故事信息接口

接口名:alipay.story.find

版本号:1.0

参数:name 故事名称

针对这个接口,开发步骤如下:

1.在model包下新建一个类,定义业务参数

@Data
public class GetStoryModel {

    @JSONField(name = "name")
    private String name;
}

2.在response包下新建一个返回类GetStoryResponse,继承BaseResponse里面填写返回的字段

@Data
public class GetStoryResponse extends BaseResponse {
    private Long id;
    private String name;
    private Date gmtCreate;
}

3.在request包下新建一个请求类,继承BaseRequest

BaseRequest中有个泛型参数,填GetStoryResponse类,表示这个请求对应的返回类。 重写method()方法,填接口名。

如果要指定版本号,可重写version()方法,或者后续使用request.setVersion(version)进行设置

public class GetStoryRequest extends BaseRequest<GetStoryResponse> {
    @Override
    protected String method() {
        return "alipay.story.find";
    }
}

可重写getRequestMethod()方法指定HTTP请求method,默认是POST

使用方式

String url = "http://localhost:8081";
String appId = "2019032617262200001";
String privateKey = "你的私钥";

// 声明一个就行
OpenClient client = new OpenClient(url, appId, privateKey);

// 标准用法
@Test
public void testGet() {
    // 创建请求对象
    GetStoryRequest request = new GetStoryRequest();
    // 请求参数
    GetStoryModel model = new GetStoryModel();
    model.setName("白雪公主");
    
    request.setBizModel(model);

    // 发送请求
    GetStoryResponse response = client.execute(request);

    if (response.isSuccess()) {
        // 返回结果
        System.out.println(String.format("成功!response:%s\n响应原始内容:%s", 
                JSON.toJSONString(response), response.getBody()));
    } else {
        System.out.println("错误,subCode:" + response.getSubCode() + ", subMsg:" + response.getSubMsg());
    }
}