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();
|
}
|
}
|
|
}
|