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
package com.hxh.spring.test.vip;
 
import com.yeshi.buwan.domain.vip.UserVIPInfo;
import com.yeshi.buwan.domain.vip.VIPOrderRecord;
import com.yeshi.buwan.domain.vip.VIPPrice;
import com.yeshi.buwan.domain.vip.VIPPriceType;
import com.yeshi.buwan.exception.vip.VIPException;
import com.yeshi.buwan.pptv.PPTVVipManager;
import com.yeshi.buwan.service.inter.vip.VIPPriceService;
import com.yeshi.buwan.service.inter.vip.VIPService;
import com.yeshi.buwan.util.Constant;
import com.yeshi.buwan.util.HttpUtil;
import com.yeshi.buwan.util.log.LoggerUtil;
import com.yeshi.buwan.util.user.VipUtil;
import com.yeshi.buwan.util.vip.VIPOrderUtil;
import net.sf.json.JSONObject;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.yeshi.utils.entity.wx.WXAPPInfo;
 
import javax.annotation.Resource;
import javax.crypto.Cipher;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.GCMParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.io.IOException;
import java.math.BigDecimal;
import java.security.GeneralSecurityException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;
import java.util.Date;
import java.util.List;
 
@RunWith(SpringJUnit4ClassRunner.class) //使用junit4进行测试
@ContextConfiguration(locations = {"classpath:spring.xml"})
@WebAppConfiguration
public class VIPTest {
 
    @Resource
    private VIPPriceService vipPriceService;
 
    @Resource
    private VIPService vipService;
 
    @Resource
    private PPTVVipManager pptvVipManager;
 
    @Test
    public void addVIPPrice() {
        VIPPrice price = new VIPPrice();
        price.setPrice(new BigDecimal("14.8"));
        price.setType(VIPPriceType.month);
        price.setPptvGoodsNo("DA7559531560894");
        price.setShow(true);
        try {
            vipPriceService.addPrice(price);
        } catch (VIPException e) {
            e.printStackTrace();
        }
 
        price = new VIPPrice();
        price.setPrice(new BigDecimal("37.8"));
        price.setType(VIPPriceType.season);
        price.setPptvGoodsNo("DA7559574625089");
        price.setShow(true);
        try {
            vipPriceService.addPrice(price);
        } catch (VIPException e) {
            e.printStackTrace();
        }
 
 
        price = new VIPPrice();
        price.setPrice(new BigDecimal("68.8"));
        price.setType(VIPPriceType.halfYear);
        price.setPptvGoodsNo("DA6989580247516");
        price.setShow(true);
        try {
            vipPriceService.addPrice(price);
        } catch (VIPException e) {
            e.printStackTrace();
        }
 
 
        price = new VIPPrice();
        price.setPrice(new BigDecimal("128.8"));
        price.setType(VIPPriceType.year);
        price.setPptvGoodsNo("DA8129574268091");
        price.setShow(true);
        try {
            vipPriceService.addPrice(price);
        } catch (VIPException e) {
            e.printStackTrace();
        }
    }
 
 
    @Test
    public void listVIPPrice() {
        List<VIPPrice> list = vipPriceService.listValidPrice();
        System.out.println(list);
    }
 
 
    @Test
    public void addOrderRecord() {
        VIPPrice price = vipPriceService.selectByPrimaryKey("172a8327fcd3685ab3c0f740d031da09");
        VIPOrderRecord record = new VIPOrderRecord();
        record.setMoney(price.getPrice());
        record.setType(price.getType());
        record.setUid(766693 + "");
 
        try {
            vipService.addVIPRecord(record);
        } catch (VIPException e) {
            e.printStackTrace();
        }
    }
 
    @Test
    public void listRecord() {
        List<VIPOrderRecord> list = vipService.listOrderRecord(null, null, 1, 10);
        long count = vipService.countOrderRecord(null, null);
 
 
        list = vipService.listOrderRecord(766693 + "", null, 1, 10);
        count = vipService.countOrderRecord(766693 + "", null);
 
 
        list = vipService.listOrderRecord(766693 + "", VIPOrderRecord.STATE_NOT_PAY, 1, 10);
        count = vipService.countOrderRecord(766693 + "", VIPOrderRecord.STATE_NOT_PAY);
 
        list = vipService.listOrderRecord(766693 + "", VIPOrderRecord.STATE_PAY, 1, 10);
        count = vipService.countOrderRecord(766693 + "", VIPOrderRecord.STATE_PAY);
 
        System.out.println(list);
    }
 
    @Test
    public void paySuccess() {
//        try {
//            vipService.paySuccess("",VIPOrderRecord.PAY_WAY_WX,new BigDecimal("14.8"),)
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
    }
 
    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            final int p = i;
            new Thread(new Runnable() {
                @Override
                public void run() {
                    HttpUtil.get("http://192.168.3.122:8080/BuWan/test/vipPay?id=36");
                    System.out.println("执行完成:" + p);
                }
            }).start();
        }
    }
 
 
    @Test
    public void list() {
        Boolean vip = true;
        Date minDate = null;
        Date maxDate = null;
        if (vip != null) {
            if (vip) {
                minDate = new Date(System.currentTimeMillis() + 1000 * 60 * 5);
            } else {
                minDate = new Date(0L);
                maxDate = new Date();
            }
        }
 
        List<UserVIPInfo> list = vipService.listVIPUser(minDate, maxDate, 1, Constant.pageCount);
        long count = vipService.countVIPUser(minDate, maxDate);
        System.out.println(count);
    }
 
 
    @Test
    public void test3() throws Exception {
        VIPOrderRecord record = vipService.getOrderRecord("82");
        pptvVipManager.buyVIP(record);
    }
 
}