|
|
@@ -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");
|
|
|
- }
|
|
|
}
|