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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

微信支付获取prepay_id以及回调地址

發(fā)布時間:2023/12/14 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 微信支付获取prepay_id以及回调地址 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
/*** 微信獲取prepay_id 同時下單* * @return* @throws Exception*/@RequestMapping(value = "/getPrepayId", method = RequestMethod.GET)public @ResponseBody Map<String, Object> getPrepayId(HttpServletRequest request, String sn) throws Exception {Map<String, Object> resultMap = new HashMap<String, Object>();Order order = orderService.findBySn(sn);System.out.println("sn==========="+sn);Member member = memberService.getCurrent();if (order == null || !member.equals(order.getMember()) || order.getPaymentMethod() == null|| order.getAmountPayable().compareTo(BigDecimal.ZERO) <= 0) {System.out.println(ERROR_VIEW);resultMap.put("error_message", ERROR_VIEW);resultMap.put("success", 1);return resultMap;}if (PaymentMethod.Method.online.equals(order.getPaymentMethod().getMethod())) {if (orderService.isLocked(order, member, true)) {System.out.println(Message.warn("shop.order.locked"));resultMap.put("error_message", Message.warn("shop.order.locked"));resultMap.put("success", 1);return resultMap;}PaymentPlugin paymentPlugin = pluginService.getPaymentPlugin("wxpayPubPaymentPlugin");if (paymentPlugin != null) {if (paymentPlugin == null || !paymentPlugin.getIsEnabled()) {System.out.println(ERROR_VIEW);resultMap.put("error_message", ERROR_VIEW);resultMap.put("success", 1);return resultMap;}// 添加支付記錄PaymentLog paymentLogtmp = paymentLogService.findBySn(order.getSn());System.out.println("sn==========="+order.getSn());System.out.println("paymentLogtmp==========="+paymentLogtmp);if(paymentLogtmp==null){PaymentLog paymentLog = new PaymentLog();paymentLog.setSn(order.getSn());paymentLog.setType(PaymentLog.Type.payment);paymentLog.setStatus(PaymentLog.Status.wait);paymentLog.setFee(paymentPlugin.calculateFee(order.getAmountPayable()));paymentLog.setAmount(paymentPlugin.calculateAmount(order.getAmountPayable()));paymentLog.setPaymentPluginId(paymentPlugin.getId());paymentLog.setPaymentPluginName(paymentPlugin.getName());paymentLog.setMember(member);paymentLog.setOrder(order);paymentLogService.save(paymentLog);}Map<String, String> paramMap = new HashMap<String, String>();paramMap.put("out_trade_no", order.getSn());paramMap.put("total_fee",order.getAmount() != null ? paymentPlugin.calculateAmount(order.getAmountPayable()).multiply(new BigDecimal("100")).toBigInteger().toString() : "0");paramMap.put("openid", member.getOpenId());String paramXms =CommonPayment.getPrepayIdParam(request, paramMap).toString();String str = HttpRequest.sendPost(CommonWeChat.PAYMENT_GET_PREPAYID_URL, paramXms);str = str.replaceAll("<![CDATA[|]]>", "");SortedMap<String, String> dataMap = CommonPayment.xmlToMap(str);SortedMap<String, String> data = new TreeMap<String, String>();if (dataMap.get("return_code").equalsIgnoreCase("SUCCESS")&& dataMap.get("result_code").equalsIgnoreCase("SUCCESS")) {data.put("appId", CommonWeChat.APPID.trim());data.put("timeStamp", Sha1Util.getTimeStamp().trim());data.put("nonceStr", Sha1Util.getNonceStr().trim());data.put("package", "prepay_id=" + dataMap.get("prepay_id").trim());data.put("signType", CommonWeChat.SIGNTYPE.trim());data.put("paySign", CommonPayment.getMD5Sign(data).trim());resultMap.put("success", 0);resultMap.put("resultData", data);} else if (dataMap.get("return_code").equalsIgnoreCase("FAIL")) {System.out.println(dataMap.get("return_msg"));resultMap.put("error_message", dataMap.get("return_msg"));resultMap.put("success", 1);} else if (dataMap.get("result_code").equalsIgnoreCase("FAIL")) {System.out.println(dataMap.get("err_code_des"));resultMap.put("error_message", dataMap.get("err_code_des"));resultMap.put("success", 1);} else {System.out.println(dataMap.get("數(shù)據(jù)有誤"));resultMap.put("error_message", "數(shù)據(jù)有誤");resultMap.put("success", 1);}} else {System.out.println(ERROR_VIEW);resultMap.put("error_message", ERROR_VIEW);resultMap.put("success", 1);return resultMap;}}return resultMap;}@RequestMapping(value = "/m_weixinNotify")public String m_weixinNotify(String sn, HttpServletRequest request, ModelMap model) {System.out.println("sn====="+sn);PaymentLog paymentLog = paymentLogService.findBySn(sn);System.out.println("paymentLog====="+paymentLog);model.addAttribute("paymentLog", paymentLog);return "payment/plugin_notify";}/*** 微信支付成功通知* * @return* @throws Exception*/@RequestMapping(value = "/paySuccess")public void paySuccess(HttpServletRequest request, HttpServletResponse response) throws Exception {System.out.println("paySuccess: begin\n");try {ServletInputStream in = request.getInputStream();StringBuffer buff = new StringBuffer();try {byte[] b = new byte[4096];for (int length; (length = in.read(b)) != -1;) {buff.append(new String(b, 0, length));}} catch (IOException e) {System.out.println("streamToString : === " + e.getMessage());buff = buff.delete(0, buff.length());e.printStackTrace();}String result = buff.toString();System.out.println("result:== " + result);System.out.println("xStreamUtil begin...");if (result != null && !result.equals("")) {Map<String, String> map = CommonPayment.xmlToMap(result);System.out.println("map:" + map);for (Object keyValue : map.keySet()) { // System.out.println(keyValue + "=" + map.get(keyValue));}System.out.println("result_code:" + map.get("result_code").equalsIgnoreCase("SUCCESS"));if (map.get("result_code").equalsIgnoreCase("SUCCESS")) { // String sign = CommonPayment.SuccessSign(map, CommonWeChat.MCH_KEY); // System.out.println("215 sign=" + map.get("sign") + " APP_PAYKRY=" + sign); // if (sign != null && map.get("sign").equals(sign)) {String out_trade_no = map.get("out_trade_no");String total_fee = map.get("total_fee");//處理訂單sendToCFT("<xml><return_code><![CDATA[SUCCESS]]></return_code></xml>", response); // }}}sendToCFT("<xml><return_code><![CDATA[FAIL]]></return_code></xml>", response);} catch (Exception ex) {System.out.println("paySuccess Exception = " + ex.getMessage());ex.printStackTrace();}System.out.println("paySuccess === end\n");}public void sendToCFT(String msg, HttpServletResponse response) throws IOException {String strHtml = msg;PrintWriter out = response.getWriter();out.println(strHtml);out.flush();out.close();}

總結(jié)

以上是生活随笔為你收集整理的微信支付获取prepay_id以及回调地址的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。