From 6927d3bed414fb1a44312668d4e9d91d62e91b3f Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期二, 09 七月 2024 00:43:50 +0800
Subject: [PATCH] 口令付款不依赖与订单

---
 src/main/java/com/taoke/autopay/controller/WebApiController.java |  101 ++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 89 insertions(+), 12 deletions(-)

diff --git a/src/main/java/com/taoke/autopay/controller/WebApiController.java b/src/main/java/com/taoke/autopay/controller/WebApiController.java
index a01d79a..094cfda 100644
--- a/src/main/java/com/taoke/autopay/controller/WebApiController.java
+++ b/src/main/java/com/taoke/autopay/controller/WebApiController.java
@@ -12,6 +12,8 @@
 import com.taoke.autopay.service.WxUserOrderCountService;
 import com.taoke.autopay.service.WxUserService;
 import com.taoke.autopay.utils.*;
+import com.taoke.autopay.vo.SubmitKeyInfo;
+import net.sf.json.JSONArray;
 import net.sf.json.JSONObject;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -25,8 +27,11 @@
 import javax.servlet.http.HttpSession;
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.math.BigDecimal;
 import java.util.Date;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 @Controller
 @RequestMapping("webapi")
@@ -59,7 +64,7 @@
             return JsonUtil.loadFalseResult("鏀粯瀹濆彛浠や笉姝g‘");
         }
         try {
-            KeyOrder order = keyOrderService.addKeyOrder(key, null, TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyyMMdd"));
+            KeyOrder order = keyOrderService.addKeyOrder(new SubmitKeyInfo(key), null, TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyyMMdd"));
             Long uid = keyOrderService.getCanDistributeUid();
             if (uid != null) {
                 KeyOrder orderUpdate = new KeyOrder();
@@ -77,8 +82,8 @@
         }
     }
 
-    private void addKey(String key, Long wxUid) throws KeyOrderException, WxOrderCountException {
-        KeyOrder order = keyOrderService.addKeyOrder(key, wxUid, TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyyMMdd"));
+    private void addKey(SubmitKeyInfo keyInfo, Long wxUid) throws KeyOrderException, WxOrderCountException {
+        KeyOrder order = keyOrderService.addKeyOrder(keyInfo, wxUid, TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyyMMdd"));
         Long uid = keyOrderService.getCanDistributeUid();
         if (uid != null) {
             KeyOrder orderUpdate = new KeyOrder();
@@ -93,12 +98,12 @@
 
     @ResponseBody
     @RequestMapping(value = "submitKeyV2")
-    public String submitKeyV2(String key, HttpSession session) {
+    public String submitKeyV2(SubmitKeyInfo keyInfo, HttpSession session) {
         WxUserInfo user = (WxUserInfo) session.getAttribute(Constant.SESSION_KEY_USER);
-        if (StringUtil.isNullOrEmpty(key)) {
+        if (StringUtil.isNullOrEmpty(keyInfo.getKey())) {
             return JsonUtil.loadFalseResult(0, "璇蜂笂浼爇ey");
         }
-        List<String> urllist = UrlUtils.parseUrlsFromText(key);
+        List<String> urllist = UrlUtils.parseUrlsFromText(keyInfo.getKey());
         if (urllist.isEmpty() || !urllist.get(0).contains("ur.alipay.com")) {
             return JsonUtil.loadFalseResult("鏀粯瀹濆彛浠や笉姝g‘");
         }
@@ -106,7 +111,7 @@
         if (user == null) {
             // 鍏堜繚瀛楰EY
 //            SESSION_KEY_TEMP_ALIPAY_KEY
-            session.setAttribute(Constant.SESSION_KEY_TEMP_ALIPAY_KEY, key);
+            session.setAttribute(Constant.SESSION_KEY_TEMP_ALIPAY_KEY, keyInfo);
             wxLogger.info("寰俊娌℃湁鎺堟潈:" + session.getId());
             String redictLink = systemConfigService.getValueCache(SystemConfigKeyEnum.WX_REDIRECT_LINK);
             if (StringUtil.isNullOrEmpty(redictLink)) {
@@ -120,7 +125,79 @@
         wxLogger.info("寰俊鏈夋巿鏉�:" + session.getId());
 
         try {
-            addKey(key, user.getId());
+            addKey(keyInfo, user.getId());
+            return JsonUtil.loadTrueResult("");
+        } catch (KeyOrderException e) {
+            e.printStackTrace();
+            return JsonUtil.loadFalseResult(e.getMessage());
+        } catch (WxOrderCountException e) {
+            return JsonUtil.loadFalseResult(e.getMessage());
+        }
+    }
+
+    /**
+     * @author hxh
+     * @description 甯﹀彛浠や笌閲戦鐨勫彛浠ゆ彁浜ゆ帴鍙�
+     * @date 0:12 2024/7/9
+     * @param: keyInfo
+     * @param: session
+     * @return java.lang.String
+     **/
+    @ResponseBody
+    @RequestMapping(value = "submitKeyV3")
+    public String submitKeyV3(SubmitKeyInfo keyInfo, HttpSession session) {
+        WxUserInfo user = (WxUserInfo) session.getAttribute(Constant.SESSION_KEY_USER);
+        if (StringUtil.isNullOrEmpty(keyInfo.getKey())) {
+            return JsonUtil.loadFalseResult(0, "璇蜂笂浼爇ey");
+        }
+        if (StringUtil.isNullOrEmpty(keyInfo.getMoney())) {
+            return JsonUtil.loadFalseResult(0, "璇蜂笂浼爉oney");
+        }
+        List<String> urllist = UrlUtils.parseUrlsFromText(keyInfo.getKey());
+        if (urllist.isEmpty() || !urllist.get(0).contains("ur.alipay.com")) {
+            return JsonUtil.loadFalseResult("鏀粯瀹濆彛浠や笉姝g‘");
+        }
+        // 楠岃瘉鎻愪氦鏃堕棿
+        String timeStr =  systemConfigService.getValueCache(SystemConfigKeyEnum.KEY_SUBMIT_TIME_RANGE);
+        if(StringUtil.isNullOrEmpty(timeStr)){
+            return JsonUtil.loadFalseResult("灏氭湭閰嶇疆鐢熸晥鏃堕棿");
+        }
+        String startTime = timeStr.split(",")[0].trim().replace(":","");
+        String endTime = timeStr.split(",")[1].trim().replace(":","");
+        String now = TimeUtil.getGernalTime(System.currentTimeMillis(),"HHmmss");
+        if(Integer.parseInt(now)<Integer.parseInt(startTime)||Integer.parseInt(now)>Integer.parseInt(endTime)){
+            return JsonUtil.loadFalseResult(String.format("鍙d护鎻愪氦鏃堕棿娈典负锛�%s-%s",timeStr.split(",")[0],timeStr.split(",")[1]));
+        }
+        // 楠岃瘉鎻愪氦鐨勯噾棰濇槸鍚︽纭�
+       String moneyStr =  systemConfigService.getValueCache(SystemConfigKeyEnum.PAY_MONEY_LIST);
+       if(StringUtil.isNullOrEmpty(moneyStr)){
+           return JsonUtil.loadFalseResult("灏氭湭閰嶇疆閲戦");
+       }
+       JSONArray array=JSONArray.fromObject(moneyStr);
+       Set<String> moneySet=new HashSet<>();
+       for(int i=0;i<array.size();i++){
+           moneySet.add(MoneyUtil.getMoneyStr(new BigDecimal(array.optString(i))));
+       }
+        if(!moneySet.contains(MoneyUtil.getMoneyStr(new BigDecimal(keyInfo.getMoney())))){
+            return JsonUtil.loadFalseResult("鎻愪氦閲戦涓嶇鍚堣姹�");
+        }
+        if (user == null) {
+            // 鍏堜繚瀛楰EY
+//            SESSION_KEY_TEMP_ALIPAY_KEY
+            session.setAttribute(Constant.SESSION_KEY_TEMP_ALIPAY_KEY, keyInfo);
+            wxLogger.info("寰俊娌℃湁鎺堟潈:" + session.getId());
+            String redictLink = systemConfigService.getValueCache(SystemConfigKeyEnum.WX_REDIRECT_LINK);
+            if (StringUtil.isNullOrEmpty(redictLink)) {
+                return JsonUtil.loadFalseResult("鏃犳硶鑾峰彇鍒版巿鏉冮摼鎺�");
+            }
+            // 娌℃湁鐧诲綍锛岃繑鍥炵櫥褰曢摼鎺�
+            JSONObject root = new JSONObject();
+            root.put("link", redictLink);
+            return JsonUtil.loadTrueResult(Constant.RESULT_CODE_NEED_LOGIN, root);
+        }
+        wxLogger.info("寰俊鏈夋巿鏉�:" + session.getId());
+        try {
+            addKey(keyInfo, user.getId());
             return JsonUtil.loadTrueResult("");
         } catch (KeyOrderException e) {
             e.printStackTrace();
@@ -143,10 +220,10 @@
                 WxUserInfo user = wxUserService.login(tokenInfo.getOpenid());
                 session.setAttribute(Constant.SESSION_KEY_USER, user);
                 wxLogger.info("寰俊淇濆瓨鐢ㄦ埛淇℃伅锛歿} id-{}", session.getId(), user.getId());
-                String alipayKey = (String) session.getAttribute(Constant.SESSION_KEY_TEMP_ALIPAY_KEY);
-                wxLogger.info("浠巗ession璇诲彇鍒発ey锛歿}", alipayKey);
-                if (alipayKey != null) {
-                    addKey(alipayKey, user.getId());
+                SubmitKeyInfo alipayKeyInfo = (SubmitKeyInfo) session.getAttribute(Constant.SESSION_KEY_TEMP_ALIPAY_KEY);
+                wxLogger.info("浠巗ession璇诲彇鍒発ey锛歿}", alipayKeyInfo);
+                if (alipayKeyInfo != null) {
+                    addKey(alipayKeyInfo, user.getId());
                 }
                 response.sendRedirect(successLink);
                 return;

--
Gitblit v1.8.0