public static void main(String[] args) {
CertAlipayRequest certAlipayRequest = new CertAlipayRequest();
certAlipayRequest.setServerUrl("https://openapi.alipay.com/gateway.do");
certAlipayRequest.setAppId("setAppId");
certAlipayRequest.setPrivateKey("setPrivateKey");
certAlipayRequest.setCertPath(AlipayTurnConfig.certPathGgf);
certAlipayRequest.setAlipayPublicCertPath(AlipayTurnConfig.alipayPublickCertPathGgf);
certAlipayRequest.setRootCertPath(AlipayTurnConfig.rootCertPathGgf);
certAlipayRequest.setSignType("RSA2");
certAlipayRequest.setFormat("json");
certAlipayRequest.setCharset("UTF-8");
AlipayClient alipayClient = null;
try {
alipayClient = new DefaultAlipayClient(certAlipayRequest);
*//** 实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称:alipay.fund.trans.common.query(转账业务单据查询接口) **//*
AlipayFundTransCommonQueryRequest request = new AlipayFundTransCommonQueryRequest();
*//** 设置业务参数,具体接口参数传值以文档说明为准:https://opendocs.alipay.com/apis/api_28/alipay.fund.trans.common.query/ **//*
AlipayFundTransCommonQueryModel model = new AlipayFundTransCommonQueryModel();
*//** 固定值:TRANS_ACCOUNT_NO_PWD:单笔无密转账到支付宝账户 **//*
model.setProductCode("TRANS_ACCOUNT_NO_PWD");
*//** 描述特定的业务场景,如果传递了out_biz_no则该字段为必传,固定值:DIRECT_TRANSFER:B2C 现金红包、单笔无密转账 **//*
model.setBizScene("DIRECT_TRANSFER");
*//** 商户转账唯一订单号,单笔转账接口的入参 **//*
model.setOutBizNo("TXPO202101010849274"); // 支付宝转账成功,系统作废的!
//model.setOutBizNo("TXPO202101010849271");// 不存在的
//model.setOutBizNo("TXVK202101111337477");// 转账失败的
request.setBizModel(model);
AlipayFundTransCommonQueryResponse response = null;
response = alipayClient.certificateExecute(request);
if(response.isSuccess()){
System.out.println("调用成功");
//System.out.println(request.getBizContent());
System.out.println(request.getBizModel());
System.out.println(response.getParams());
System.out.println(response.getBody());
System.out.println(response.getOrderId());
System.out.println(response.getTransAmount());
} else {
System.out.println("调用失败");
System.out.println(request.getBizModel().toString());
System.out.println(response.getParams());
System.out.println(response.getBody());
System.out.println(response.getOrderId());
System.out.println(response.getSubCode());
System.out.println(response.getSubMsg());
}
} catch (AlipayApiException e) {
e.printStackTrace();
}
}
网友评论