java集成支付宝原路退款功能
* 支付宝原路退款集成需要商户订单号,支付宝交易流水号,以及退款金额(退款金额不得大于订单金额)
/****
* 支付宝订单原路退款
* @param out_trade_no 商户内部订单号
* @param trade_no 支付宝内部交易流水号
* @param refund_amount 退款金额,金额不得大于订单金额,最多保留两位小数
* @return
*/
public static String aliapyRefund(String out_trade_no,String trade_no,String refund_amount) {
//appid
String app_id=AlipayConfig.app_id;
//商户私钥
String private_key=AlipayConfig.private_key_refund;
//支付宝公钥验签
String alipay_public_key=AlipayConfig.alipay_public_key;
AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do",app_id,private_key,"json","utf-8",alipay_public_key);
AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();
//订单退款业务参数拼装
request.setBizContent("{" +"\"out_trade_no\":\""+out_trade_no+"\"," +"\"trade_no\":\""+trade_no+"\","+"\"out_request_no\":\""+"HZ01RF001"+"\"," +"\"refund_amount\":"+refund_amount+"" +" }");
AlipayTradeRefundResponse response=null;
try {
response = alipayClient.execute(request);
log.info("支付宝退款结果展示:"+response);
} catch (AlipayApiException e) {
log.info("支付宝退款结果错误内容显示:");
e.printStackTrace();
}
if("10000".equals(response.getCode())){
log.info("支付宝退款成功");
return "success"; //退款成功
} else {
log.info("支付宝退款失败");
return "error"; //退款失败
}
}
*以上相关支付宝工具类都可以去官方下载