微信支付獲取prepay_id以及回撥地址
/** * 微信獲取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("資料有誤")); resultMap.put("error_message", "資料有誤"); 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(); }
相關推薦
微信支付獲取prepay_id以及回撥地址
/** * 微信獲取prepay_id 同時下單 * * @return * @throws Exception */ @RequestMapping(value = "/getPrepayId", method = RequestMethod.G
(Web、觸屏)微信支付功能呼叫以及QQ回撥地址配置、以及遇到的一些坑
/** * (觸屏版)跳轉游記支付二維碼頁 (介面返回表單如下) * <form id="lolapaysubmit" name="lolapaysubmit" action="https://wx.tenpay.com/cgi-bin/mmpayweb-bin/c
PHP app 喚起微信支付 獲取鏈接【項目實例】
PHP App支付 微信支付 public function weixin_params_data(){ $data = $this->ApiData(); //獲取接口訪問的數據 //$_type = $post_data['type']; if(
微信支付 獲取RSA加密公鑰API JAVA版
UC val XML nonce 其中 final stack tps 下載 近做微信支付 企業付款到銀行卡,其中收款方銀行卡號、收款方用戶名需要獲取RSA加密公鑰API進行加密;本文以windows為例; 微信開發文檔地址:https://pay.weixin.qq.c
全面詳細的微信支付思路流程以及專案程式碼分享
之前一直沒有接觸微信支付這方面的業務,現在因專案需要,需要用到此功能,開始各種百度,稍微瞭解了一下,微信支付分為: 支付寶支付、APP支付、掃碼支付,但是對於H5支付和支付寶支付現在還是沒有徹底搞明白他兩的區別,希望大佬們可以稍微提點一二,小弟先在此謝過! 大體思路如下: 1】.獲取co
企業微信支付獲取Js_tiket報錯:invalid credential, access_token is invalid or not latest hint: [mxIF0455vr69!]
在企業微信支付中,獲取Js_tiket報invalid credential, access_token is invalid or not latest hint: [mxIF0455vr69!] 可能的原因是請求的URL錯誤,更換請求URL解決 原URL: https://a
微信支付APP端以及服務端(JavaEE)可以直接使用
最近在整合微信支付,不得不說微信文件就是坑,說的不明不白,還是支付寶簡單,流程:1、客戶端提交訂單——》到(自己平臺的)伺服器,引數與服務端協商2、服務端拿到請求訂單資訊——》參考微信統一下單介面——》把必須傳的引數進行加密轉XML傳到微信伺服器3、如果簽名正確,微信服務端會
解決整合微信第三方登入和分享回撥的衝突
這幾天做專案需要加入源生的微信登入和分享,我是先做的登入功能,在WXEntryActivity處理登入後的回撥,寫了很多邏輯,包括拿使用者資訊,上傳到伺服器等,過了幾天做微信分享,發現每次分享完成後點選返回應用,直接就閃退了,我就納悶了,為什麼會出現這樣的情況,
微信分享和登入共存 回撥函式不繼續執行的問題
前幾天做開發的時候 遇到了在專案中同時整合微信的登入和分享功能,剛開始登入功能是沒問題的 ,但是當弄分享的時候出了問題,當用戶分享之後點選返回APP會返回到一個空白頁面,只有當再次點選返回才會回到APP介面,斷點之後發現是因為這兩個功能都會呼叫微信WXEntryActivi
微信支付v3開發(6) 收貨地址共享接口
方式 word .com overflow rda over spa agent 電話 請看新版教程 微信支付開發(7) 收貨地址共享接口V2本文介紹微信支付下的收貨地址共享接口的開發過程。一. 簡單介紹微信收貨地址共享,是指用戶在微信瀏覽器內打開網頁,填寫過地址後,
微信支付v3開發(6) 收貨地址共享介面
請看新版教程 微信支付開發(7) 收貨地址共享介面V2 本文介紹微信支付下的收貨地址共享介面的開發過程。 一. 簡介 微信收貨地址共享,是指使用者在微信瀏覽器內開啟網頁,填寫過地址後,後續可以免填寫支援快速選擇,也可增加和編輯。此地址為使用者屬性,可在各商戶的網頁中
微信支付回撥遇到php7獲取資料失敗
微信的DEMO中對支付的回撥獲取資料是這麼處理的: $xml = $GLOBALS['HTTP_RAW_POST_DATA']; 近來部署到PHP7 發現回撥失效了,折騰好久發現XML是空的。在G上搜索了相關資料原來PHP7要使用下面的方法獲取。 $xml = file_get
JAVA微信掃碼支付模式二功能實現以及回撥
一、準備工作 首先吐槽一下微信關於支付這塊,本身支援的支付模式就好幾種,但是官方文件特別零散,連像樣的Java相關的demo也沒幾個。本人之前沒有搞過微信支付,一開始真是被它搞暈,折騰兩天終於調通了,特此寫下來,以享後人吧! 其中APP_ID和APP_SECRET可以在
PHP微信支付回撥獲取不到資料的解決辦法
接收回調資料可以用(提前是確保程式碼不存在BUG的情況下) $xml = $GLOBALS['HTTP_RAW_POST_DATA']; 或 $xml = file_get_contents('php://input'); 如果以上還是沒有進入回撥那麼就需要修改PHP環境
微信 支付非同步回撥 獲取引數值
import java.io.StringReader; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import
處理微信支付的非同步回撥
/** * 微信支付非同步回撥(只有非同步回撥對訂單進行處理) */ public function wchatUrlBack() { $postStr = file_get_contents('php://input'); i
淺析微信支付:申請退款、退款回撥介面、查詢退款
本文是【淺析微信支付】系列文章的第八篇,主要講解商戶如何處理微信申請退款、退款回撥、查詢退款介面,其中有一些坑的地方,會著重強調。 淺析微信支付系列已經更新七篇了喲~,沒有看過的朋友們可以看一下哦。 淺析微信支付:查詢訂單和關閉訂單 淺析微信支付:支付結果通知 淺析微信支付:統一下單介面
微信支付非同步回撥,帶你解決微信支付的深坑
1.首先我們先下載微信支付的伺服器端demo 2.個檔案作用介紹 index.jsp 下單 payRequest.jsp 獲取微信支付prepay_id等。 重點我說說這個payNotifyUrl.jsp
微信支付WXPayEntryActivity 不回撥
微信支付同步回撥不回撥問題記錄 1.微信支付官方文件 https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=8_5 第三方的東西都是比較簡單的,直接看官方文件就可以,無論支付寶支付還是微信支付,客戶端的工作量要小於服務端
微信支付統一下單的坑跟回撥地址程式碼示例
這裡我是把微信裡的回撥dome 拿出來重寫了一下, 在配置回撥地址的時候,要確定你的回撥連結地址一定要能夠訪問, 裡面註釋的比較多- -是我自己測試用的 也可以拿來作為參考, 配合上面一篇我寫的統一下單dome文章作為 結合來做,