Administrator
2025-02-09 696a46908ba2e824dacb115377ed14d44857b307
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
package com.taoke.autopay;
 
import com.taoke.autopay.dao.KeyOrderMapper;
import com.taoke.autopay.dto.DYOrderDto;
import com.taoke.autopay.entity.KeyOrder;
import com.taoke.autopay.entity.OrderCountTypeEnum;
import com.taoke.autopay.entity.SystemConfigKeyEnum;
import com.taoke.autopay.entity.WxUserSettings;
import com.taoke.autopay.exception.KeyOrderException;
import com.taoke.autopay.exception.KeyVerifyException;
import com.taoke.autopay.exception.WxOrderCountException;
import com.taoke.autopay.manager.OrderPayFailProcessor;
import com.taoke.autopay.service.*;
import com.taoke.autopay.utils.AlipayOrderUtil;
import com.taoke.autopay.utils.Constant;
import com.taoke.autopay.utils.TimeUtil;
import com.taoke.autopay.vo.SubmitKeyInfo;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.yeshi.utils.UrlUtils;
 
import javax.annotation.Resource;
import java.util.Collections;
import java.util.Date;
import java.util.List;
 
/**
 * @author hxh
 * @title: KeyTest
 * @description: TODO
 * @date 2024/7/24 6:56
 */
@SpringBootTest
public class KeyTest {
 
    @Resource
    private SystemConfigService systemConfigService;
 
 
    @Resource
    private KeyOrderService keyOrderService;
 
    @Resource
    private KeyOrderMapper keyOrderMapper;
 
    @Resource
    private OrderPayFailProcessor orderPayFailProcessor;
 
    private void addKey(SubmitKeyInfo keyInfo, Long wxUid) throws KeyVerifyException, KeyOrderException, WxOrderCountException {
        // 解析链接
        List<String> urllist = UrlUtils.parseUrlsFromText(keyInfo.getKey());
 
 
        String verifyAlipayKey = systemConfigService.getValueCache(SystemConfigKeyEnum.ALIPAY_KEY_VERIFY);
        if (verifyAlipayKey != null && verifyAlipayKey.trim().equalsIgnoreCase("1") || true) {
            try {
                // 需要验证支付宝口令
                if (urllist.size() < 1) {
                    throw new Exception("口令中不包含链接");
                }
                AlipayOrderUtil.AlipayOrderTradeInfo tradeInfo = AlipayOrderUtil.getTradeInfo(urllist.get(0));
                String orderStatus = "";
                switch (tradeInfo.getStatus()) {
                    case AlipayOrderUtil.AlipayOrderTradeInfo.STATUS_CANCELED:
                        orderStatus = "订单已取消";
                        break;
                    case AlipayOrderUtil.AlipayOrderTradeInfo.STATUS_PAY:
                        orderStatus = "订单已支付";
                        break;
                    case AlipayOrderUtil.AlipayOrderTradeInfo.STATUS_NOT_PAY:
                        orderStatus = "订单未支付";
                        break;
                }
 
 
                if (tradeInfo == null) {
                    throw new Exception("口令内容获取失败");
                }
                // 验证内容
                DYOrderDto dto = keyOrderService.verifyKey(tradeInfo.getGoodsTitle(), orderStatus, tradeInfo.getItemRealAmount(),null, null);
            } catch (KeyVerifyException ee) {
                throw ee;
            } catch (Exception e) {
                throw new KeyVerifyException(KeyVerifyException.CODE_COMMON, e.getMessage());
            }
        }
    }
 
    @Test
    public void test1() {
        SubmitKeyInfo keyInfo = new SubmitKeyInfo();
        keyInfo.setKey("【支.f.u.宝】亲,复制 m:/AYyvvyJ32pG  Y:/e CA8474 2021/01/18打开支付宝\uD83C\uDFEE就可以帮我\uD83C\uDFEE付款啦\uD83C\uDFEEhttps://ur.alipay.com/_1kIJISKdMN6PREE9laoYWS");
        try {
            addKey(keyInfo, 1L);
            KeyOrder keyOrder=new KeyOrder();
            keyOrder.setId("test21123123");
            keyOrder.setKey(keyInfo.getKey());
            keyOrderMapper.insertSelective(keyOrder);
        } catch (KeyVerifyException e) {
            e.printStackTrace();
        } catch (KeyOrderException e) {
            e.printStackTrace();
        } catch (WxOrderCountException e) {
            e.printStackTrace();
        }
    }
 
    @Test
    public void testRePay() throws InterruptedException {
        for (int i = 0; i < 10; i++) {
            orderPayFailProcessor.processPayFail("2c9d0dd55cd845819c8e6010fe10def4", "读取支付宝粘贴板超时");
            Thread.sleep(2000);
            orderPayFailProcessor.processFromQueue();
        }
    }
 
    @Test
    public void statisticAgentId() {
        KeyOrderMapper.DaoQuery query=new KeyOrderMapper.DaoQuery();
        query.hasAgentId=true;
        query.hasPayTime = true;
        query.state =2;
        query.count = 100;
 
        List<Long> list =   keyOrderService.listAgentId(query);
        System.out.println(list);
    }
 
    @Test
    public void repaire(){
        KeyOrderMapper.DaoQuery query=new KeyOrderMapper.DaoQuery();
        query.state=3;
        query.minCreateTime=new Date(TimeUtil.convertToTimeTemp("2024-08-02","yyyy-MM-dd"));
        query.stateDesc="订单已支付";
        query.count = 1000;
        List<KeyOrder>  list =  keyOrderService.list(query);
        for(KeyOrder o:list){
            KeyOrder update=new KeyOrder();
            update.setId(o.getId());
            update.setState(KeyOrder.STATE_PAY);
            update.setPayTime(o.getExcutePayTime());
            keyOrderService.update(update);
        }
 
    }
 
    @Resource
    private ClientInfoService clientInfoService;
 
    @Test
    public void test2(){
        List<Long> clientIds = clientInfoService.getRePayClientIds();
        if (clientIds!=null&&clientIds.size()>0) {
            Collections.shuffle(clientIds);
            // 查询设备未执行的数量
            for(Long cuid:clientIds) {
                KeyOrderMapper.DaoQuery daoQuery = new KeyOrderMapper.DaoQuery();
                daoQuery.distributeClientUid =cuid;
                daoQuery.state =  KeyOrder.STATE_NOT_PAY;
                daoQuery.minCreateTime=new Date(System.currentTimeMillis() - 1000*60*30L);
                long count =  keyOrderService.count(daoQuery);
                if(count <=1){
                    // 分配
                    System.out.println( cuid);
                }
            }
        }
 
 
    }
 
    @Resource
    private WxUserSettingService wxUserSettingService;
 
    @Resource
    private WxUserOrderCountService wxUserOrderCountService;
 
    @Test
    public void testCount() throws Exception{
 
 
    }
 
    @Test
    public void testSettle(){
        keyOrderService.statisticChannelOrders(5L,new Date(TimeUtil.convertToTimeTemp("20240809","yyyyMMdd")),new Date(TimeUtil.convertToTimeTemp("20240810","yyyyMMdd")));
    }
 
 
    @Test
    public void testOrderCount(){
        long wxUid = 15834L;
        long notProcessCount = keyOrderService.countUserNotDoOrder(wxUid, new Date(System.currentTimeMillis() - 1000*60*300));
        System.out.println(notProcessCount);
    }
 
 
}