MyTest.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. package com.qs.mp.task;
  2. import cn.hutool.core.codec.Base62;
  3. import cn.hutool.core.date.LocalDateTimeUtil;
  4. import cn.hutool.core.util.HashUtil;
  5. import cn.hutool.core.util.IdUtil;
  6. import cn.hutool.core.util.NumberUtil;
  7. import cn.hutool.crypto.SecureUtil;
  8. import cn.hutool.crypto.symmetric.DES;
  9. import cn.hutool.crypto.symmetric.SymmetricAlgorithm;
  10. import cn.hutool.crypto.symmetric.SymmetricCrypto;
  11. import cn.hutool.http.HttpRequest;
  12. import com.alibaba.fastjson.JSON;
  13. import com.alibaba.fastjson.JSONArray;
  14. import com.alibaba.fastjson.JSONObject;
  15. import com.alibaba.fastjson.parser.Feature;
  16. import com.alibaba.fastjson.serializer.SerializerFeature;
  17. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  18. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  19. import com.eptok.yspay.opensdkjava.fund.BankAuthorityApi;
  20. import com.eptok.yspay.opensdkjava.fund.MercFundApi;
  21. import com.eptok.yspay.opensdkjava.pojo.vo.OnlineReqDataVo;
  22. import com.eptok.yspay.opensdkjava.util.Base64Utils;
  23. import com.eptok.yspay.opensdkjava.util.DateUtil;
  24. import com.eptok.yspay.opensdkjava.util.SrcDesUtil;
  25. import com.eptok.yspay.opensdkjava.util.YsOnlineSignUtils;
  26. import com.eptok.yspay.opensdkjava.util.YsfSignUtil;
  27. import com.qs.mp.admin.domain.Coupon;
  28. import com.qs.mp.admin.domain.CouponTicket;
  29. import com.qs.mp.admin.domain.GoodsCard;
  30. import com.qs.mp.admin.domain.Marketing;
  31. import com.qs.mp.admin.service.ICouponChannelService;
  32. import com.qs.mp.admin.service.ICouponService;
  33. import com.qs.mp.admin.service.ICouponTicketService;
  34. import com.qs.mp.admin.service.IGoodsCardService;
  35. import com.qs.mp.common.constant.YsServerApiConstants;
  36. import com.qs.mp.common.core.redis.DistributedLocker;
  37. import com.qs.mp.common.core.redis.RedisCache;
  38. import com.qs.mp.common.domain.YsCallLog;
  39. import com.qs.mp.common.enums.DivisionStatusEnum;
  40. import com.qs.mp.common.enums.UserTypeEnum;
  41. import com.qs.mp.common.enums.YsCallBizTypeEnum;
  42. import com.qs.mp.common.utils.AESUtil;
  43. import com.qs.mp.common.utils.DateUtils;
  44. import com.qs.mp.common.utils.RSAUtil;
  45. import com.qs.mp.common.utils.WebhookService;
  46. import com.qs.mp.common.utils.html.EscapeUtil;
  47. import com.qs.mp.common.utils.http.OkHttpUtil;
  48. import com.qs.mp.common.utils.uuid.IdUtils;
  49. import com.qs.mp.common.utils.uuid.UUID;
  50. import com.qs.mp.framework.service.IWxSubscribeMessage;
  51. import com.qs.mp.pay.domain.DivisionLog;
  52. import com.qs.mp.pay.service.IWalletService;
  53. import com.qs.mp.quartz.task.DayStatTask;
  54. import com.qs.mp.quartz.task.MarketingTask;
  55. import com.qs.mp.quartz.task.TicketOrderTask;
  56. import com.qs.mp.system.service.id.BizIdGenerator;
  57. import com.qs.mp.user.domain.MarketingUserCode;
  58. import com.qs.mp.user.service.IMarketingUserCodeService;
  59. import com.qs.mp.utils.SecurityUtils;
  60. import com.taobao.api.Constants;
  61. import java.util.concurrent.TimeUnit;
  62. import org.apache.commons.lang3.RandomStringUtils;
  63. import org.apache.commons.lang3.StringUtils;
  64. import org.apache.http.client.methods.HttpRequestBase;
  65. import org.junit.jupiter.api.Test;
  66. import org.slf4j.Logger;
  67. import org.slf4j.LoggerFactory;
  68. import org.springframework.beans.factory.annotation.Autowired;
  69. import org.springframework.beans.factory.annotation.Value;
  70. import org.springframework.boot.test.context.SpringBootTest;
  71. import java.io.IOException;
  72. import java.time.LocalDateTime;
  73. import java.util.*;
  74. /**
  75. * @author Cup
  76. * @date 2022/4/26
  77. */
  78. @SpringBootTest
  79. public class MyTest {
  80. protected final Logger logger = LoggerFactory.getLogger(this.getClass());
  81. @Autowired
  82. private IWalletService walletService;
  83. @Autowired
  84. private MarketingTask marketingTask;
  85. @Autowired
  86. private RedisCache redisCache;
  87. @Autowired
  88. private BizIdGenerator bizIdGenerator;
  89. @Autowired
  90. private IWxSubscribeMessage wxSubscribeMessage;
  91. @Autowired
  92. private IMarketingUserCodeService marketingUserCodeService;
  93. @Autowired
  94. private DayStatTask dayStatTask;
  95. @Autowired
  96. private ICouponService couponService;
  97. @Autowired
  98. private ICouponChannelService couponChannelService;
  99. @Autowired
  100. private ICouponTicketService couponTicketService;
  101. @Autowired
  102. private IGoodsCardService goodsCardService;
  103. @Autowired
  104. private DistributedLocker distributedLocker;
  105. @Autowired
  106. private TicketOrderTask ticketOrderTask;
  107. @Value("${ys-pay.serverUrl}")
  108. private String serverUrl;
  109. @Value("${ys-pay.partner-id}")
  110. private String partnerId;
  111. @Value("${ys-pay.private-key-pass}")
  112. private String privateKeyPass;
  113. @Value("${ys-pay.private-key-path}")
  114. private String privateKeyPath;
  115. @Value("${ys-pay.public-key-path}")
  116. private String publicKeyPath;
  117. @Value("${ys-pay.withdraw-notify-url}")
  118. private String ysWithdrawNotifyUrl;
  119. /**
  120. * 分账查询测试
  121. */
  122. @Test
  123. void test22() {
  124. OnlineReqDataVo req = new OnlineReqDataVo();
  125. //请求路径,建议配置在项目的配置文件里面
  126. String reqUrl = "https://commonapi.ysepay.com/gateway.do";
  127. //银盛支付服务器主动通知商户网站里指定的页面http路径
  128. String notifyUrl = "http://api.test.ysepay.net/atinterface/receive_return.htm";
  129. req.setNotifyUrl(notifyUrl);
  130. //商户在银盛支付平台开设的用户号[商户号],接入时需要替换成自己的
  131. req.setPartnerId(partnerId);
  132. req.setReqUrl(reqUrl);
  133. req.setPrivateKeyFilePath(privateKeyPath);
  134. req.setPrivateKeyPassword(privateKeyPass);
  135. req.setYsPublicKeyFilePath(publicKeyPath);
  136. //线上分账查询接口业务参数
  137. Map<String, Object> bizContent = new HashMap<>();
  138. bizContent.put("src_usercode", partnerId);//原交易发起方
  139. bizContent.put("out_trade_no", "20230414176151484");//原订单号
  140. bizContent.put("sys_flag", "DD");//可空。系统标志 DD:订单交易,DS:代收交易,默认是DD,订单交易
  141. req.setParamData(bizContent);
  142. String result = null;
  143. try{
  144. logger.info("线上分账查询调用sdk接口addScanMerc请求入参为:"+ JSONObject.toJSONString(req));
  145. result = MercFundApi.divisionOnlineQuery(req);
  146. System.out.println("result = " + result);
  147. //根据返回结果处理自己的业务逻辑,result内容详见接口文档
  148. }catch (Exception e){
  149. logger.info("线上分账查询接口失败:"+ e.getMessage());
  150. }
  151. }
  152. /**
  153. * 分账测试
  154. */
  155. @Test
  156. void test21() {
  157. // 调用分账登记接口
  158. OnlineReqDataVo req = new OnlineReqDataVo();
  159. req.setReqUrl(YsServerApiConstants.COMMON_API);
  160. req.setNotifyUrl("https://test-mp.quanshu123.com/service/notify/ysDivCallback");
  161. req.setPartnerId(partnerId);
  162. req.setPrivateKeyFilePath(privateKeyPath);
  163. req.setPrivateKeyPassword(privateKeyPass);
  164. req.setYsPublicKeyFilePath(publicKeyPath);
  165. // 分账登记业务参数
  166. Map<String, Object> bizContent = new HashMap<>();
  167. String divTradeNo = DateUtil.getDateNowYmd() + DateUtil.getRandom(14);
  168. divTradeNo = "2023041335526144";
  169. bizContent.put("out_trade_no", divTradeNo);
  170. bizContent.put("payee_usercode", partnerId);
  171. bizContent.put("total_amount", "0.10");
  172. bizContent.put("is_divistion", "02");
  173. bizContent.put("is_again_division", "N");
  174. bizContent.put("division_mode", "01");
  175. // 分账明细
  176. // JSONArray divList = new JSONArray();
  177. // JSONObject divObject = new JSONObject();
  178. // divObject.put("division_mer_usercode", partnerId);
  179. // divObject.put("div_ratio", "1");
  180. // divObject.put("is_chargeFee", "02");
  181. // divList.add(divObject);
  182. //分账明细
  183. // bizContent.put("div_list", divList);
  184. req.setParamData(bizContent);
  185. String result = null;
  186. DivisionLog divisionLog = new DivisionLog();
  187. divisionLog.setStatus(DivisionStatusEnum.INIT);
  188. try{
  189. logger.info("分账登记调用sdk接口addScanMerc请求入参为:"+ JSONObject.toJSONString(req));
  190. result = MercFundApi.divisionOnlineAccept(req);
  191. logger.info("分账登记调用addScanMerc出参为:"+ result);
  192. //根据返回结果处理自己的业务逻辑,result内容详见接口文档
  193. }catch (Exception e){
  194. divisionLog.setStatus(DivisionStatusEnum.SUBMIT_FAIL);
  195. logger.error("线上分账登记接口失败:"+ e.getMessage());
  196. }
  197. }
  198. /**
  199. * 提现测试方法
  200. */
  201. @Test
  202. void test20() {
  203. String tradeNo = DateUtil.getDateNowYmd() + DateUtil.getRandom(14);
  204. OnlineReqDataVo req = new OnlineReqDataVo();
  205. req.setReqUrl(YsServerApiConstants.COMMON_API);
  206. req.setPrivateKeyFilePath(privateKeyPath);
  207. req.setYsPublicKeyFilePath(publicKeyPath);
  208. req.setPrivateKeyPassword(privateKeyPass);
  209. req.setNotifyUrl(ysWithdrawNotifyUrl);
  210. req.setPartnerId(partnerId);
  211. //实时提现(一般户到银行卡)业务参数
  212. Map<String, Object> bizContent = new HashMap<>();
  213. //商户生成的订单号,生成规则前8位必须为交易日期,如20180525,范围跨度支持包含当天在内的前后一天
  214. bizContent.put("out_trade_no", tradeNo);
  215. //商户号
  216. bizContent.put("merchant_usercode", partnerId);
  217. //暂时只支持币种:CNY(人民币)
  218. bizContent.put("currency", "CNY");
  219. //提现的总金额。单位为:RMB Yuan。取值范围为[0.01,99999999.99],精确到小数点后两位。Number(10,2)指10位长度,2位精度
  220. bizContent.put("total_amount", "0.04");
  221. //订单说明
  222. bizContent.put("subject", "提现了");
  223. //商户日期(该参数做交易与查询时需要一致) 该日期需在当日的前后一天时间范围之内
  224. bizContent.put("shopdate", DateUtil.getDateNowYmd());
  225. //银行帐号
  226. bizContent.put("bank_account_no", "6212260488888888888");
  227. req.setParamData(bizContent);
  228. String result = null;
  229. try{
  230. logger.info("实时提现(一般户到银行卡)调用sdk接口addScanMerc请求入参为:"+ JSONObject.toJSONString(req));
  231. //根据返回结果处理自己的业务逻辑,result内容详见接口文档
  232. result = MercFundApi.withdrawQuick(req);
  233. }catch (Exception e){
  234. logger.info("实时提现(一般户到银行卡)失败:"+ e.getMessage());
  235. }
  236. System.out.println("result = " + result);
  237. }
  238. @Test
  239. void test19() {
  240. // 调用接口校验
  241. OnlineReqDataVo req = new OnlineReqDataVo();
  242. req.setReqUrl(YsServerApiConstants.OPEN_API);
  243. req.setPartnerId(partnerId);
  244. req.setPrivateKeyFilePath(privateKeyPath);
  245. req.setYsPublicKeyFilePath(publicKeyPath);
  246. req.setPrivateKeyPassword(privateKeyPass);
  247. //银行实名认证三要素下单业务参数
  248. Map<String, Object> bizContent = new HashMap<>();
  249. String tradeNo = DateUtil.getDateNowYmd() + DateUtil.getRandom(14);
  250. //商户生成的订单号,生成规则前8位必须为交易日期,如20180525,范围跨度支持包含当天在内的前后一天
  251. bizContent.put("out_trade_no", tradeNo);
  252. //商户日期(该参数做交易与查询时需要一致)该日期需在当日的前后一天时间范围之内
  253. bizContent.put("shopdate", DateUtil.getDateNowYmd());
  254. //实名认证姓名--请填写真实信息
  255. bizContent.put("bank_account_name", "张三");
  256. //银行帐号,支持对公对私
  257. bizContent.put("bank_account_no", "6212260488888888888");
  258. //证件号码,目前只支持身份证
  259. bizContent.put("id_card", "41022319940916602X");
  260. req.setParamData(bizContent);
  261. String result = null;
  262. try {
  263. logger.info("银行实名认证三要素调用sdk接口addScanMerc请求入参为:" + JSONObject.toJSONString(req));
  264. //根据返回结果处理自己的业务逻辑,result内容详见接口文档
  265. result = BankAuthorityApi.sendBankAuthThreePrecise(req);
  266. } catch (Exception e) {
  267. logger.info("银行实名认证三要素失败:" + e.getMessage());
  268. }
  269. System.out.println("result = " + result);
  270. }
  271. @Test
  272. void test18() {
  273. walletService.h5Pay(null, "0239021091224323", 100, "测试测试测试");
  274. }
  275. /**
  276. * 实名认证方法
  277. */
  278. @Test
  279. void test17() {
  280. OnlineReqDataVo req = new OnlineReqDataVo();
  281. //商户在银盛支付平台开设的用户号[商户号],接入时需要替换成自己的
  282. req.setPartnerId(partnerId);
  283. req.setReqUrl(YsServerApiConstants.OPEN_API);
  284. req.setPrivateKeyFilePath(privateKeyPath);
  285. req.setPrivateKeyPassword(privateKeyPass);
  286. req.setYsPublicKeyFilePath(publicKeyPath);
  287. //银行实名认证三要素下单业务参数
  288. Map<String, Object> bizContent = new HashMap<>();
  289. bizContent.put("out_trade_no", DateUtil.getDateNowYmd() + DateUtil.getRandom(6));//商户生成的订单号,生成规则前8位必须为交易日期,如20180525,范围跨度支持包含当天在内的前后一天
  290. bizContent.put("shopdate", DateUtil.getDateNowYmd());//商户日期(该参数做交易与查询时需要一致)该日期需在当日的前后一天时间范围之内
  291. bizContent.put("bank_account_name", "李四");//实名认证姓名--请填写真实信息
  292. bizContent.put("bank_account_no", "6212260488888888888");//银行帐号,支持对公对私
  293. bizContent.put("id_card","41022319940916602X");//证件号码,目前只支持身份证
  294. req.setParamData(bizContent);
  295. String result = null;
  296. try{
  297. logger.info("银行实名认证三要素调用sdk接口addScanMerc请求入参为:"+ JSONObject.toJSONString(req));
  298. //根据返回结果处理自己的业务逻辑,result内容详见接口文档
  299. result = BankAuthorityApi.sendBankAuthThreePrecise(req);
  300. }catch (Exception e){
  301. logger.info("银行实名认证三要素失败:"+ e.getMessage());
  302. }
  303. System.out.println("result = " + result);
  304. }
  305. /**
  306. * 实名认证测试方法
  307. * @throws Exception
  308. */
  309. @Test
  310. void test16() throws Exception {
  311. Map<String, String> mapData = new HashMap<>();
  312. mapData.put("partner_id", partnerId);
  313. mapData.put("method", "ysepay.authenticate.three.key.element.precise");
  314. mapData.put("timestamp", DateUtil.getDateNow());
  315. mapData.put("sign_type", "RSA");
  316. mapData.put("charset", "utf-8");
  317. mapData.put("version", "3.0");
  318. // mapData.put("out_trade_no", "202003276843192280647119");
  319. JSONObject json = new JSONObject();
  320. json.put("out_trade_no", DateUtil.getDateNowYmd() + DateUtil.getRandom(6));
  321. json.put("shopdate", DateUtil.getDateNowYmd());
  322. json.put("bank_account_name", "蒋浩");
  323. json.put("bank_account_no", "6212260488888888888");
  324. json.put("id_card", SrcDesUtil.encryptData(partnerId, "331081199909124619"));
  325. mapData.put("biz_content", json.toString());
  326. //参数签名
  327. try {
  328. String sign = YsOnlineSignUtils.sign(mapData, privateKeyPass, privateKeyPath);
  329. mapData.put("sign", sign);
  330. System.out.println("sign = " + sign);
  331. } catch (Exception e) {
  332. System.err.println("签名异常" + e);
  333. }
  334. String result = OkHttpUtil.post("https://openapi.ysepay.com/gateway.do", mapData);
  335. // 结果验签
  336. JSONObject jsonObject = JSON.parseObject(result, Feature.OrderedField);
  337. // 加签内容
  338. String content = JSONObject.toJSONString(
  339. jsonObject.get("ysepay_authenticate_three_key_element_precise_response"),
  340. SerializerFeature.WriteMapNullValue);
  341. System.out.println("返回" + result);
  342. System.out.println("content = " + content);
  343. }
  344. @Test
  345. void test15() {
  346. ticketOrderTask.cancel();
  347. }
  348. @Test
  349. void test14() {
  350. distributedLocker.tryLock("goods_card_lock_key_466", 0, -1, TimeUnit.SECONDS);
  351. }
  352. @Test
  353. void test13() {
  354. List<GoodsCard> goodsCardList = goodsCardService.list(new QueryWrapper<GoodsCard>()
  355. .eq("is_use", 1));
  356. goodsCardList.forEach(System.out::println);
  357. }
  358. @Test
  359. void test12() {
  360. Coupon coupon = couponService.getById(56);
  361. String description = coupon.getDescription();
  362. String s = description.replaceAll("\\n", "<br>");
  363. System.out.println("coupon.getDescription() = " + s);
  364. }
  365. @Test
  366. void test11() {
  367. boolean remove = couponTicketService.remove(
  368. new LambdaQueryWrapper<CouponTicket>().eq(CouponTicket::getCouponId, 11));
  369. System.out.println("remove = " + remove);
  370. }
  371. @Test
  372. void test10() {
  373. for (int i = 0; i < 1; i++) {
  374. couponService.distributeByMarketing(188L, "56");
  375. }
  376. }
  377. @Test
  378. void test9() {
  379. Marketing marketing = new Marketing();
  380. marketing.setId(44L);
  381. marketing.setTitle("测试测试");
  382. wxSubscribeMessage.sendMarketingLottery(187L, marketing);
  383. }
  384. @Test
  385. void test8() {
  386. dayStatTask.stat("20220713");
  387. }
  388. @Test
  389. void test7() {
  390. String hellow = AESUtil.encrypt("hellow");
  391. System.out.println("hellow = " + hellow);
  392. String decrypt = AESUtil.decrypt("hahaha");
  393. System.out.println("decrypt = " + decrypt);
  394. }
  395. @Test
  396. void test6() {
  397. // List<MarketingUserCode> userCodeList = marketingUserCodeService.list(new LambdaQueryWrapper<MarketingUserCode>()
  398. // .select(MarketingUserCode::getUserId)
  399. // .eq(MarketingUserCode::getMarketingId, 102)
  400. //// .eq(MarketingUserCode::getUserType, UserTypeEnum.ORDINARY.getValue())
  401. // .groupBy(MarketingUserCode::getUserId));
  402. List<MarketingUserCode> userCodeList = marketingUserCodeService.list(new LambdaQueryWrapper<MarketingUserCode>()
  403. .select(MarketingUserCode::getUserId)
  404. .eq(MarketingUserCode::getUserType, UserTypeEnum.ORDINARY.getValue())
  405. .groupBy(MarketingUserCode::getUserId));
  406. userCodeList.forEach(System.out::println);
  407. }
  408. @Test
  409. void test5() {
  410. Set<String> testSet = new HashSet<>();
  411. testSet.add("test1");
  412. testSet.add("test2");
  413. testSet.add("test3");
  414. testSet.add("test4");
  415. redisCache.setCacheSet("testSet", testSet);
  416. List<Object> list = new ArrayList<>();
  417. list.add("test1");
  418. list.add("test3");
  419. list.add("test5");
  420. list.add("test6");
  421. list.add("test7");
  422. redisCache.removeSetValueByKey("testSet", list);
  423. }
  424. @Test
  425. void test4() {
  426. Marketing marketing = new Marketing();
  427. marketing.setId(45L);
  428. marketing.setTitle("测试订阅通");
  429. wxSubscribeMessage.sendMarketingLottery(188L, marketing);
  430. wxSubscribeMessage.sendMarketingLottery(79L, marketing);
  431. // wxSubscribeMessage.sendMarketingStart(188L, marketing);
  432. // wxSubscribeMessage.sendMarketingStart(79L, marketing);
  433. // wxSubscribeMessage.sendMarketingHelp(188L, marketing);
  434. // wxSubscribeMessage.sendMarketingHelp(79L, marketing);
  435. }
  436. @Test
  437. void test2() throws IOException {
  438. marketingTask.lottery();
  439. }
  440. @Test
  441. void test3() {
  442. for (int i = 0; i < 20; i++) {
  443. System.out.println("bizIdGenerator = " + bizIdGenerator.newId());
  444. }
  445. }
  446. @Test
  447. void test1() {
  448. walletService.refund("968527112497659906", 10, "测试");
  449. }
  450. }