123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538 |
- package com.qs.mp.task;
- import cn.hutool.core.codec.Base62;
- import cn.hutool.core.date.LocalDateTimeUtil;
- import cn.hutool.core.util.HashUtil;
- import cn.hutool.core.util.IdUtil;
- import cn.hutool.core.util.NumberUtil;
- import cn.hutool.crypto.SecureUtil;
- import cn.hutool.crypto.symmetric.DES;
- import cn.hutool.crypto.symmetric.SymmetricAlgorithm;
- import cn.hutool.crypto.symmetric.SymmetricCrypto;
- import cn.hutool.http.HttpRequest;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.alibaba.fastjson.parser.Feature;
- import com.alibaba.fastjson.serializer.SerializerFeature;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.eptok.yspay.opensdkjava.fund.BankAuthorityApi;
- import com.eptok.yspay.opensdkjava.fund.MercFundApi;
- import com.eptok.yspay.opensdkjava.pojo.vo.OnlineReqDataVo;
- import com.eptok.yspay.opensdkjava.util.Base64Utils;
- import com.eptok.yspay.opensdkjava.util.DateUtil;
- import com.eptok.yspay.opensdkjava.util.SrcDesUtil;
- import com.eptok.yspay.opensdkjava.util.YsOnlineSignUtils;
- import com.eptok.yspay.opensdkjava.util.YsfSignUtil;
- import com.qs.mp.admin.domain.Coupon;
- import com.qs.mp.admin.domain.CouponTicket;
- import com.qs.mp.admin.domain.GoodsCard;
- import com.qs.mp.admin.domain.Marketing;
- import com.qs.mp.admin.service.ICouponChannelService;
- import com.qs.mp.admin.service.ICouponService;
- import com.qs.mp.admin.service.ICouponTicketService;
- import com.qs.mp.admin.service.IGoodsCardService;
- import com.qs.mp.common.constant.YsServerApiConstants;
- import com.qs.mp.common.core.redis.DistributedLocker;
- import com.qs.mp.common.core.redis.RedisCache;
- import com.qs.mp.common.domain.YsCallLog;
- import com.qs.mp.common.enums.DivisionStatusEnum;
- import com.qs.mp.common.enums.UserTypeEnum;
- import com.qs.mp.common.enums.YsCallBizTypeEnum;
- import com.qs.mp.common.utils.AESUtil;
- import com.qs.mp.common.utils.DateUtils;
- import com.qs.mp.common.utils.RSAUtil;
- import com.qs.mp.common.utils.WebhookService;
- import com.qs.mp.common.utils.html.EscapeUtil;
- import com.qs.mp.common.utils.http.OkHttpUtil;
- import com.qs.mp.common.utils.uuid.IdUtils;
- import com.qs.mp.common.utils.uuid.UUID;
- import com.qs.mp.framework.service.IWxSubscribeMessage;
- import com.qs.mp.pay.domain.DivisionLog;
- import com.qs.mp.pay.service.IWalletService;
- import com.qs.mp.quartz.task.DayStatTask;
- import com.qs.mp.quartz.task.MarketingTask;
- import com.qs.mp.quartz.task.TicketOrderTask;
- import com.qs.mp.system.service.id.BizIdGenerator;
- import com.qs.mp.user.domain.MarketingUserCode;
- import com.qs.mp.user.service.IMarketingUserCodeService;
- import com.qs.mp.utils.SecurityUtils;
- import com.taobao.api.Constants;
- import java.util.concurrent.TimeUnit;
- import org.apache.commons.lang3.RandomStringUtils;
- import org.apache.commons.lang3.StringUtils;
- import org.apache.http.client.methods.HttpRequestBase;
- import org.junit.jupiter.api.Test;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.boot.test.context.SpringBootTest;
- import java.io.IOException;
- import java.time.LocalDateTime;
- import java.util.*;
- /**
- * @author Cup
- * @date 2022/4/26
- */
- @SpringBootTest
- public class MyTest {
- protected final Logger logger = LoggerFactory.getLogger(this.getClass());
- @Autowired
- private IWalletService walletService;
- @Autowired
- private MarketingTask marketingTask;
- @Autowired
- private RedisCache redisCache;
- @Autowired
- private BizIdGenerator bizIdGenerator;
- @Autowired
- private IWxSubscribeMessage wxSubscribeMessage;
- @Autowired
- private IMarketingUserCodeService marketingUserCodeService;
- @Autowired
- private DayStatTask dayStatTask;
- @Autowired
- private ICouponService couponService;
- @Autowired
- private ICouponChannelService couponChannelService;
- @Autowired
- private ICouponTicketService couponTicketService;
- @Autowired
- private IGoodsCardService goodsCardService;
- @Autowired
- private DistributedLocker distributedLocker;
- @Autowired
- private TicketOrderTask ticketOrderTask;
- @Value("${ys-pay.serverUrl}")
- private String serverUrl;
- @Value("${ys-pay.partner-id}")
- private String partnerId;
- @Value("${ys-pay.private-key-pass}")
- private String privateKeyPass;
- @Value("${ys-pay.private-key-path}")
- private String privateKeyPath;
- @Value("${ys-pay.public-key-path}")
- private String publicKeyPath;
- @Value("${ys-pay.withdraw-notify-url}")
- private String ysWithdrawNotifyUrl;
- /**
- * 分账查询测试
- */
- @Test
- void test22() {
- OnlineReqDataVo req = new OnlineReqDataVo();
- //请求路径,建议配置在项目的配置文件里面
- String reqUrl = "https://commonapi.ysepay.com/gateway.do";
- //银盛支付服务器主动通知商户网站里指定的页面http路径
- String notifyUrl = "http://api.test.ysepay.net/atinterface/receive_return.htm";
- req.setNotifyUrl(notifyUrl);
- //商户在银盛支付平台开设的用户号[商户号],接入时需要替换成自己的
- req.setPartnerId(partnerId);
- req.setReqUrl(reqUrl);
- req.setPrivateKeyFilePath(privateKeyPath);
- req.setPrivateKeyPassword(privateKeyPass);
- req.setYsPublicKeyFilePath(publicKeyPath);
- //线上分账查询接口业务参数
- Map<String, Object> bizContent = new HashMap<>();
- bizContent.put("src_usercode", partnerId);//原交易发起方
- bizContent.put("out_trade_no", "20230414176151484");//原订单号
- bizContent.put("sys_flag", "DD");//可空。系统标志 DD:订单交易,DS:代收交易,默认是DD,订单交易
- req.setParamData(bizContent);
- String result = null;
- try{
- logger.info("线上分账查询调用sdk接口addScanMerc请求入参为:"+ JSONObject.toJSONString(req));
- result = MercFundApi.divisionOnlineQuery(req);
- System.out.println("result = " + result);
- //根据返回结果处理自己的业务逻辑,result内容详见接口文档
- }catch (Exception e){
- logger.info("线上分账查询接口失败:"+ e.getMessage());
- }
- }
- /**
- * 分账测试
- */
- @Test
- void test21() {
- // 调用分账登记接口
- OnlineReqDataVo req = new OnlineReqDataVo();
- req.setReqUrl(YsServerApiConstants.COMMON_API);
- req.setNotifyUrl("https://test-mp.quanshu123.com/service/notify/ysDivCallback");
- req.setPartnerId(partnerId);
- req.setPrivateKeyFilePath(privateKeyPath);
- req.setPrivateKeyPassword(privateKeyPass);
- req.setYsPublicKeyFilePath(publicKeyPath);
- // 分账登记业务参数
- Map<String, Object> bizContent = new HashMap<>();
- String divTradeNo = DateUtil.getDateNowYmd() + DateUtil.getRandom(14);
- divTradeNo = "2023041335526144";
- bizContent.put("out_trade_no", divTradeNo);
- bizContent.put("payee_usercode", partnerId);
- bizContent.put("total_amount", "0.10");
- bizContent.put("is_divistion", "02");
- bizContent.put("is_again_division", "N");
- bizContent.put("division_mode", "01");
- // 分账明细
- // JSONArray divList = new JSONArray();
- // JSONObject divObject = new JSONObject();
- // divObject.put("division_mer_usercode", partnerId);
- // divObject.put("div_ratio", "1");
- // divObject.put("is_chargeFee", "02");
- // divList.add(divObject);
- //分账明细
- // bizContent.put("div_list", divList);
- req.setParamData(bizContent);
- String result = null;
- DivisionLog divisionLog = new DivisionLog();
- divisionLog.setStatus(DivisionStatusEnum.INIT);
- try{
- logger.info("分账登记调用sdk接口addScanMerc请求入参为:"+ JSONObject.toJSONString(req));
- result = MercFundApi.divisionOnlineAccept(req);
- logger.info("分账登记调用addScanMerc出参为:"+ result);
- //根据返回结果处理自己的业务逻辑,result内容详见接口文档
- }catch (Exception e){
- divisionLog.setStatus(DivisionStatusEnum.SUBMIT_FAIL);
- logger.error("线上分账登记接口失败:"+ e.getMessage());
- }
- }
- /**
- * 提现测试方法
- */
- @Test
- void test20() {
- String tradeNo = DateUtil.getDateNowYmd() + DateUtil.getRandom(14);
- OnlineReqDataVo req = new OnlineReqDataVo();
- req.setReqUrl(YsServerApiConstants.COMMON_API);
- req.setPrivateKeyFilePath(privateKeyPath);
- req.setYsPublicKeyFilePath(publicKeyPath);
- req.setPrivateKeyPassword(privateKeyPass);
- req.setNotifyUrl(ysWithdrawNotifyUrl);
- req.setPartnerId(partnerId);
- //实时提现(一般户到银行卡)业务参数
- Map<String, Object> bizContent = new HashMap<>();
- //商户生成的订单号,生成规则前8位必须为交易日期,如20180525,范围跨度支持包含当天在内的前后一天
- bizContent.put("out_trade_no", tradeNo);
- //商户号
- bizContent.put("merchant_usercode", partnerId);
- //暂时只支持币种:CNY(人民币)
- bizContent.put("currency", "CNY");
- //提现的总金额。单位为:RMB Yuan。取值范围为[0.01,99999999.99],精确到小数点后两位。Number(10,2)指10位长度,2位精度
- bizContent.put("total_amount", "0.04");
- //订单说明
- bizContent.put("subject", "提现了");
- //商户日期(该参数做交易与查询时需要一致) 该日期需在当日的前后一天时间范围之内
- bizContent.put("shopdate", DateUtil.getDateNowYmd());
- //银行帐号
- bizContent.put("bank_account_no", "6212260488888888888");
- req.setParamData(bizContent);
- String result = null;
- try{
- logger.info("实时提现(一般户到银行卡)调用sdk接口addScanMerc请求入参为:"+ JSONObject.toJSONString(req));
- //根据返回结果处理自己的业务逻辑,result内容详见接口文档
- result = MercFundApi.withdrawQuick(req);
- }catch (Exception e){
- logger.info("实时提现(一般户到银行卡)失败:"+ e.getMessage());
- }
- System.out.println("result = " + result);
- }
- @Test
- void test19() {
- // 调用接口校验
- OnlineReqDataVo req = new OnlineReqDataVo();
- req.setReqUrl(YsServerApiConstants.OPEN_API);
- req.setPartnerId(partnerId);
- req.setPrivateKeyFilePath(privateKeyPath);
- req.setYsPublicKeyFilePath(publicKeyPath);
- req.setPrivateKeyPassword(privateKeyPass);
- //银行实名认证三要素下单业务参数
- Map<String, Object> bizContent = new HashMap<>();
- String tradeNo = DateUtil.getDateNowYmd() + DateUtil.getRandom(14);
- //商户生成的订单号,生成规则前8位必须为交易日期,如20180525,范围跨度支持包含当天在内的前后一天
- bizContent.put("out_trade_no", tradeNo);
- //商户日期(该参数做交易与查询时需要一致)该日期需在当日的前后一天时间范围之内
- bizContent.put("shopdate", DateUtil.getDateNowYmd());
- //实名认证姓名--请填写真实信息
- bizContent.put("bank_account_name", "张三");
- //银行帐号,支持对公对私
- bizContent.put("bank_account_no", "6212260488888888888");
- //证件号码,目前只支持身份证
- bizContent.put("id_card", "41022319940916602X");
- req.setParamData(bizContent);
- String result = null;
- try {
- logger.info("银行实名认证三要素调用sdk接口addScanMerc请求入参为:" + JSONObject.toJSONString(req));
- //根据返回结果处理自己的业务逻辑,result内容详见接口文档
- result = BankAuthorityApi.sendBankAuthThreePrecise(req);
- } catch (Exception e) {
- logger.info("银行实名认证三要素失败:" + e.getMessage());
- }
- System.out.println("result = " + result);
- }
- @Test
- void test18() {
- walletService.h5Pay(null, "0239021091224323", 100, "测试测试测试");
- }
- /**
- * 实名认证方法
- */
- @Test
- void test17() {
- OnlineReqDataVo req = new OnlineReqDataVo();
- //商户在银盛支付平台开设的用户号[商户号],接入时需要替换成自己的
- req.setPartnerId(partnerId);
- req.setReqUrl(YsServerApiConstants.OPEN_API);
- req.setPrivateKeyFilePath(privateKeyPath);
- req.setPrivateKeyPassword(privateKeyPass);
- req.setYsPublicKeyFilePath(publicKeyPath);
- //银行实名认证三要素下单业务参数
- Map<String, Object> bizContent = new HashMap<>();
- bizContent.put("out_trade_no", DateUtil.getDateNowYmd() + DateUtil.getRandom(6));//商户生成的订单号,生成规则前8位必须为交易日期,如20180525,范围跨度支持包含当天在内的前后一天
- bizContent.put("shopdate", DateUtil.getDateNowYmd());//商户日期(该参数做交易与查询时需要一致)该日期需在当日的前后一天时间范围之内
- bizContent.put("bank_account_name", "李四");//实名认证姓名--请填写真实信息
- bizContent.put("bank_account_no", "6212260488888888888");//银行帐号,支持对公对私
- bizContent.put("id_card","41022319940916602X");//证件号码,目前只支持身份证
- req.setParamData(bizContent);
- String result = null;
- try{
- logger.info("银行实名认证三要素调用sdk接口addScanMerc请求入参为:"+ JSONObject.toJSONString(req));
- //根据返回结果处理自己的业务逻辑,result内容详见接口文档
- result = BankAuthorityApi.sendBankAuthThreePrecise(req);
- }catch (Exception e){
- logger.info("银行实名认证三要素失败:"+ e.getMessage());
- }
- System.out.println("result = " + result);
- }
- /**
- * 实名认证测试方法
- * @throws Exception
- */
- @Test
- void test16() throws Exception {
- Map<String, String> mapData = new HashMap<>();
- mapData.put("partner_id", partnerId);
- mapData.put("method", "ysepay.authenticate.three.key.element.precise");
- mapData.put("timestamp", DateUtil.getDateNow());
- mapData.put("sign_type", "RSA");
- mapData.put("charset", "utf-8");
- mapData.put("version", "3.0");
- // mapData.put("out_trade_no", "202003276843192280647119");
- JSONObject json = new JSONObject();
- json.put("out_trade_no", DateUtil.getDateNowYmd() + DateUtil.getRandom(6));
- json.put("shopdate", DateUtil.getDateNowYmd());
- json.put("bank_account_name", "蒋浩");
- json.put("bank_account_no", "6212260488888888888");
- json.put("id_card", SrcDesUtil.encryptData(partnerId, "331081199909124619"));
- mapData.put("biz_content", json.toString());
- //参数签名
- try {
- String sign = YsOnlineSignUtils.sign(mapData, privateKeyPass, privateKeyPath);
- mapData.put("sign", sign);
- System.out.println("sign = " + sign);
- } catch (Exception e) {
- System.err.println("签名异常" + e);
- }
- String result = OkHttpUtil.post("https://openapi.ysepay.com/gateway.do", mapData);
- // 结果验签
- JSONObject jsonObject = JSON.parseObject(result, Feature.OrderedField);
- // 加签内容
- String content = JSONObject.toJSONString(
- jsonObject.get("ysepay_authenticate_three_key_element_precise_response"),
- SerializerFeature.WriteMapNullValue);
- System.out.println("返回" + result);
- System.out.println("content = " + content);
- }
- @Test
- void test15() {
- ticketOrderTask.cancel();
- }
- @Test
- void test14() {
- distributedLocker.tryLock("goods_card_lock_key_466", 0, -1, TimeUnit.SECONDS);
- }
- @Test
- void test13() {
- List<GoodsCard> goodsCardList = goodsCardService.list(new QueryWrapper<GoodsCard>()
- .eq("is_use", 1));
- goodsCardList.forEach(System.out::println);
- }
- @Test
- void test12() {
- Coupon coupon = couponService.getById(56);
- String description = coupon.getDescription();
- String s = description.replaceAll("\\n", "<br>");
- System.out.println("coupon.getDescription() = " + s);
- }
- @Test
- void test11() {
- boolean remove = couponTicketService.remove(
- new LambdaQueryWrapper<CouponTicket>().eq(CouponTicket::getCouponId, 11));
- System.out.println("remove = " + remove);
- }
- @Test
- void test10() {
- for (int i = 0; i < 1; i++) {
- couponService.distributeByMarketing(188L, "56");
- }
- }
- @Test
- void test9() {
- Marketing marketing = new Marketing();
- marketing.setId(44L);
- marketing.setTitle("测试测试");
- wxSubscribeMessage.sendMarketingLottery(187L, marketing);
- }
- @Test
- void test8() {
- dayStatTask.stat("20220713");
- }
- @Test
- void test7() {
- String hellow = AESUtil.encrypt("hellow");
- System.out.println("hellow = " + hellow);
- String decrypt = AESUtil.decrypt("hahaha");
- System.out.println("decrypt = " + decrypt);
- }
- @Test
- void test6() {
- // List<MarketingUserCode> userCodeList = marketingUserCodeService.list(new LambdaQueryWrapper<MarketingUserCode>()
- // .select(MarketingUserCode::getUserId)
- // .eq(MarketingUserCode::getMarketingId, 102)
- //// .eq(MarketingUserCode::getUserType, UserTypeEnum.ORDINARY.getValue())
- // .groupBy(MarketingUserCode::getUserId));
- List<MarketingUserCode> userCodeList = marketingUserCodeService.list(new LambdaQueryWrapper<MarketingUserCode>()
- .select(MarketingUserCode::getUserId)
- .eq(MarketingUserCode::getUserType, UserTypeEnum.ORDINARY.getValue())
- .groupBy(MarketingUserCode::getUserId));
- userCodeList.forEach(System.out::println);
- }
- @Test
- void test5() {
- Set<String> testSet = new HashSet<>();
- testSet.add("test1");
- testSet.add("test2");
- testSet.add("test3");
- testSet.add("test4");
- redisCache.setCacheSet("testSet", testSet);
- List<Object> list = new ArrayList<>();
- list.add("test1");
- list.add("test3");
- list.add("test5");
- list.add("test6");
- list.add("test7");
- redisCache.removeSetValueByKey("testSet", list);
- }
- @Test
- void test4() {
- Marketing marketing = new Marketing();
- marketing.setId(45L);
- marketing.setTitle("测试订阅通");
- wxSubscribeMessage.sendMarketingLottery(188L, marketing);
- wxSubscribeMessage.sendMarketingLottery(79L, marketing);
- // wxSubscribeMessage.sendMarketingStart(188L, marketing);
- // wxSubscribeMessage.sendMarketingStart(79L, marketing);
- // wxSubscribeMessage.sendMarketingHelp(188L, marketing);
- // wxSubscribeMessage.sendMarketingHelp(79L, marketing);
- }
- @Test
- void test2() throws IOException {
- marketingTask.lottery();
- }
- @Test
- void test3() {
- for (int i = 0; i < 20; i++) {
- System.out.println("bizIdGenerator = " + bizIdGenerator.newId());
- }
- }
- @Test
- void test1() {
- walletService.refund("968527112497659906", 10, "测试");
- }
- }
|