您好,登錄后才能下訂單哦!
本文實(shí)例為大家分享了java微信退款接口和支付寶退款接口的具體代碼,供大家參考,具體內(nèi)容如下
1、微信退款接口
相對(duì)來說我感覺微信的退款接口還是比較好調(diào)用的,直接發(fā)送httppost請(qǐng)求即可;
/** * * 微信退款 * @param transaction_id 微信支付訂單號(hào) * @param out_refund_no 商戶訂單號(hào) * @param total_fee 總金額 * @param refund_fee 退款金額 * @param op_user_id 操作人 * @return String * @exception */ public String wxPayRefundRequest(String transaction_id, String out_refund_no, int total_fee, int refund_fee, String op_user_id) { CloseableHttpClient httpclient = null; CloseableHttpResponse response = null; String strResponse = null; try { httpclient = ClientCustomSSL.getCloseableHttpClient(); // 構(gòu)造HTTP請(qǐng)求 HttpPost httpPost = new HttpPost(Configure.PAY_REFUND_API); // PayRefundReqData wxdata = new PayRefundReqData( // "1004720096201602263541023415", "16371", 30, 30, "19417"); PayRefundReqData wxdata = new PayRefundReqData(transaction_id, out_refund_no, total_fee, refund_fee, op_user_id); String requestStr = Util.ConvertObj2Xml(wxdata); StringEntity se = new StringEntity(requestStr.toString()); httpPost.setEntity(se); // 發(fā)送請(qǐng)求 response = httpclient.execute(httpPost); HttpEntity entity = response.getEntity(); if (entity != null) { SAXReader saxReader = new SAXReader(); Document document = saxReader.read(entity.getContent()); Element rootElt = document.getRootElement(); // 結(jié)果碼 String returnCode = rootElt.elementText("return_code"); String resultCode = rootElt.elementText("result_code"); if ("SUCCESS".equals(returnCode)&&"SUCCESS".equals(resultCode)) { strResponse=returnCode; }else { strResponse=rootElt.elementText("err_code_des"); } } EntityUtils.consume(entity); } catch (Exception e) { Logger.getLogger(getClass()).error("payRefundRequest", e); } finally { try { response.close(); httpclient.close(); } catch (IOException e) { // TODO Auto-generated catch block Logger.getLogger(getClass()).error("payRefundRequest關(guān)閉異常:", e); } } return strResponse; }
報(bào)錯(cuò)的話請(qǐng)檢查加密的sign是否正確,還有就是調(diào)用的接口地址是否正確
2、支付寶退款接口
支付寶直接導(dǎo)入支付寶封裝好的jar包直接調(diào)用即可,官網(wǎng)下載地址
調(diào)用方法:
/** * * 支付寶退款請(qǐng)求 * @param out_trade_no 訂單支付時(shí)傳入的商戶訂單號(hào),不能和 trade_no同時(shí)為空。 * @param trade_no 支付寶交易號(hào),和商戶訂單號(hào)不能同時(shí)為空 * @param refund_amount 需要退款的金額,該金額不能大于訂單金額,單位為元,支持兩位小數(shù) * @return * String * @exception */ public String alipayRefundRequest(String out_trade_no,String trade_no,double refund_amount){ // 發(fā)送請(qǐng)求 String strResponse = null; try { AlipayClient alipayClient = new DefaultAlipayClient (AlipayConfig.alipayurl,AlipayConfig.appid, AlipayConfig.private_key,AlipayConfig.content_type,AlipayConfig.input_charset,AlipayConfig.ali_public_key); AlipayTradeRefundRequest request = new AlipayTradeRefundRequest(); AlipayRefundInfo alidata= new AlipayRefundInfo(); alidata.setOut_trade_no(out_trade_no); alidata.setRefund_amount(refund_amount); alidata.setTrade_no(trade_no); request.setBizContent(JsonUtils.convertToString(alidata)); AlipayTradeRefundResponse response = alipayClient.execute(request); strResponse=response.getCode(); if ("10000".equals(response.getCode())) { strResponse="退款成功"; }else { strResponse=response.getSubMsg(); } } catch (Exception e) { Logger.getLogger(getClass()).error("alipayRefundRequest", e); } return strResponse; }
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持億速云。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。