Administrator
2025-02-17 7c733388b5e071fedd9b6b2ab4b000f0a5416784
口令提交过渡页
4个文件已修改
1个文件已添加
309 ■■■■■ 已修改文件
src/main/java/com/taoke/autopay/controller/WebApiController.java 111 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/taoke/autopay/manager/PayCountVerifyManager.java 46 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/static/index3.html 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/static/result.html 137 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/test/java/com/taoke/autopay/KeyTest.java 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/taoke/autopay/controller/WebApiController.java
@@ -9,6 +9,7 @@
import com.taoke.autopay.exception.KeyOrderException;
import com.taoke.autopay.exception.KeyVerifyException;
import com.taoke.autopay.exception.WxOrderCountException;
import com.taoke.autopay.manager.PayCountVerifyManager;
import com.taoke.autopay.service.KeyOrderService;
import com.taoke.autopay.service.SystemConfigService;
import com.taoke.autopay.service.WxUserService;
@@ -17,6 +18,7 @@
import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@@ -47,20 +49,22 @@
    @Resource
    private SystemConfigService systemConfigService;
    @Autowired
    private PayCountVerifyManager payCountVerifyManager;
    private void addKey(SubmitKeyInfo keyInfo, Long wxUid) throws KeyVerifyException, KeyOrderException, WxOrderCountException {
    private KeyOrder addKey(SubmitKeyInfo keyInfo, Long wxUid) throws KeyVerifyException, KeyOrderException, WxOrderCountException {
        // 查询没有处理的数量
        long notProcessCount = keyOrderService.countUserNotDoOrder(wxUid, new Date(System.currentTimeMillis() - 1000*60*30));
        if(notProcessCount>0){
        long notProcessCount = keyOrderService.countUserNotDoOrder(wxUid, new Date(System.currentTimeMillis() - 1000 * 60 * 30));
        if (notProcessCount > 0) {
            throw new WxOrderCountException("上一个口令尚未处理完!");
        }
        // 解析链接
        List<String> urllist = UrlUtils.parseUrlsFromText(keyInfo.getKey());
        String verifyAlipayKey = systemConfigService.getValueCache(SystemConfigKeyEnum.ALIPAY_KEY_VERIFY);
        DYOrderDto orderDto =null;
        DYOrderDto orderDto = null;
        int orderType = Constant.ORDER_TYPE_UNKNOWN;
        if (verifyAlipayKey != null && verifyAlipayKey.trim().equalsIgnoreCase("1")) {
            try {
@@ -97,7 +101,7 @@
                throw new KeyVerifyException(KeyVerifyException.CODE_COMMON, e.getMessage());
            }
        }
        KeyOrder order = keyOrderService.addKeyOrder(keyInfo, wxUid, TimeUtil.getGernalTime(System.currentTimeMillis(), Constant.DB_DAY_FORMAT),orderType, orderDto);
        KeyOrder order = keyOrderService.addKeyOrder(keyInfo, wxUid, TimeUtil.getGernalTime(System.currentTimeMillis(), Constant.DB_DAY_FORMAT), orderType, orderDto);
        Long uid = keyOrderService.getCanDistributeUid(Constant.MAX_PAY_ACCOUNT_QUEUE_SIZE);
        if (uid != null) {
            KeyOrder orderUpdate = new KeyOrder();
@@ -106,8 +110,7 @@
            orderUpdate.setDistributeTime(new Date());
            keyOrderService.update(orderUpdate);
        }
        return order;
    }
    private void verifySubmitKey(String key) throws Exception {
@@ -120,7 +123,8 @@
        }
    }
    private Map<String, IPUtil.IPInfo> ipInfoMap=new HashMap<>();
    private Map<String, IPUtil.IPInfo> ipInfoMap = new HashMap<>();
    @ResponseBody
    @RequestMapping(value = "submitKeyV4")
    public String submitKeyV4(SubmitKeyInfo keyInfo, HttpSession session, HttpServletRequest request) {
@@ -132,9 +136,9 @@
        }
        String ip = IPUtil.getRemotIP(request);
        keyInfo.setIp(ip);
        if(!ipInfoMap.containsKey(ip)){
        if (!ipInfoMap.containsKey(ip)) {
            try {
                IPUtil.IPInfo ipInfo =  IPUtil.getLocalIPInfo(ip);
                IPUtil.IPInfo ipInfo = IPUtil.getLocalIPInfo(ip);
                ipInfoMap.put(ip, ipInfo);
            } catch (Exception e) {
                throw new RuntimeException(e);
@@ -142,13 +146,13 @@
        }
        keyInfo.setIpInfo(ipInfoMap.get(ip));
        String citys =  systemConfigService.getValueCache(SystemConfigKeyEnum.FORBIDDEN_SUBMIT_CITYS);
        if(citys!=null&&ipInfoMap.get(ip)!=null){
           List<String> cityList = Arrays.asList(citys.split(","));
           if(cityList.contains(ipInfoMap.get(ip).getCity())){
               LogUtil.loggerDebug.warn("区域屏蔽:{}-{}", ip, new Gson().toJson(ipInfoMap.get(ip)));
               return JsonUtil.loadFalseResult("暂时无法上传口令");
           }
        String citys = systemConfigService.getValueCache(SystemConfigKeyEnum.FORBIDDEN_SUBMIT_CITYS);
        if (citys != null && ipInfoMap.get(ip) != null) {
            List<String> cityList = Arrays.asList(citys.split(","));
            if (cityList.contains(ipInfoMap.get(ip).getCity())) {
                LogUtil.loggerDebug.warn("区域屏蔽:{}-{}", ip, new Gson().toJson(ipInfoMap.get(ip)));
                return JsonUtil.loadFalseResult("暂时无法上传口令");
            }
        }
        try {
@@ -184,10 +188,12 @@
            return JsonUtil.loadTrueResult(Constant.RESULT_CODE_NEED_LOGIN, root);
        }
        wxLogger.info("微信有授权:" + session.getId());
        LogUtil.loggerDebug.warn("GEO信息:{}-{}-{}", user.getId(),ip, new Gson().toJson(ipInfoMap.get(ip)));
        LogUtil.loggerDebug.warn("GEO信息:{}-{}-{}", user.getId(), ip, new Gson().toJson(ipInfoMap.get(ip)));
        try {
            addKey(keyInfo, user.getId());
            return JsonUtil.loadTrueResult("");
            KeyOrder order = addKey(keyInfo, user.getId());
            JSONObject data = new JSONObject();
            data.put("id", order.getId());
            return JsonUtil.loadTrueResult(data);
        } catch (KeyOrderException e) {
            e.printStackTrace();
            return JsonUtil.loadFalseResult(e.getMessage());
@@ -246,9 +252,9 @@
                wxLogger.info("从session读取到key:{}", alipayKeyInfo);
                if (alipayKeyInfo != null) {
                    if(!ipInfoMap.containsKey(alipayKeyInfo.getIp())){
                    if (!ipInfoMap.containsKey(alipayKeyInfo.getIp())) {
                        try {
                            IPUtil.IPInfo ipInfo =  IPUtil.getLocalIPInfo(alipayKeyInfo.getIp());
                            IPUtil.IPInfo ipInfo = IPUtil.getLocalIPInfo(alipayKeyInfo.getIp());
                            ipInfoMap.put(alipayKeyInfo.getIp(), ipInfo);
                        } catch (Exception e) {
                            throw new RuntimeException(e);
@@ -260,7 +266,6 @@
                return;
            }
        } catch (Exception e) {
            e.printStackTrace();
            wxLogger.error("授权失败:{}", e.getMessage());
            if (!StringUtil.isNullOrEmpty(referer)) {
                Map<String, String> params = HttpUtil.getPramsFromUrl(referer);
@@ -271,4 +276,64 @@
        response.sendRedirect(failLink);
    }
    /**
     * 查询口令提交结果
     *
     * @param id
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "queryKeyResult")
    public String queryKeyResult(String id, HttpServletRequest request) {
        KeyOrder keyOrder = keyOrderService.selectById(id);
        if (keyOrder == null) {
            return JsonUtil.loadFalseResult("口令不存在");
        }
        String desc = "";
        switch (keyOrder.getState()) {
            case KeyOrder.STATE_NOT_PROCESS:
                if (keyOrder.getDistributeClientUid() == null) {
                    desc = "口令已提交,等待支付中...";
                } else {
                    desc = "支付排队中...";
                }
                break;
            case KeyOrder.STATE_NOT_PAY:
                desc = "正在支付...";
                break;
            case KeyOrder.STATE_PAY:
                desc = "支付成功";
                break;
            case KeyOrder.STATE_REJECT_PAY:
                desc = keyOrder.getStateDesc();
                break;
        }
        JSONObject data = new JSONObject();
        data.put("state_desc", desc);
        data.put("finish", keyOrder.getState() == KeyOrder.STATE_PAY || keyOrder.getState() == KeyOrder.STATE_REJECT_PAY ? 1 : 0);
        return JsonUtil.loadTrueResult(data);
    }
    /**
     * 查询支付剩余次数
     *
     * @param session
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "queryPayLeftCount")
    public String queryPayLeftCount(HttpSession session, HttpServletRequest request) {
        WxUserInfo user = (WxUserInfo) session.getAttribute(Constant.SESSION_KEY_USER);
        if (user == null || user.getId() == null) {
            return JsonUtil.loadFalseResult("用户尚未登录");
        }
        // 查询支付剩余次数
        Map<Integer, Long> map = payCountVerifyManager.computeUserLeftPayCount(user.getId());
        return JsonUtil.loadTrueResult(new Gson().toJson(map));
    }
}
src/main/java/com/taoke/autopay/manager/PayCountVerifyManager.java
@@ -10,6 +10,10 @@
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * 支付次数管理器
@@ -24,18 +28,19 @@
    private UserSettingService userSettingService;
    /**
     *  验证支付次数
     * 验证支付次数
     *
     * @param uid
     * @param orderType
     * @param orderChannel
     * @throws Exception
     */
    public void verifyPayCount(long uid, int orderType, OrderChannelEnum orderChannel) throws KeyOrderException {
        OrderCountTypeEnum orderCountType=null;
        if(orderType== Constant.ORDER_TYPE_DY){
            orderCountType=OrderCountTypeEnum.DY_ORDER_PAY;
        }else if(orderType==Constant.ORDER_TYPE_KS){
            orderCountType=OrderCountTypeEnum.KS_ORDER_PAY;
        OrderCountTypeEnum orderCountType = null;
        if (orderType == Constant.ORDER_TYPE_DY) {
            orderCountType = OrderCountTypeEnum.DY_ORDER_PAY;
        } else if (orderType == Constant.ORDER_TYPE_KS) {
            orderCountType = OrderCountTypeEnum.KS_ORDER_PAY;
        }
        long todayCount = wxUserOrderCountService.sum(uid, orderCountType, orderChannel, TimeUtil.getGernalTime(System.currentTimeMillis(), Constant.DB_DAY_FORMAT));
        long totalCount = wxUserOrderCountService.sum(uid, orderCountType, null, null);
@@ -45,5 +50,34 @@
        }
    }
    /**
     * 计算用户剩余支付次数
     *
     * @param uid
     */
    public Map<Integer,Long> computeUserLeftPayCount(Long uid) {
        Map<Integer,Long> map=new HashMap<>();
        OrderCountTypeEnum[] orderTypes = {OrderCountTypeEnum.DY_ORDER_PAY, OrderCountTypeEnum.KS_ORDER_PAY};
        OrderChannelEnum[] orderChannels = {OrderChannelEnum.cyx, OrderChannelEnum.bps, OrderChannelEnum.own};
        for (OrderCountTypeEnum type : orderTypes) {
            List<Long> countList=new ArrayList<>();
            for (OrderChannelEnum orderChannel : orderChannels) {
                long todayCount = wxUserOrderCountService.sum(uid, type, orderChannel, TimeUtil.getGernalTime(System.currentTimeMillis(), Constant.DB_DAY_FORMAT));
                long totalCount = wxUserOrderCountService.sum(uid, type, null, null);
                int maxPayCount = userSettingService.getLimitCountByTotalCount(type.getType(), totalCount, orderChannel);
                long leftCount = maxPayCount - todayCount;
                countList.add(leftCount);
            }
            long maxCount=0;
            for (Long count : countList) {
                if(count>maxCount){
                    maxCount=count;
                }
            }
            map.put(type.getType(),Math.min( maxCount, 50));
        }
        return map;
    }
}
src/main/resources/static/index3.html
@@ -99,6 +99,7 @@
                        if(response.code==0){
                            layer.msg("提交成功");
                             $(".edit").val("");
                             window.location.href ="result.html?id="+response.data.id;
                        } else if(response.code==1001){
                            window.location.replace(response.data.link);
                        }else{
src/main/resources/static/result.html
New file
@@ -0,0 +1,137 @@
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="width=device-width, viewport-fit=cover, initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>支付结果</title>
    <link rel="stylesheet" type="text/css" href="layui/css/layui.css"/>
    <script src="js/jquery.min.js"></script>
    <script src="layui/layui.js"></script>
    <style>
        body {
            background: #FFF;
        }
        .container {
            display: flex;
            align-items: center;
            flex-direction: column;
        }
        .btn {
            background-color: #FF2B4B;
            border-radius: 0.5rem;
            width: 80%;
            margin-top: 2rem;
            font-size: 1.2rem;
        }
        #result_desc {
            font-size: 1rem;
            color: red;
            margin-top: 0.2rem;
        }
        .left-count span{
            background-color: #FF2B4B;
            color: white;
            border-radius: 0.2rem;
            margin: 0.2rem;
            padding: 0 1rem;
        }
        .left-count{
            display: flex;
            justify-content: space-around;
            padding: 1rem 0;
            visibility: hidden;
        }
        .invalid{
            background-color: gray;
        }
    </style>
</head>
<body>
<div class="container">
    <div class="left-count">
        <span id="dy">抖音剩余--次</span>
        <span id="ks">快手剩余--次</span>
    </div>
    <div></div>
    <div style="display: block;width: 80%;padding: 2rem 0rem;">
        <div >提交结果:</div>
        <div id="result_desc"></div>
    </div>
    <button class="layui-btn btn invalid" >继续提交口令</button>
</div>
<script>
    $(function () {
        function getQueryString(name) {
            console.log(window.location.search)
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
            var r = window.location.search.substr(1).match(reg);
            if (r != null)
                return unescape(decodeURI(r[2]));
            return null;
        }
        function queryResult(id) {
            $.post("/webapi/queryKeyResult", {"id": id}, function (response) {
                if (response.code == 0) {
                    if (response.data.finish == 0) {
                        setTimeout(function () {
                            queryResult(id);
                        }, 2000);
                    }else{
                        $(".btn").removeClass("invalid");
                    }
                    $("#result_desc").html(response.data["state_desc"]);
                } else {
                    layer.msg(response.msg);
                }
            }, 'json').fail(function (jqXHR, textStatus, errorThrown) {
                layer.msg("网络请求失败");
            });
        }
        function queryPayLeftCount(){
            $.post("/webapi/queryPayLeftCount", {}, function (response) {
                if (response.code == 0) {
                 $("#dy").html( "抖音剩余"+ response.data["1"]+"次");
                 $("#ks").html( "快手剩余"+ response.data["2"]+"次");
                 $(".left-count").css("visibility","visible");
                }
            }, 'json').fail(function (jqXHR, textStatus, errorThrown) {
                layer.msg("网络请求失败");
            });
        }
        let id = getQueryString("id");
        queryResult(id);
        queryPayLeftCount();
        $(".btn").click(function () {
            if(!$(".btn").hasClass("invalid"))
            {
                history.go(-1);
            }
        });
    });
</script>
</body>
</html>
src/test/java/com/taoke/autopay/KeyTest.java
@@ -1,5 +1,6 @@
package com.taoke.autopay;
import com.google.gson.Gson;
import com.taoke.autopay.dao.KeyOrderMapper;
import com.taoke.autopay.dto.DYOrderDto;
import com.taoke.autopay.entity.KeyOrder;
@@ -10,9 +11,11 @@
import com.taoke.autopay.exception.KeyVerifyException;
import com.taoke.autopay.exception.WxOrderCountException;
import com.taoke.autopay.manager.OrderPayFailProcessor;
import com.taoke.autopay.manager.PayCountVerifyManager;
import com.taoke.autopay.service.*;
import com.taoke.autopay.utils.AlipayOrderUtil;
import com.taoke.autopay.utils.Constant;
import com.taoke.autopay.utils.JsonUtil;
import com.taoke.autopay.utils.TimeUtil;
import com.taoke.autopay.vo.SubmitKeyInfo;
import org.junit.jupiter.api.Test;
@@ -23,6 +26,7 @@
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
 * @author hxh
@@ -194,5 +198,15 @@
        System.out.println(notProcessCount);
    }
    @Resource
    private PayCountVerifyManager payCountVerifyManager;
    @Test
    public void test4(){
        Long uid = 2L;
        Map<Integer,Long> map =  payCountVerifyManager.computeUserLeftPayCount(uid);
       System.out.println(new Gson().toJson(map));
    }
}