关闭订单代码示例
本章主要介绍关闭订单的 Java SDK 代码示例。
代码示例
public void tradeClose(AcopayTradeCloseRequestModel tradeCloseRequestModel) {
// 翼辉支付平台公钥
String acopayPublicKey = "<acopayPublicKey>";
// 商户私钥
String mchPrivateKey = "<yourMchPrivateKey>";
// 商户号
String mchNo = "<yourMchNo>";
try {
// 创建 AcopayClient 实例
AcopayClient acopayClient = new DefaultAcopayClient(acopayPublicKey, mchPrivateKey, mchNo);
// 发送关单请求
AcopayResponse<AcopayTradeCloseResponseModel> acopayTradeCloseAcopayResponse = acopayClient
.tradeClose(tradeCloseRequestModel);
// 判断请求是否成功
if (acopayTradeCloseAcopayResponse.statusSuccessful()) {
log.info("关单接口返回:{}", acopayTradeCloseAcopayResponse);
// 获取业务数据
AcopayTradeCloseResponseModel data = acopayTradeCloseAcopayResponse.getData();
// 获取业务状态码
String code = data.getCode();
// 根据业务状态码进行商户业务处理
} else {
log.info("关单接口业务失败,返回状态码:{}, 返回信息:{}, 异常信息:{}",
acopayTradeCloseAcopayResponse.getStatus(), acopayTradeCloseAcopayResponse.getMessage(),
acopayTradeCloseAcopayResponse.getFieldErrors());
}
} catch (AcopayException e) {
// 进行异常处理
log.error("关单接口请求异常", e);
}
}