项目中用到的支付宝退款
@RequestMapping("/getAlipayZ")
@ResponseBody
public static String getAlipayZ() {
AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", APP_ID,APP_PRIVATE_KEY, "json", "GBK", ALIPAY_PUBLIC_KEY, "RSA2");
AlipayTradeRefundRequest requests = new AlipayTradeRefundRequest();
AlipayTradeRefundModel bizModel = new AlipayTradeRefundModel();
bizModel.setOutTradeNo(outTradeNo);
//bizModel.setTradeNo(tradeNo);
bizModel.setRefundAmount(RefundAmount);
Boolean flag =new Boolean(false);
requests.setBizModel(bizModel);
AlipayTradeRefundResponse response = null;
try {
response = alipayClient.execute(requests);
if (response.isSuccess()) {
flag = true;
System.out.println("成功");
return response.getBody();
} else {
System.out.println("失败");
flag = false;
return response.getBody();
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("异常");
flag = false;
return response.getBody();
}
}
}
本文详细介绍了一个使用支付宝退款API的Java示例代码,包括初始化AlipayClient、设置退款参数及处理响应结果的过程。通过该示例,读者可以了解如何在项目中实现支付宝退款功能。
2万+

被折叠的 条评论
为什么被折叠?



