xiongzhu 3 سال پیش
والد
کامیت
b9c3c2bcfe

+ 1 - 0
src/main/java/com/izouma/nineth/service/AdapayMerchantService.java

@@ -256,4 +256,5 @@ public class AdapayMerchantService {
             throw new BusinessException(errMsg + "(" + errCode + ")");
         }
     }
+
 }

+ 17 - 65
src/main/java/com/izouma/nineth/service/UserService.java

@@ -3,19 +3,12 @@ package com.izouma.nineth.service;
 import cn.binarywang.wx.miniapp.api.WxMaService;
 import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
 import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.serializer.SerializerFeature;
 import com.huifu.adapay.core.exception.BaseAdaPayException;
-import com.huifu.adapay.model.AdapayCommon;
-import com.huifu.adapay.model.SettleAccount;
 import com.izouma.nineth.TokenHistory;
 import com.izouma.nineth.config.AdapayProperties;
 import com.izouma.nineth.config.Constants;
 import com.izouma.nineth.domain.Collection;
-import com.izouma.nineth.domain.Follow;
-import com.izouma.nineth.domain.IdentityAuth;
-import com.izouma.nineth.domain.Invite;
-import com.izouma.nineth.domain.User;
+import com.izouma.nineth.domain.*;
 import com.izouma.nineth.dto.*;
 import com.izouma.nineth.enums.AuthStatus;
 import com.izouma.nineth.enums.AuthorityName;
@@ -37,7 +30,6 @@ import me.chanjar.weixin.common.error.WxErrorException;
 import me.chanjar.weixin.mp.api.WxMpService;
 import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
 import me.chanjar.weixin.mp.bean.result.WxMpUser;
-import org.apache.commons.collections.MapUtils;
 import org.apache.commons.lang3.RandomStringUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.BeanUtils;
@@ -47,6 +39,7 @@ import org.springframework.context.event.EventListener;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageImpl;
 import org.springframework.data.jpa.domain.Specification;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
 import org.springframework.stereotype.Service;
 
@@ -603,73 +596,32 @@ public class UserService {
         return map;
     }
 
-
-    public void switchAccount() {
-        switchAccount(adapayProperties.getAppId());
+    @Async
+    public void checkSettleAccountAsync() {
+        checkSettleAccount();
     }
 
-    public void switchAccount(String appId) {
-        userRepo.findBySettleAccountIdIsNotNull().parallelStream().forEach(user -> {
+    public void checkSettleAccount() {
+        userRepo.findBySettleAccountIdIsNotNull().forEach(user -> {
             try {
                 IdentityAuth identityAuth = identityAuthRepo.findFirstByUserIdAndStatusAndDelFalseOrderByCreatedAtDesc(user.getId(), AuthStatus.SUCCESS)
                         .orElseThrow(new BusinessException("用户未认证"));
                 UserBankCard userBankCard = userBankCardRepo.findByUserId(user.getId()).stream().findAny()
                         .orElseThrow(new BusinessException("未绑卡"));
-                createMember(appId, user.getId().toString(), Optional.ofNullable(userBankCard.getPhone())
-                        .orElse(user.getPhone()), identityAuth.getRealName(), identityAuth.getIdNo());
-                createSettleAccount(appId, user.getId()
-                        .toString(), identityAuth.getRealName(), identityAuth.getIdNo(), Optional.ofNullable(userBankCard.getPhone())
-                        .orElse(user.getPhone()), userBankCard.getBankNo());
+                adapayMerchantService.createMemberForAll(
+                        user.getId().toString(), Optional.ofNullable(userBankCard.getPhone()).orElse(user.getPhone()),
+                        identityAuth.getRealName(), identityAuth.getIdNo());
+                adapayMerchantService.createSettleAccountForAll(
+                        user.getId().toString(), identityAuth.getRealName(),
+                        identityAuth.getIdNo(), Optional.ofNullable(userBankCard.getPhone()).orElse(user.getPhone()),
+                        userBankCard.getBankNo());
                 userBankCard.setPhone(Optional.ofNullable(userBankCard.getPhone()).orElse(user.getPhone()));
                 userBankCardRepo.save(userBankCard);
             } catch (Exception e) {
-//                user.setSettleAccountId(null);
-//                userRepo.save(user);
-//                userBankCardRepo.deleteByUserId(user.getId());
+                user.setSettleAccountId(null);
+                userRepo.save(user);
+                userBankCardRepo.deleteByUserId(user.getId());
             }
         });
     }
-
-    public void createMember(String appId, String memberId, String tel, String realName, String idno) throws BaseAdaPayException {
-        Map<String, Object> memberParams = new HashMap<>();
-        memberParams.put("adapay_func_code", "members.realname");
-        memberParams.put("member_id", memberId);
-        memberParams.put("app_id", appId);
-        memberParams.put("tel_no", tel);
-        memberParams.put("user_name", realName);
-        memberParams.put("cert_type", "00");
-        memberParams.put("cert_id", idno);
-        Map<String, Object> res = AdapayCommon.requestAdapay(memberParams);
-        log.info("createMember\n{}", JSON.toJSONString(res, SerializerFeature.PrettyFormat));
-        if (!("succeeded".equals(MapUtils.getString(res, "status"))
-                || "member_id_exists".equals(MapUtils.getString(res, "error_code")))) {
-            String errMsg = MapUtils.getString(res, "error_msg");
-            String errCode = MapUtils.getString(res, "error_code");
-            throw new BusinessException(errMsg + "(" + errCode + ")");
-        }
-    }
-
-    public String createSettleAccount(String appId, String memberId, String realName, String idNo, String phone, String bankNo) throws BaseAdaPayException {
-        Map<String, Object> settleCountParams = new HashMap<>();
-        Map<String, Object> accountInfo = new HashMap<>();
-        accountInfo.put("card_id", bankNo);
-        accountInfo.put("card_name", realName);
-        accountInfo.put("cert_id", idNo);
-        accountInfo.put("cert_type", "00");
-        accountInfo.put("tel_no", phone);
-        accountInfo.put("bank_acct_type", "2");
-        settleCountParams.put("member_id", memberId);
-        settleCountParams.put("app_id", appId);
-        settleCountParams.put("channel", "bank_account");
-        settleCountParams.put("account_info", accountInfo);
-        Map<String, Object> res = SettleAccount.create(settleCountParams);
-        log.info("createSettleAccount\n{}", JSON.toJSONString(res, SerializerFeature.PrettyFormat));
-        if (!("succeeded".equals(MapUtils.getString(res, "status"))
-                || "account_exists".equals(MapUtils.getString(res, "error_code")))) {
-            String errMsg = MapUtils.getString(res, "error_msg");
-            String errCode = MapUtils.getString(res, "error_code");
-            throw new BusinessException(errMsg + "(" + errCode + ")");
-        }
-        return MapUtils.getString(res, "id");
-    }
 }

+ 3 - 3
src/main/java/com/izouma/nineth/web/UserController.java

@@ -264,9 +264,9 @@ public class UserController extends BaseController {
     }
 
     @PreAuthorize("hasAnyRole('ADMIN')")
-    @GetMapping("/switchAccount")
-    public String switchAccount() {
-        userService.switchAccount();
+    @GetMapping("/checkSettleAccount")
+    public String checkSettleAccount() {
+        userService.checkSettleAccountAsync();
         return "ok";
     }
 }

+ 9 - 0
src/test/java/com/izouma/nineth/service/AdapayMerchantServiceTest.java

@@ -0,0 +1,9 @@
+package com.izouma.nineth.service;
+
+import com.izouma.nineth.ApplicationTests;
+
+import static org.junit.Assert.*;
+
+public class AdapayMerchantServiceTest extends ApplicationTests {
+
+}

+ 5 - 5
src/test/java/com/izouma/nineth/service/AdapayTest.java

@@ -29,14 +29,14 @@ import java.util.List;
 import java.util.Map;
 
 public class AdapayTest {
-    private final String appId = "app_0e8d3acb-3d95-4ebb-8445-e470c378a787";
+    private final String appId = "app_4c00a390-70c0-44ac-b3f0-f6dd25f6a364";
 
     public AdapayTest() {
         Adapay.debug = false;
         Adapay.prodMode = true;
 
         MerConfig merConfig = new MerConfig();
-        merConfig.setApiKey("api_live_dc298e47-c0be-4acf-a962-a2c2988e4cae");
+        merConfig.setApiKey("api_live_dfc6a4b3-cd8b-453c-a1b2-d7440f1d73b5");
         merConfig.setApiMockKey("api_test_26e9eee7-6695-4169-90a1-203c6d2cf196");
         merConfig.setRSAPrivateKey("MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCLeSEu8CXg4iwpRtAapIGpbuoJdyAh3E2FgIqOJSME/0+DscuIUVzfQzMWgXT98Zd8aKQLmjTWHx6Tg60DCFJzJBkISZYaqF9Oc+YdPe15TINpp5syKDk72WeUEW/jlXiLwKyeFxzCvedbpbdAUi0cP64US/LslGohHGWUrgj/WBR33vgwA2NAHR+ziGp8IhFUXHoWtXdBjwGsWuZ6Wt9mWOVeGIHP6OyUYzhkVuDyFMZ6wlA60PqxPAQrvZG3VP2mSlpWTs7xQHM9nk8Rn2pQDUmexHmKS/wn4XZvl3S9KRs6/l8wDqlBW5QhmEZNRwiOG8n/FpqxUMI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mp5IyGcFlmGP219OcEfzt8BV8s3yoPHPpgYX/zPsH9764UMSZb+FRXFLd8HC+UqqppQ4cq2RmMu5X7H/DWoj9FqXgusjOmZUyWiJgTPC4ktFesuhJhCHuk/50/nXmc6O8rWLwXqXf1XNaoNfzDmZNQ20jRZGr8eVc4g=");
         merConfig.setRSAPublicKey("MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAi3khLvAl4OIsKUbQGqSBqW7qCXcgIdxNhYCKjiUjBP9Pg7HLiFFc30MzFoF0/fGXfGikC5o01h8ek4OtAwhScyQZCEmWGqhfTnPmHT3teUyDaaebMig5O9lnlBFv45V4i8Csnhccwr3nW6W3QFItHD+uFEvy7JRqIRxllK4I/1gUd974MANjQB0fs4hqfCIRVFx6FrV3QY8BrFrmelrfZljlXhiBz+jslGM4ZFbg8hTGesJQOtD6sTwEK72Rt1T9pkpaVk7O8UBzPZ5PEZ9qUA1JnsR5ikv8J+F2b5d0vSkbOv5fMA6pQVuUIZhGTUcIjhvJ/xaasVDCIRRY+EkqtQIDAQAB");
@@ -201,16 +201,16 @@ public class AdapayTest {
     @Test
     public void singleRefund() throws BaseAdaPayException {
         Map<String, Object> refundParams = new HashMap<>();
-        refundParams.put("refund_amt", "19.80");
+        refundParams.put("refund_amt", "889.00");
         refundParams.put("refund_order_no", new SnowflakeIdWorker(0, 0).nextId() + "");
-        Map<String, Object> response = Refund.create("002112022021218280510338519797695426560", refundParams);
+        Map<String, Object> response = Refund.create("002112022030216390710345015359205462016", refundParams);
         System.out.println(JSON.toJSONString(response, SerializerFeature.PrettyFormat));
     }
 
     @Test
     public void singleRefundVerify() throws BaseAdaPayException {
         Map<String, Object> queryParams = new HashMap<>();
-        queryParams.put("payment_id", "002112022021218280610338519802865594368");
+        queryParams.put("payment_id", "002112022030216390710345015359205462016");
         Map<String, Object> refund = Refund.query(queryParams);
         System.out.println(JSON.toJSONString(refund, SerializerFeature.PrettyFormat));
     }