Przeglądaj źródła

[会员管理][修改]:粉丝批量同步

release
Stormeye Wu 7 lat temu
rodzic
commit
3d9c6a62db
1 zmienionych plików z 28 dodań i 12 usunięć
  1. +28
    -12
      mlWechatOpen/src/main/java/com/iformall/mp/controller/WxMemController.java

+ 28
- 12
mlWechatOpen/src/main/java/com/iformall/mp/controller/WxMemController.java Wyświetl plik

@@ -2,10 +2,7 @@ package com.iformall.mp.controller;


import com.iformall.common.ResultData; import com.iformall.common.ResultData;
import com.iformall.domain.po.WxAuthorizerInfo; import com.iformall.domain.po.WxAuthorizerInfo;
import com.iformall.domain.po.WxCUser;
import com.iformall.enums.EnumAppType;
import com.iformall.mapper.WxAuthorizerInfoMapper; import com.iformall.mapper.WxAuthorizerInfoMapper;
import com.iformall.mapper.WxCUserMapper;
import com.iformall.mp.manager.WxMpManager; import com.iformall.mp.manager.WxMpManager;
import com.iformall.service.WxCUserService; import com.iformall.service.WxCUserService;
import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.error.WxErrorException;
@@ -21,7 +18,6 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;


import java.util.Date;
import java.util.List; import java.util.List;


/** /**
@@ -42,10 +38,9 @@ public class WxMemController {
private WxCUserService userService; private WxCUserService userService;


@GetMapping("/syncAccountFansList") @GetMapping("/syncAccountFansList")
public ResultData syncAccountFansList(@PathVariable String appId) throws WxErrorException {
public ResultData syncAccountFansList(@PathVariable String appId) {
final WxMpService wxService = wxMpManager.getMpService(appId); final WxMpService wxService = wxMpManager.getMpService(appId);



WxAuthorizerInfo authQ = new WxAuthorizerInfo(); WxAuthorizerInfo authQ = new WxAuthorizerInfo();
authQ.setAuthorizerAppid(appId); authQ.setAuthorizerAppid(appId);
WxAuthorizerInfo authorizerInfo = wxAuthorizerInfoMapper.findWeChatMp(authQ); WxAuthorizerInfo authorizerInfo = wxAuthorizerInfoMapper.findWeChatMp(authQ);
@@ -55,9 +50,7 @@ public class WxMemController {
while (true) { while (true) {
WxMpUserList mpUserList = wxService.getUserService().userList(nextOpenId); WxMpUserList mpUserList = wxService.getUserService().userList(nextOpenId);
logger.info(mpUserList.toString()); logger.info(mpUserList.toString());
List<WxMpUser> userList = wxService.getUserService().userInfoList(mpUserList.getOpenids());
logger.info(userList.toString());
saveToDB(userList, authorizerInfo);
getBatchUserInfos(wxService, mpUserList, authorizerInfo);
nextOpenId = mpUserList.getNextOpenid(); nextOpenId = mpUserList.getNextOpenid();
if(StringUtils.isBlank(nextOpenId)) { if(StringUtils.isBlank(nextOpenId)) {
break; break;
@@ -66,9 +59,32 @@ public class WxMemController {
return new ResultData(); return new ResultData();
} }


private void saveToDB(List<WxMpUser> userList, WxAuthorizerInfo authorizerInfo) {
for(WxMpUser mpUser: userList) {
userService.saveOrUpdateMpUser(mpUser, authorizerInfo);
private void getBatchUserInfos(WxMpService wxService, WxMpUserList mpUserList, WxAuthorizerInfo authorizerInfo) {
List<String> openIds = mpUserList.getOpenids();
if(openIds.size() > 100) {
int index = 0;
while(true) {
getBatchUserInfo(wxService, openIds.subList(index, index + 99), authorizerInfo);
index += 100;
}
} else {
getBatchUserInfo(wxService, openIds, authorizerInfo);
}
}

private void getBatchUserInfo(WxMpService wxService, List<String> openIds, WxAuthorizerInfo authorizerInfo) {
List<WxMpUser> userList = null;
try{
userList = wxService.getUserService().userInfoList(openIds);
} catch (WxErrorException e) {
logger.error("batchget userinfo list error: " + e.getMessage());
return;
}
if(userList != null) {
logger.info(userList.toString());
for(WxMpUser mpUser: userList) {
userService.saveOrUpdateMpUser(mpUser, authorizerInfo);
}
} }
} }
} }

Ładowanie…
Anuluj
Zapisz