admin
2024-07-27 65aaf1c05bd06cefa82ebc40cc3e01cf4ac233c0
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
package com.taoke.autopay;
 
import com.taoke.autopay.dto.DYOrderDto;
import com.taoke.autopay.entity.KeyOrder;
import com.taoke.autopay.entity.SystemConfigKeyEnum;
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.KeyOrderService;
import com.taoke.autopay.service.SystemConfigService;
import com.taoke.autopay.utils.AlipayOrderUtil;
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.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 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());
            }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("【支fu`寳】亲,复制 Q:/dYsUzQV77s5  p:/S ZH2412 2020/11/27打开支付宝就可以帮我🏮付款啦💪https://ur.alipay.com/_Ig4toHTlLHbBqiJqb3dpC");
        try {
            addKey(keyInfo, 1L);
        } 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();
        }
    }
 
}