UserServiceTest.java 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. package com.izouma.nineth.service;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.alipay.api.AlipayApiException;
  4. import com.huifu.adapay.core.exception.BaseAdaPayException;
  5. import com.izouma.nineth.ApplicationTests;
  6. import com.izouma.nineth.config.Constants;
  7. import com.izouma.nineth.domain.IdentityAuth;
  8. import com.izouma.nineth.domain.User;
  9. import com.izouma.nineth.domain.netease.NeteaseMessage;
  10. import com.izouma.nineth.domain.netease.Team;
  11. import com.izouma.nineth.dto.BankValidate;
  12. import com.izouma.nineth.dto.PageQuery;
  13. import com.izouma.nineth.dto.UserBankCard;
  14. import com.izouma.nineth.dto.UserRegister;
  15. import com.izouma.nineth.enums.AuthStatus;
  16. import com.izouma.nineth.enums.InviteType;
  17. import com.izouma.nineth.enums.netease.TeamType;
  18. import com.izouma.nineth.exception.BusinessException;
  19. import com.izouma.nineth.repo.IdentityAuthRepo;
  20. import com.izouma.nineth.repo.UserBankCardRepo;
  21. import com.izouma.nineth.repo.UserRepo;
  22. import com.izouma.nineth.service.netease.NeteaseMessageService;
  23. import com.izouma.nineth.service.netease.TeamService;
  24. import com.izouma.nineth.service.storage.StorageService;
  25. import com.izouma.nineth.utils.BankUtils;
  26. import lombok.extern.slf4j.Slf4j;
  27. import org.apache.commons.lang3.StringUtils;
  28. import org.junit.jupiter.api.Test;
  29. import org.junit.jupiter.api.extension.ExtendWith;
  30. import org.springframework.beans.factory.annotation.Autowired;
  31. import org.springframework.boot.test.context.SpringBootTest;
  32. import org.springframework.test.context.junit.jupiter.SpringExtension;
  33. import java.io.IOException;
  34. import java.util.ArrayList;
  35. import java.util.HashMap;
  36. import java.util.List;
  37. import java.util.Map;
  38. import java.util.regex.Pattern;
  39. @Slf4j
  40. @ExtendWith(SpringExtension.class)
  41. @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
  42. public class UserServiceTest extends ApplicationTests {
  43. @Autowired
  44. private UserService userService;
  45. @Autowired
  46. private UserRepo userRepo;
  47. @Autowired
  48. private StorageService storageService;
  49. @Autowired
  50. private UserBankCardRepo userBankCardRepo;
  51. @Autowired
  52. private AdapayMerchantService adapayMerchantService;
  53. @Autowired
  54. private IdentityAuthRepo identityAuthRepo;
  55. @Autowired
  56. private TeamService teamService;
  57. @Autowired
  58. private NeteaseMessageService neteaseMessageService;
  59. @Test
  60. public void findByUsernameAndDelFalse1() {
  61. }
  62. @Test
  63. public void searchByPhone() {
  64. System.out.println(userService.searchByPhone("15077886171"));
  65. }
  66. @Test
  67. public void register() throws IOException {
  68. try {
  69. User user = userService.create(UserRegister.builder()
  70. .username("1111fff1g1rertuiohejldknhgurphoj")
  71. .nickname("1111fff1g1rertuiohejldknhgurphoj")
  72. .avatar(Constants.DEFAULT_AVATAR)
  73. .phone("15077886171")
  74. .build());
  75. System.out.println(user.getId());
  76. } catch (Exception e) {
  77. if (Pattern.matches(".*SQL.*constraint.*phone.*", e.getMessage())) {
  78. System.out.println("手机号已注册");
  79. }
  80. if (Pattern.matches(".*SQL.*constraint.*username.*", e.getMessage())) {
  81. System.out.println("用户名已存在");
  82. }
  83. e.printStackTrace();
  84. }
  85. }
  86. @Test
  87. public void batchRegister() {
  88. userService.batchRegister("13226246698\n" +
  89. "13793310531\n" +
  90. "13358006613\n" +
  91. "18898406893\n" +
  92. "17615876370\n" +
  93. "13267002685\n" +
  94. "15888548080\n" +
  95. "13678662069\n" +
  96. "15659009359\n" +
  97. "13011776866\n" +
  98. "18810668532\n" +
  99. "13543322894\n" +
  100. "13589360750\n" +
  101. "18582589484\n" +
  102. "15194185209\n" +
  103. "15063692500\n" +
  104. "13605489618\n" +
  105. "18069783568\n" +
  106. "15801815684\n" +
  107. "13285413859\n" +
  108. "13688419164\n" +
  109. "15979115671\n" +
  110. "13799940755\n" +
  111. "18301015323", "123456");
  112. }
  113. @Test
  114. public void test() {
  115. PageQuery pageQuery = new PageQuery();
  116. Map<String, Object> query = pageQuery.getQuery();
  117. query.put("inviteCode", "JL21FF");
  118. pageQuery.setSize(5000);
  119. List<User> phone = userService.all(pageQuery)
  120. .getContent();
  121. phone.forEach(user -> System.out.println(user.getPhone() + ":" + user.getCreatedAt()));
  122. // 2022-01-14T15:53:58 504 第一次查询
  123. phone.forEach(user -> System.out.print(user.getPhone() + " "));
  124. }
  125. @Test
  126. public void switchAccount() {
  127. userService.checkSettleAccount();
  128. }
  129. @Test
  130. public void phoneRegister() {
  131. userService.phoneRegister("18100004444", "1234", "123456", null, 9972L,
  132. 206925L, null, InviteType.NORMAL, null);
  133. }
  134. @Test
  135. public void addBankCard() throws BaseAdaPayException {
  136. Long userId = 134613L;
  137. String bankNo = "6222024301070380165";
  138. String phone = "15077886171";
  139. User user = userRepo.findById(userId).orElseThrow(new BusinessException("用户不存在"));
  140. IdentityAuth identityAuth = identityAuthRepo
  141. .findFirstByUserIdAndStatusAndDelFalseOrderByCreatedAtDesc(userId, AuthStatus.SUCCESS)
  142. .orElseThrow(new BusinessException("用户未认证"));
  143. if (identityAuth.isOrg()) {
  144. //throw new BusinessException("企业认证用户请绑定对公账户");
  145. }
  146. if (!StringUtils.isBlank(user.getSettleAccountId())) {
  147. throw new BusinessException("此账号已绑定");
  148. }
  149. BankValidate bankValidate = BankUtils.validate(bankNo);
  150. if (!bankValidate.isValidated()) {
  151. throw new BusinessException("暂不支持此卡");
  152. }
  153. adapayMerchantService
  154. .createMemberForAll(userId.toString(), user.getPhone(), identityAuth.getRealName(), identityAuth
  155. .getIdNo());
  156. user.setMemberId(user.getId().toString());
  157. userRepo.save(user);
  158. String accountId = adapayMerchantService.createSettleAccountForAll
  159. (user.getMemberId(), identityAuth.getRealName(),
  160. identityAuth.getIdNo(), phone, bankNo);
  161. user.setSettleAccountId(accountId);
  162. userRepo.save(user);
  163. userBankCardRepo.save(UserBankCard.builder()
  164. .bank(bankValidate.getBank())
  165. .bankName(bankValidate.getBankName())
  166. .bankNo(bankNo)
  167. .cardType(bankValidate.getCardType())
  168. .cardTypeDesc(bankValidate.getCardTypeDesc())
  169. .userId(userId)
  170. .phone(phone)
  171. .realName(identityAuth.getRealName())
  172. .idNo(identityAuth.getIdNo())
  173. .build());
  174. }
  175. @Test
  176. public void removeBank() throws BaseAdaPayException {
  177. Long[] arr = {2577842L, 1440523L, 2775597L, 2766468L, 2686690L, 2747709L,
  178. 2804878L, 1737822L, 1692606L, 1690986L, 12895L, 2768872L,
  179. 2758319L, 1722623L, 2767026L, 2742354L, 2772909L, 2813187L,
  180. 2592513L, 1245862L, 2581606L, 2775941L, 1649287L, 2764550L,
  181. 2660763L, 2609032L, 2777065L, 2589915L, 2810643L, 3114342L,
  182. 2897490L, 2579233L, 2728905L, 3064530L, 3261900L, 1634473L,
  183. 2798840L, 3146142L, 2872925L, 3309420L, 3618828L, 2786593L,
  184. 3337840L, 3253588L, 2745257L, 3454559L, 3474642L, 3468716L,
  185. 3363882L, 2685228L, 3088476L, 2900428L, 2705763L, 2687527L,
  186. 2787733L, 2737842L, 3324792L, 3147077L, 3145577L, 3142936L,
  187. 3385528L, 2888036L, 3366975L, 2842334L, 2864480L, 3277214L,
  188. 3260809L, 2867983L, 3246561L, 3472246L, 3302523L, 2882982L,
  189. 3150301L, 2782692L, 3082410L, 3043665L, 3448907L, 3421038L,
  190. 3371851L, 3225869L, 3087358L, 3463444L, 3478718L, 3434422L,
  191. 2784575L, 2622956L, 2700225L, 1635188L, 2715660L, 620172L,
  192. 3418309L, 3476261L, 2597211L, 3293018L, 3261495L, 3443258L
  193. };
  194. for (Long aLong : arr) {
  195. userService.removeBankCard(aLong);
  196. }
  197. }
  198. @Test
  199. public void scanWeakPassword() {
  200. userService.scanWeakPassword();
  201. }
  202. @Test
  203. public void aliAuth() throws AlipayApiException {
  204. String certifyId = userService.prepareAliAuth("IDENTITY_CARD", 1L, "熊竹", "321002199408304614");
  205. log.info(certifyId);
  206. String url = userService.getAliAuthUrl(certifyId);
  207. log.info(url);
  208. userService.checkFaceAuth(certifyId);
  209. }
  210. @Test
  211. public void checkauth() throws AlipayApiException {
  212. userService.checkFaceAuth("7160e6a875cb67648bc7a3cce6e5397e");
  213. }
  214. @Test
  215. public void teamTest() {
  216. Team team = new Team();
  217. team.setName("测试大厅2");
  218. team.setOwnerid("9859");
  219. List<String> members = new ArrayList<>();
  220. members.add("7956591");
  221. team.setMembers(members);
  222. team.setCustom(TeamType.PUBLIC);
  223. teamService.create(team);
  224. }
  225. @Test
  226. public void sendMessage() {
  227. NeteaseMessage neteaseMessage = new NeteaseMessage();
  228. neteaseMessage.setFromId("9859");
  229. neteaseMessage.setToId("7807550605");
  230. neteaseMessage.setOpe(1);
  231. neteaseMessage.setType(0);
  232. Map<String, Object> body = new HashMap<>();
  233. body.put("msg", "这是一条测试消息");
  234. neteaseMessage.setBody(JSONObject.toJSONString(body));
  235. neteaseMessageService.sendMessage(neteaseMessage);
  236. }
  237. @Test
  238. public void tTe() {
  239. teamService.getUnreadCount("9850","7807550605");
  240. }
  241. }