日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

申请退款

發布時間:2024/1/17 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 申请退款 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

微信公眾號支付請看上一篇文章:?
http://blog.csdn.net/aofavx/article/details/52220394?
需要用到的Java類都在:?
http://download.csdn.net/detail/aofavx/9606697

微信公眾號退款相對支付來說就簡單多了,唯一需要注意的地方就是:在支付的時候需要用到商戶的證書。?
退款代碼如下:?
jsp提交退款申請:

//退款 function refundWXPay() { window.location.href="refundPay?orderId=${orderId}"; }
  • 1
  • 2
  • 3
  • 4

java代碼:

/***微信公眾號申請退款* @param orderId 訂單id* @param total_fee 退款金額* @param refund_fee 退款金額* @param response* @return* @throws Exception */@RequestMapping(value="/refundPay")@ResponseBodyprivate ModelAndView refundwx(HttpServletRequest request,HttpServletResponse response) throws Exception{logBefore(logger, "退款"); ModelAndView mv = this.getModelAndView(); PageData pd = new PageData(); pd = this.getPageData(); /*--------1.初始化數據參數----------*/ String appId= "wxfd7c065eee11112222"; String secret= "b5b3a627f5d1f8888888888888"; String shh= "111111111; String key= "mmmmmmmmmmmmmmm"; String filePath = "E:\\證書\\apiclient_cert.p12"; //退款需要提供證書數據,所以需要根據證書路徑讀取證書 //需要退款的商戶訂單號,對應提交訂單中的out_trade_no String orderId = request.getParameter("orderId").toString(); String total_fee=WeChat.getMoney(request.getParameter("total_fee")); //也可以根據業務場景從數據庫中獲取總金額和退款金額 String refund_fee=WeChat.getMoney(request.getParameter("refund_fee")); Map<String,String> result = (Map<String, String>) wxRefund(request,response,appId,secret,shh,key,orderId,total_fee,refund_fee,filePath); /* 根據result的返回狀態,處理你的業務邏輯 ..... */ mv.setViewName("wechat/refundFind"); return mv; } private Object wxRefund(HttpServletRequest request,HttpServletResponse response,String appId, String secret,String shh,String key,String orderId,String total_fee,String refund_fee,String path){ Map<String,String> result=new HashMap<String,String>(); PageData pd = new PageData(); pd = this.getPageData(); String refundid = UuidUtil.get32UUID(); String nonce_str = MD5.getMessageDigest(String.valueOf(new Random().nextInt(10000)).getBytes()); /*----- 1.生成預支付訂單需要的的package數據-----*/ SortedMap<String, String> packageParams = new TreeMap<String, String>(); packageParams.put("appid", appId); packageParams.put("mch_id", shh); packageParams.put("nonce_str", nonce_str); packageParams.put("op_user_id", shh); packageParams.put("out_trade_no", orderId); packageParams.put("out_refund_no", refundid); packageParams.put("total_fee",total_fee); packageParams.put("refund_fee", refund_fee); /*----2.根據package生成簽名sign---- */ RequestHandler reqHandler = new RequestHandler(request, response); reqHandler.init(appId, secret, key); String sign = reqHandler.createSign(packageParams); /*----3.拼裝需要提交到微信的數據xml---- */ String xml="<xml>" +"<appid>"+appId+"</appid>" + "<mch_id>"+shh+"</mch_id>" + "<nonce_str>"+nonce_str+"</nonce_str>" + "<op_user_id>"+shh+"</op_user_id>" + "<out_trade_no>"+orderId+"</out_trade_no>" + "<out_refund_no>"+refundid+"</out_refund_no>" + "<refund_fee>"+refund_fee+"</refund_fee>" + "<total_fee>"+total_fee+"</total_fee>" + "<sign>"+sign+"</sign>" +"</xml>"; try { /*----4.讀取證書文件,這一段是直接從微信支付平臺提供的demo中copy的,所以一般不需要修改---- */ KeyStore keyStore = KeyStore.getInstance("PKCS12"); FileInputStream instream = new FileInputStream(new File(path)); try { keyStore.load(instream, shh.toCharArray()); } finally { instream.close(); } // Trust own CA and all self-signed certs SSLContext sslcontext = SSLContexts.custom().loadKeyMaterial(keyStore, shh.toCharArray()).build(); // Allow TLSv1 protocol only SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext,new String[] { "TLSv1" },null, SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(sslsf).build(); /*----5.發送數據到微信的退款接口---- */ String url="https://api.mch.weixin.qq.com/secapi/pay/refund"; HttpPost httpost= HttpClientConnectionManager.getPostMethod(url); httpost.setEntity(new StringEntity(xml, "UTF-8")); HttpResponse weixinResponse = httpClient.execute(httpost); String jsonStr = EntityUtils.toString(weixinResponse.getEntity(), "UTF-8"); logger.info(jsonStr); Map map = GetWxOrderno.doXMLParse(jsonStr); if("success".equalsIgnoreCase((String) map.get("return_code"))){ logger.info("退款成功"); result.put("returncode", "ok"); result.put("returninfo", "退款成功"); }else{ logger.info("退款失敗"); result.put("returncode", "error"); result.put("returninfo", "退款失敗"); } } catch (Exception e) { logger.info("退款失敗"); result.put("returncode", "error"); result.put("returninfo", "退款失敗"); } return result; }




來源:http://blog.csdn.net/yuexianchang/article/details/52433966
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的申请退款的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。