支付宝退款接口:
参考:https://docs.open.alipay.com/api_1/alipay.trade.refund/ 官方文档
直接上代码:
/** * 支付宝的退款接口 * @param orderId 商户的订单号 * @param tradeNo 支付宝的交易流水号 * @param totalAmount 退款金额 * @return */ public static Map alipayCreateOrderRefund(String orderId,String tradeNo,String totalAmount) { Map map = new LinkedHashMap(); AlipayClient alipayClient = new DefaultAlipayClient(AlipayConfig. aliPayUrl, AlipayConfig.appId, AlipayConfig.developerSpoon, "json", AlipayConfig.input_charset, AlipayConfig.aliPaySpoon, "RSA2"); AlipayTradeRefundRequest request = new AlipayTradeRefundRequest(); AlipayTradeRefundModel model= new AlipayTradeRefundModel(); model.setOutTradeNo(orderId);//订单支付时传入的商户订单号 model.setTradeNo(tradeNo);//支付宝交易号 model.setRefundAmount(totalAmount);//refund_amount 需要退款的金额,该金额不能大于订单金额,单位为元 request.setBizModel(model);//请求参数 AlipayTradeRefundResponse response=null; try { response = alipayClient.execute(request); System.out.println(JSONObject.fromObject(response).toString()); Map tuiMap=JSONObject.fromObject(response); }catch ( AlipayApiException e){ String massage = "alipay.trade.refund退款接口:订单签名错误"; System.out.println(massage); } if(response.isSuccess()){ System.out.println("调用成功"); map.put("status", 0);//订单退款 status:0 成功 1:失败 logger.info("支付宝:支付订单支付结果查询:订单out_trade_no----"+orderId+"---订单退款成功!"); } else { System.out.println("调用失败"); map.put("status",1);//订单退款 status:0 成功 1:失败 logger.info("支付宝:支付订单支付结果查询:订单out_trade_no----"+orderId+"---订单退款失败!"); } return map; }
退款成功的参数例如以下:
退款成功:{ "body":"{"alipay_trade_refund_response":{"code":"10000","msg":"Success","buyer_logon_id":"185******13","buyer_user_id":"2088422483503995","fund_change":"N","gmt_refund_pay":"2019-08-13 17:48:25","out_trade_no":"12337925","refund_fee":"0.01","send_back_fee":"0.00","trade_no":"2019081322001403990517324158"},"sign":"dNhUcD9THBOpAigyklYLyaNqUOEv2IpxENZLshgG4dzQkKa04GvVU1a9dqib98osDOEYAnGf1RNzm1QZvvw/9ybVCWMkQK0C/No+Tv13+7DZ2DfSqmtG+JsEugQM4lHJfsVm/QUIU9kprPOeuKJAoAw+fLVXaSgFT+hsnatHUpR0F+3ail/jpQDfonneMfJanMuAxbfA2LVlxHVpIaoC73yyHK0WEQNrSwnp0pTEO30uqnLi4EehiV+Wo8bSdGr9ilzAEmq1bcDsNQuftE+4TU/I4J5KyhjAJos4SbOU+98fQylwSqdG16Od3lDEuusedPq5bz1yoW+mDW0peU5i+g=="}", "buyerLogonId":"185******13", "buyerUserId":"2088422483503995", "code":"10000", "errorCode":"10000", "fundChange":"N", "gmtRefundPay":{ "date":13, "day":2, "hours":17, "minutes":48, "month":7, "seconds":25, "time":1565689705000, "timezoneOffset":-480, "year":119 }, "msg":"Success", "openId":"", "outTradeNo":"12337925", "params":{ "biz_content":"{"out_trade_no":"12337925","refund_amount":"0.01","trade_no":"2019081322001403990517324158"}" }, "presentRefundBuyerAmount":"", "presentRefundDiscountAmount":"", "presentRefundMdiscountAmount":"", "refundCurrency":"", "refundDetailItemList":[ ], "refundFee":"0.01", "sendBackFee":"0.00", "storeName":"", "subCode":"", "subMsg":"", "success":true, "tradeNo":"2019081322001403990517324158"}
根据自己的业务进行解析就行了,然后处理订单就行