支付寶退款接口及反回參數

支付寶退款接口:json

參考:https://docs.open.alipay.com/api_1/alipay.trade.refund/    官方文檔api

直接上代碼:app

    

/**
     * 支付寶的退款接口
     * @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;
    }

 

退款成功的參數例如如下:ui

退款成功:
{
    "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"
}

根據本身的業務進行解析就好了,而後處理訂單就行spa

相關文章
相關標籤/搜索