支付宝沙箱支付退款
1 创建AplipayClient,调用支付宝沙箱支付接口
2 创建AlipayTradeRefundRequest,设置相关参数,例如支付宝交易凭证号,交易金额等
3 获得响应AlipayTradeRefundResponse,获得退款状态
代码如下:
@GetMapping("return") public void returnPay() throws AlipayApiException { // 1. 创建Client,通用SDK提供的Client,负责调用支付宝的API AlipayClient alipayClient = new DefaultAlipayClient(serverUrl,appId,privateKey,"json", "UTF-8",alipayPublicKey,"RSA2"); // 2. 创建 Request,设置参数 AlipayTradeRefundRequest request = new AlipayTradeRefundRequest(); JSONObject bizContent = new JSONObject(); bizContent.put("trade_no", "2023122922001412850501466077"); // 支付宝回调的订单流水号 bizContent.put("refund_amount", 5.00); // 订单的总金额 bizContent.put("out_request_no", "202100012260112"); // 我的订单编号 request.setBizContent(bizContent.toString()); // 3. 执行请求 AlipayTradeRefundResponse response = alipayClient.execute(request); if (response.isSuccess()) { // 退款成功,isSuccess 为true System.out.println("退款成功"); } else { // 退款失败,isSuccess 为false System.out.println(response.getBody()); } }
0条评论
点击登录参与评论