From 8da49e321c1b5269ce75e529e9f0aedd3872446f Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期四, 17 九月 2020 11:53:11 +0800
Subject: [PATCH] 优化支付

---
 service-front/src/main/java/com/java110/front/smo/AppAbstractComponentSMO.java |   42 +++++++++++++++++++++++++++++++++++-------
 1 files changed, 35 insertions(+), 7 deletions(-)

diff --git a/service-front/src/main/java/com/java110/front/smo/AppAbstractComponentSMO.java b/service-front/src/main/java/com/java110/front/smo/AppAbstractComponentSMO.java
index 4b2255d..1a48a89 100644
--- a/service-front/src/main/java/com/java110/front/smo/AppAbstractComponentSMO.java
+++ b/service-front/src/main/java/com/java110/front/smo/AppAbstractComponentSMO.java
@@ -14,11 +14,7 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.HttpEntity;
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.HttpMethod;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.ResponseEntity;
+import org.springframework.http.*;
 import org.springframework.web.client.HttpStatusCodeException;
 import org.springframework.web.client.RestTemplate;
 
@@ -91,6 +87,22 @@
                                                  String feeName, String tradeType,
                                                  String orderNum, double money,
                                                  String openId, SmallWeChatDto smallWeChatDto) throws Exception {
+        return java110Payment(outRestTemplate, feeName, tradeType, orderNum, money, openId, smallWeChatDto, "");
+    }
+
+    /**
+     * 棰勪笅鍗�
+     *
+     * @param orderNum
+     * @param money
+     * @param openId
+     * @return
+     * @throws Exception
+     */
+    protected Map<String, String> java110Payment(RestTemplate outRestTemplate,
+                                                 String feeName, String tradeType,
+                                                 String orderNum, double money,
+                                                 String openId, SmallWeChatDto smallWeChatDto, String notifyUrl) throws Exception {
         logger.info("銆愬皬绋嬪簭鏀粯銆� 缁熶竴涓嬪崟寮�濮�, 璁㈠崟缂栧彿=" + orderNum);
         SortedMap<String, String> resultMap = new TreeMap<String, String>();
 //鐢熸垚鏀粯閲戦锛屽紑鍙戠幆澧冨鐞嗘敮浠橀噾棰濇暟鍒�0.01銆�0.02銆�0.03鍏�
@@ -98,7 +110,14 @@
         double payAmount = PayUtil.getPayAmountByEnv(MappingCache.getValue("HC_ENV"), money);
 //娣诲姞鎴栨洿鏂版敮浠樿褰�(鍙傛暟璺熻繘鑷繁涓氬姟闇�姹傛坊鍔�)
 
-        Map<String, String> resMap = this.java110UnifieldOrder(outRestTemplate, feeName, orderNum, tradeType, payAmount, openId, smallWeChatDto);
+        Map<String, String> resMap = null;
+
+        if (StringUtil.isEmpty(notifyUrl)) {
+            resMap = this.java110UnifieldOrder(outRestTemplate, feeName, orderNum, tradeType, payAmount, openId, smallWeChatDto);
+        } else {
+            resMap = this.java110UnifieldOrder(outRestTemplate, feeName, orderNum, tradeType, payAmount, openId, smallWeChatDto, notifyUrl);
+        }
+
         if ("SUCCESS".equals(resMap.get("return_code")) && "SUCCESS".equals(resMap.get("result_code"))) {
             if (WechatAuthProperties.TRADE_TYPE_JSAPI.equals(tradeType)) {
 
@@ -137,6 +156,15 @@
     private Map<String, String> java110UnifieldOrder(RestTemplate outRestTemplate, String feeName, String orderNum,
                                                      String tradeType, double payAmount, String openid,
                                                      SmallWeChatDto smallWeChatDto) throws Exception {
+        return java110UnifieldOrder(outRestTemplate, feeName, orderNum, tradeType, payAmount, openid, smallWeChatDto, wechatAuthProperties.getWxNotifyUrl());
+    }
+
+    /**
+     * 灏忕▼搴忔敮浠樼粺涓�涓嬪崟
+     */
+    private Map<String, String> java110UnifieldOrder(RestTemplate outRestTemplate, String feeName, String orderNum,
+                                                     String tradeType, double payAmount, String openid,
+                                                     SmallWeChatDto smallWeChatDto, String notifyUrl) throws Exception {
 
         String systemName = MappingCache.getValue(WechatConstant.WECHAT_DOMAIN, WechatConstant.PAY_GOOD_NAME);
 
@@ -148,7 +176,7 @@
         paramMap.put("out_trade_no", orderNum);
         paramMap.put("total_fee", PayUtil.moneyToIntegerStr(payAmount));
         paramMap.put("spbill_create_ip", PayUtil.getLocalIp());
-        paramMap.put("notify_url", wechatAuthProperties.getWxNotifyUrl() + "?wId=" + WechatFactory.getWId(smallWeChatDto.getAppId()));
+        paramMap.put("notify_url", notifyUrl + "?wId=" + WechatFactory.getWId(smallWeChatDto.getAppId()));
         paramMap.put("trade_type", tradeType);
         paramMap.put("openid", openid);
 

--
Gitblit v1.8.0