跳到主要内容

Java SDK使用说明

您可以使用我们提供的开放SDK与PayCloud支付网关集成。SDK封装了执行集成的过程,包括添加和验证调用支付网关API的签名。 我们不保证此代码的安全性和实用性。这只是一个示例,演示了调用API的过程。您可以参考此代码来编写更适合您的业务系统的程序。

使用条件

适用于Java语言,JDK 1.8及以上版本的开发环境。

Java SDK集成

  1. SDK封装了签名验证逻辑,可以使用SDK直接调用API。
  2. 确定与接口对应的类 例如接口名称: wisehub.cloud.pay.order
    SDK中的类是:将每个单词的第一个字母大写,去掉分隔符(“.”),并在末尾添加Request(或Response)。
    示例中接口名称对应的类为:
    WisehubCloudPayOrderRequest(Request class)
    BscancPaySubmitResponse(Response class)

使用步骤

1. 下载jar并将其添加到您的项目中,请参考github源代码

wise-paycloud-open-api-sdk-java

云端API集成Java SDK jar包下载示意图
云端API集成Java SDK jar包下载示意图

2. 这个JAR依赖于一些开源的第三方JAR。如果这些JAR没有集成到您的项目中,您将需要手动向项目添加依赖项

<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.62</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.11</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.6</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.5.6</version>
</dependency>

3. 请参阅以下示例,并根据 API文档 进行开发

//  Instantiate the client
OpenApiClient openapiClient = new OpenApiClient(<YOUR_APP_ID>, <GATEWAY_URL>, <YOUR_APP_RSA_PRIVATE_KEY>, <GATEWAY_RSA_PUBLIC_KEY>);

// Instantiate the request class corresponding to the specific API.
// The class name corresponds to the interface name, and the name of the current calling interface: paycloud.pay.barcodepay
BscancPaySubmitRequest request = new BscancPaySubmitRequest();

// The SDK already encapsulates the public parameters; here you only need to pass in the business parameters
request.setMerchant_no("M01902792415");
request.setMerchant_order_no("TEST_" + System.currentTimeMillis());
request.setPrice_currency("USD");
request.setTrans_amount(new BigDecimal(10000.00));
request.setAuth_code("135170366275527172");
request.setDescription("test");

BscancPaySubmitResponse response;
try {
response = openapiClient.execute(request);
} catch (OpenApiException e) {
// The call failed with an error message printed
System.err.println();
System.err.println("request api error:" + e.getErrCode() + "->>" + e.getErrMsg());
return;
}
if (!response.isSuccess()) {
// Interface failed to execute, error message printed
System.err.println();
System.err.println("api execute error: " + JSON.toJSONString(response));
}