diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/basic/WxMerchantController.java b/mallinkAdmin/src/main/java/com/iformall/controller/basic/WxMerchantController.java index 1d1d2ca6d..c19975d8d 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/basic/WxMerchantController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/basic/WxMerchantController.java @@ -371,15 +371,7 @@ public class WxMerchantController extends BaseController { if(merchant == null){ return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"请检查传递参数"); } - WxAppinfo appInfo = wxAppinfoService.getCAppInfo(getTenantInfo(), EnumAppPlat.TOUTIAO); - if(appInfo == null) { - return new ResultData(ErrorCode.APP_ID_NOT_FOUND); - } - WxPayAccount payAcount = payAccountService.getById(appInfo.getPayId()); - if(payAcount == null){ - return new ResultData(ErrorCode.APP_ID_NOT_FOUND); - } - return wxProfitSharingReceiverService.updateTtReceiver(merchant,appInfo.getAppId(),payAcount.getApiKey()); + return wxProfitSharingReceiverService.updateTtReceiver(merchant); } @@ -400,19 +392,10 @@ public class WxMerchantController extends BaseController { if(anEnum == null){ return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"请检查传递参数"); } - - WxAppinfo appInfo = wxAppinfoService.getCAppInfo(getTenantInfo(), EnumAppPlat.TOUTIAO); - if(appInfo == null) { - return new ResultData(ErrorCode.APP_ID_NOT_FOUND); - } - WxPayAccount payAcount = payAccountService.getById(appInfo.getPayId()); - if(payAcount == null){ - return new ResultData(ErrorCode.API_KEY_NOT_FOUND); - } if(anEnum.equals(AppAddSubMerchantUrlType.improt_URL)){ - return wxProfitSharingReceiverService.getTtReceiverImprotURL(merchant,appInfo.getAppId(),payAcount.getApiKey()); + return wxProfitSharingReceiverService.getTtReceiverImprotURL(merchant); }else if(anEnum.equals(AppAddSubMerchantUrlType.Balance_URL)){ - return wxProfitSharingReceiverService.getTtReceiverBalanceURL(merchant,appInfo.getAppId(),payAcount.getApiKey()); + return wxProfitSharingReceiverService.getTtReceiverBalanceURL(merchant); }else{ return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"请检查传递参数"); } @@ -436,7 +419,7 @@ public class WxMerchantController extends BaseController { if(payAcount == null){ return new ResultData(ErrorCode.APP_ID_NOT_FOUND); } - return wxProfitSharingReceiverService.updateTtReceiverIsUse(merchant,appInfo.getAppId(),payAcount.getApiKey()); + return wxProfitSharingReceiverService.updateTtReceiverIsUse(merchant); } } diff --git a/mallinkAdmin/src/main/resources/db/migration/V2022101100001__add_pay_account.sql b/mallinkAdmin/src/main/resources/db/migration/V2022101100001__add_pay_account.sql index 427b4218b..b944144f9 100644 --- a/mallinkAdmin/src/main/resources/db/migration/V2022101100001__add_pay_account.sql +++ b/mallinkAdmin/src/main/resources/db/migration/V2022101100001__add_pay_account.sql @@ -13,4 +13,11 @@ where type = 0; update `mallink`.`wx_pay_account` set private_key_path = null,cert_serial_no = null,api_v3_key = null where type = 0; + +update `mallink`.`wx_pay_account` set merchant_api_key = api_key +where type = 0; + +update `mallink`.`wx_pay_account` set api_key = null +where type = 0; + --清缓存,重启项目 \ No newline at end of file diff --git a/mallinkBApi/src/main/java/com/iformall/controller/WxMerchantController.java b/mallinkBApi/src/main/java/com/iformall/controller/WxMerchantController.java index d09ae37a9..cae3f5243 100644 --- a/mallinkBApi/src/main/java/com/iformall/controller/WxMerchantController.java +++ b/mallinkBApi/src/main/java/com/iformall/controller/WxMerchantController.java @@ -184,18 +184,10 @@ public class WxMerchantController extends BaseController { return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"请检查传递参数"); } - WxAppinfo appInfo = wxAppinfoService.getCAppInfo(getTenantInfo(), EnumAppPlat.TOUTIAO); - if(appInfo == null) { - return new ResultData(ErrorCode.APP_ID_NOT_FOUND); - } - WxPayAccount payAcount = payAccountService.getById(appInfo.getPayId()); - if(payAcount == null){ - return new ResultData(ErrorCode.APP_ID_NOT_FOUND); - } if(anEnum.equals(AppAddSubMerchantUrlType.improt_URL)){ - return wxProfitSharingReceiverService.getTtReceiverImprotURL(merchant,appInfo.getAppId(),payAcount.getApiKey()); + return wxProfitSharingReceiverService.getTtReceiverImprotURL(merchant); }else if(anEnum.equals(AppAddSubMerchantUrlType.Balance_URL)){ - return wxProfitSharingReceiverService.getTtReceiverBalanceURL(merchant,appInfo.getAppId(),payAcount.getApiKey()); + return wxProfitSharingReceiverService.getTtReceiverBalanceURL(merchant); }else{ return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"请检查传递参数"); } diff --git a/mallinkSchedule/src/main/java/com/iformall/schedule/TtMerchantReciverSchedule.java b/mallinkSchedule/src/main/java/com/iformall/schedule/TtMerchantReciverSchedule.java index be1d7bf80..3e36eddfb 100644 --- a/mallinkSchedule/src/main/java/com/iformall/schedule/TtMerchantReciverSchedule.java +++ b/mallinkSchedule/src/main/java/com/iformall/schedule/TtMerchantReciverSchedule.java @@ -45,33 +45,15 @@ public class TtMerchantReciverSchedule { @Scheduled(cron = "0 */30 * * * ?") // @Scheduled(cron = "0 */5 * * * *?") //测试五分钟执行 public void updateMerchantReciverSchedule() { - WxMall mallQ = new WxMall(); - mallQ.setSaleType(EnumSaleType.TT_ALL_ROUND.getCode()); - List mallList = wxMallService.findList(mallQ); - if(mallList == null || mallList.isEmpty()){ - return; - } - List tenantIds = mallList.stream().map(m -> m.getTenantId()).collect(Collectors.toList()); + List ttAppInfos = getTTAppInfos(); + + List tenantIds = ttAppInfos.stream().map(appinfo -> appinfo.getTenantId()).collect(Collectors.toList()); List merchants = wxMerchantMapper.findByTenantIds(tenantIds); if(merchants == null || merchants.isEmpty()){ return; } - Map appIdMap = new HashMap<>(); - Map payAccountKeyMap = new HashMap<>(); - WxAppinfo appQ = new WxAppinfo(); - appQ.setType(EnumAppType.C.getCode()); - appQ.setPlat(EnumPayWay.PAY_WAY_TT.getPlat().getCode()); - List wxAppinfoList = wxAppinfoService.getList(appQ); - for (WxAppinfo wxAppinfo:wxAppinfoList) { - appIdMap.put(wxAppinfo.getTenantId(),wxAppinfo.getAppId()); - WxPayAccount wxPayAccount = payAccountService.getById(wxAppinfo.getPayId()); - if(wxPayAccount != null){ - payAccountKeyMap.put(wxAppinfo.getTenantId(),wxPayAccount.getApiKey()); - } - } - for (WxMerchant m:merchants) { // try { // wxProfitSharingReceiverService.updateTtReceiver(m,appIdMap.get(m.getTenantId()),payAccountKeyMap.get(m.getTenantId())); @@ -80,7 +62,7 @@ public class TtMerchantReciverSchedule { // logger.error("TtMerchantReciverSchedule error.updateTtReceiver:"+m.getId(),e); // } try { - wxProfitSharingReceiverService.updateTtReceiverIsUse(m,appIdMap.get(m.getTenantId()),payAccountKeyMap.get(m.getTenantId())); + wxProfitSharingReceiverService.updateTtReceiverIsUse(m); } catch (Exception e) { e.printStackTrace(); logger.error("TtMerchantReciverSchedule error.updateTtReceiver:"+m.getId(),e); @@ -88,4 +70,12 @@ public class TtMerchantReciverSchedule { } } + private List getTTAppInfos() { + WxAppinfo appinfo =new WxAppinfo(); + appinfo.setPlat(EnumAppPlat.TOUTIAO.getCode()); + appinfo.setType(EnumAppType.C.getCode()); + appinfo.setEnable(EnumEnableType.Enable.getCode()); + return wxAppinfoService.getList(appinfo); + } + } \ No newline at end of file diff --git a/mallinkSchedule/src/main/java/com/iformall/schedule/TtOrderQueryCpsSchedule.java b/mallinkSchedule/src/main/java/com/iformall/schedule/TtOrderQueryCpsSchedule.java index 2fb3a5b63..db839623e 100644 --- a/mallinkSchedule/src/main/java/com/iformall/schedule/TtOrderQueryCpsSchedule.java +++ b/mallinkSchedule/src/main/java/com/iformall/schedule/TtOrderQueryCpsSchedule.java @@ -46,10 +46,8 @@ public class TtOrderQueryCpsSchedule { @Scheduled(cron = "0 5 */1 * * ?") // @Scheduled(cron = "0 0/5 * * * ?") public void OrderPushErrorTaskSchedule() { - WxAppinfo appQ = new WxAppinfo(); - appQ.setType(EnumAppType.C.getCode()); - appQ.setPlat(EnumPayWay.PAY_WAY_TT.getPlat().getCode()); - List wxAppinfoList = wxAppinfoService.getList(appQ); + List wxAppinfoList = this.getTTAppInfos(); + for (WxAppinfo appinfo:wxAppinfoList) { try{ WxPayAccount payAccount = wxPayAccountService.getById(appinfo.getPayId()); @@ -117,4 +115,12 @@ public class TtOrderQueryCpsSchedule { } + private List getTTAppInfos() { + WxAppinfo appinfo =new WxAppinfo(); + appinfo.setPlat(EnumAppPlat.TOUTIAO.getCode()); + appinfo.setType(EnumAppType.C.getCode()); + appinfo.setEnable(EnumEnableType.Enable.getCode()); + return wxAppinfoService.getList(appinfo); + } + } \ No newline at end of file diff --git a/mallinkService/src/main/java/com/iformall/service/WxProfitSharingReceiverService.java b/mallinkService/src/main/java/com/iformall/service/WxProfitSharingReceiverService.java index 5a34eae62..654ca2ba5 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxProfitSharingReceiverService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxProfitSharingReceiverService.java @@ -54,12 +54,12 @@ public interface WxProfitSharingReceiverService { void sendMsg(String phone, String account, String merchant, String time, Integer modelType, TenantEntity tenantEntity); - ResultData updateTtReceiver(WxMerchant merchant, String appId, String payAccountKey); + ResultData updateTtReceiver(WxMerchant merchant); - ResultData getTtReceiverImprotURL(WxMerchant merchant, String appId, String payAccountKey); + ResultData getTtReceiverImprotURL(WxMerchant merchant); - ResultData getTtReceiverBalanceURL(WxMerchant merchant, String appId, String payAccountKey); + ResultData getTtReceiverBalanceURL(WxMerchant merchant); - ResultData updateTtReceiverIsUse(WxMerchant merchant, String appId, String payAccountKey); + ResultData updateTtReceiverIsUse(WxMerchant merchant); } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingReceiverServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingReceiverServiceImpl.java index b7c166773..a8efe0b77 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingReceiverServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingReceiverServiceImpl.java @@ -267,14 +267,14 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv } @Override - public ResultData updateTtReceiver(WxMerchant merchant, String appId, String payAccountKey) { - if(merchant == null || StringUtils.isBlank(appId) || StringUtils.isBlank(payAccountKey)) { + public ResultData updateTtReceiver(WxMerchant merchant) { + if(merchant == null) { return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"请检查传递参数"); } WxProfitSharingReceiver wxProfitSharingReceiver = getTtSharingReceiver(merchant); //进件页面 - AppAddSubMerchantResult improt_URLResult = appAddSubMerchant(appId,payAccountKey,merchant.getId().toString(),AppAddSubMerchantUrlType.improt_URL); + AppAddSubMerchantResult improt_URLResult = appAddSubMerchant(merchant,merchant.getId().toString(),AppAddSubMerchantUrlType.improt_URL); if(improt_URLResult.isSuccess()){ wxProfitSharingReceiver.setReceiverAccount(improt_URLResult.getMerchantId()); wxProfitSharingReceiver.setTtImportUrl(improt_URLResult.getUrl()); @@ -282,7 +282,7 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv logger.error("获取进件页面 error{}"+improt_URLResult.getMsg()); } //余额页面 - AppAddSubMerchantResult balance_URLResult = appAddSubMerchant(appId,payAccountKey,merchant.getId().toString(),AppAddSubMerchantUrlType.Balance_URL); + AppAddSubMerchantResult balance_URLResult = appAddSubMerchant(merchant,merchant.getId().toString(),AppAddSubMerchantUrlType.Balance_URL); if(balance_URLResult.isSuccess()){ wxProfitSharingReceiver.setReceiverAccount(balance_URLResult.getMerchantId()); wxProfitSharingReceiver.setTtBalanceUrl(balance_URLResult.getUrl()); @@ -294,13 +294,13 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv } @Override - public ResultData getTtReceiverImprotURL(WxMerchant merchant, String appId, String payAccountKey) { - if(merchant == null || StringUtils.isBlank(appId) || StringUtils.isBlank(payAccountKey)) { + public ResultData getTtReceiverImprotURL(WxMerchant merchant) { + if(merchant == null) { return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"请检查传递参数"); } WxProfitSharingReceiver wxProfitSharingReceiver = getTtSharingReceiver(merchant); //进件页面 - AppAddSubMerchantResult improt_URLResult = appAddSubMerchant(appId,payAccountKey,merchant.getId().toString(),AppAddSubMerchantUrlType.improt_URL); + AppAddSubMerchantResult improt_URLResult = appAddSubMerchant(merchant,merchant.getId().toString(),AppAddSubMerchantUrlType.improt_URL); if(improt_URLResult.isSuccess()){ wxProfitSharingReceiver.setReceiverAccount(improt_URLResult.getMerchantId()); wxProfitSharingReceiver.setTtImportUrl(improt_URLResult.getUrl()); @@ -313,13 +313,13 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv } @Override - public ResultData getTtReceiverBalanceURL(WxMerchant merchant, String appId, String payAccountKey) { - if(merchant == null || StringUtils.isBlank(appId) || StringUtils.isBlank(payAccountKey)) { + public ResultData getTtReceiverBalanceURL(WxMerchant merchant) { + if(merchant == null) { return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"请检查传递参数"); } WxProfitSharingReceiver wxProfitSharingReceiver = getTtSharingReceiver(merchant); //余额页面 - AppAddSubMerchantResult balance_URLResult = appAddSubMerchant(appId,payAccountKey,merchant.getId().toString(),AppAddSubMerchantUrlType.Balance_URL); + AppAddSubMerchantResult balance_URLResult = appAddSubMerchant(merchant,merchant.getId().toString(),AppAddSubMerchantUrlType.Balance_URL); if(balance_URLResult.isSuccess()){ wxProfitSharingReceiver.setReceiverAccount(balance_URLResult.getMerchantId()); wxProfitSharingReceiver.setTtBalanceUrl(balance_URLResult.getUrl()); @@ -350,10 +350,19 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv } @Override - public ResultData updateTtReceiverIsUse(WxMerchant merchant, String appId, String payAccountKey) { - if(merchant == null || StringUtils.isBlank(appId) || StringUtils.isBlank(payAccountKey)) { + public ResultData updateTtReceiverIsUse(WxMerchant merchant) { + if(merchant == null) { return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"请检查传递参数"); } + WxAppinfo appInfo = wxAppinfoService.getCAppInfoFromRedis(merchant.getTenantId(), EnumAppPlat.TOUTIAO); + if(appInfo == null){ + throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); + } + WxPayAccount payAcount = wxPayAccountService.getByIdFromRedis(appInfo.getPayId()); + if(payAcount == null){ + throw new MallinkException(ErrorCode.API_KEY_NOT_FOUND); + } + WxProfitSharingReceiver oldReceiver = new WxProfitSharingReceiver(); oldReceiver.updateTenantInfo(merchant); oldReceiver.setMerchantId(merchant.getId()); @@ -363,7 +372,8 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv if(wxProfitSharingReceiver == null){ return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"未找到分账信息"); } - QueryMerchantResult queryMerchantResult = DouYinPayHelper.queryMerchantStatus(appId, payAccountKey, wxProfitSharingReceiver.getReceiverAccount(), wxProfitSharingReceiver.getMerchantId().toString(), null); + + QueryMerchantResult queryMerchantResult = DouYinPayHelper.queryMerchantStatus(appInfo.getAppId(), payAcount.getMerchantApiKey(), wxProfitSharingReceiver.getReceiverAccount(), wxProfitSharingReceiver.getMerchantId().toString(), null); if(queryMerchantResult != null){ // if(queryMerchantResult.getWx().intValue() != 1){ // return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"微信渠道未进件成功!"); @@ -380,10 +390,18 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv } } - private AppAddSubMerchantResult appAddSubMerchant(String appId, String payAccountKey, String merchantId, AppAddSubMerchantUrlType appAddSubMerchantUrlType){ + private AppAddSubMerchantResult appAddSubMerchant(TenantEntity tenantEntity, String merchantId, AppAddSubMerchantUrlType appAddSubMerchantUrlType){ + WxAppinfo appInfo = wxAppinfoService.getCAppInfoFromRedis(tenantEntity.getTenantId(), EnumAppPlat.TOUTIAO); + if(appInfo == null){ + throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); + } + WxPayAccount payAcount = wxPayAccountService.getByIdFromRedis(appInfo.getPayId()); + if(payAcount == null){ + throw new MallinkException(ErrorCode.API_KEY_NOT_FOUND); + } AppAddSubMerchant appAddSubMerchant = new AppAddSubMerchant(); - appAddSubMerchant.setAppId(appId); - appAddSubMerchant.setSalt(payAccountKey); + appAddSubMerchant.setAppId(appInfo.getAppId()); + appAddSubMerchant.setSalt(payAcount.getMerchantApiKey()); appAddSubMerchant.setSubMerchantId(merchantId); appAddSubMerchant.setUrlType(appAddSubMerchantUrlType.getCode()); return DouYinPayHelper.appAddSubMerchant(appAddSubMerchant); diff --git a/mallinkService/src/main/java/com/iformall/service/tt/impl/TtOrderServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/tt/impl/TtOrderServiceImpl.java index 885ef3215..cda211c07 100644 --- a/mallinkService/src/main/java/com/iformall/service/tt/impl/TtOrderServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/tt/impl/TtOrderServiceImpl.java @@ -248,7 +248,7 @@ public class TtOrderServiceImpl implements TtOrderService { DouYinCreatePreOrder preOrder = new DouYinCreatePreOrder(); preOrder.setAppId(appInfo.getAppId()); preOrder.setSercrect(appInfo.getSecret()); - preOrder.setSalt(payAcount.getApiKey()); + preOrder.setSalt(payAcount.getMerchantApiKey()); preOrder.setOutOrderNo(order.getId().toString()); preOrder.setTotalAmount(order.getPayment()); preOrder.setSubject(coupon.getTitle()); @@ -296,7 +296,7 @@ public class TtOrderServiceImpl implements TtOrderService { if(order.getOrderStatus() == EnumTtOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()){ String msg = ""; //待付款 - OrderQueryResult orderQueryResult = DouYinPayHelper.orderQuery(appInfo.getAppId(), payAccount.getApiKey(), order.getId().toString(), null); + OrderQueryResult orderQueryResult = DouYinPayHelper.orderQuery(appInfo.getAppId(), payAccount.getMerchantApiKey(), order.getId().toString(), null); if(orderQueryResult == null){ msg = "查询-单号不存在"; }else{