使用微信支付接口退款
准备工作
微信支付开发文档:https://pay.weixin.qq.com/docs/merchant/apis/jsapi-payment/create.html
退款与查单的请求头类似,但是查单是GET请求,所以在构造签名的时候相对简单些,但是退款请求中有请求参数,在构造签名时,需要将请求体添加到请求头参数中。
开始开发
1、构造请求参数
查看微信支付开发文档,请求参数中refund_id/out_refund_no,transaction_id/out_trade_no这两个参数,一个是微信支付系统中的退款号以及订单号,一个是自己的系统中的退款号以及订单号,这里我们使用后者;其次必填的参数还有refund、total、currency、amount
//构造请求参数
Map data = new HashMap();
data.put("out_trade_no", orderDao.getOrder_no());
data.put("out_refund_no", orderDao.getRefund_order_no());
Map amount = new HashMap();
amount.put("refund", (int) (Double.parseDouble(orderDao.getPrice()) * 100));
amount.put("total", (int) (Double.parseDouble(orderDao.getPrice()) * 100));
amount.put("currency", "CNY");
data.put("amount", amount)