|
@@ -268,10 +268,10 @@ public class WeChatServiceImpl implements WeChatService, InitializingBean {
|
|
|
|
|
|
String lockKey = String.format(Constants.LOCK_SYNC_USER,accountId);
|
|
|
String lockValue = cache.getIfPresent(lockKey);
|
|
|
- if (StringUtils.isEmpty(lockValue)) {
|
|
|
+ if (!StringUtils.isEmpty(lockValue)) {
|
|
|
throw new CustomException(500,"当前公众号正在后台同步粉丝数据,请您稍等一会!");
|
|
|
}
|
|
|
- cache.put(lockKey,lockValue);
|
|
|
+ cache.put(lockKey,lockKey);
|
|
|
logger.info("公众号:{}同步粉丝数据---- start,时间:{}",accountId, LocalDateTime.now().toString());
|
|
|
String requestUrl = "https://api.weixin.qq.com/cgi-bin/user/get?access_token=%s&next_openid=%s";
|
|
|
String nextOpenId = "";
|
|
@@ -340,6 +340,12 @@ public class WeChatServiceImpl implements WeChatService, InitializingBean {
|
|
|
@Override
|
|
|
@Async("asyncExecutor")
|
|
|
public void syncTag(String accountId) {
|
|
|
+ String lockKey = String.format(Constants.LOCK_SYNC_TAG,accountId);
|
|
|
+ String cacheValue = cache.getIfPresent(lockKey);
|
|
|
+ if (!StringUtils.isEmpty(cacheValue)) {
|
|
|
+ throw new CustomException(500,"");
|
|
|
+ }
|
|
|
+ cache.put(lockKey,lockKey);
|
|
|
String requestUrl = "https://api.weixin.qq.com/cgi-bin/tags/get?access_token=%s";
|
|
|
String accessToken = getAuthorizerAccessToken(accountId);
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
@@ -347,7 +353,23 @@ public class WeChatServiceImpl implements WeChatService, InitializingBean {
|
|
|
requestUrl = String.format(requestUrl,accessToken);
|
|
|
HttpEntity<MultiValueMap<String, String>> entity = new HttpEntity<> (headers);
|
|
|
ResponseEntity<String> respStr = restTemplate.exchange(requestUrl,HttpMethod.GET,entity,String.class);
|
|
|
- List<AccountTag> accountTags = JSONObject.parseArray(respStr.getBody(), AccountTag.class);
|
|
|
+ JSONArray jsonArray = JSONObject.parseObject(respStr.getBody()).getJSONArray("tags");
|
|
|
+ int size = jsonArray.size();
|
|
|
+ List<AccountTag> accountTags = new ArrayList<>(size);
|
|
|
+ JSONObject temp = null;
|
|
|
+ AccountTag tempTag = null;
|
|
|
+ String createTime = Constants.DATE_TIME_FORMATTER.format(LocalDateTime.now());
|
|
|
+ for (int i = 0; i < size; i++) {
|
|
|
+ temp = jsonArray.getJSONObject(i);
|
|
|
+ tempTag = new AccountTag();
|
|
|
+ tempTag.setAccountId(accountId);
|
|
|
+ tempTag.setFansCount(temp.getInteger("count"));
|
|
|
+ tempTag.setName(temp.getString("name"));
|
|
|
+ tempTag.setWxId(temp.getInteger("id"));
|
|
|
+ tempTag.setCreateTime(createTime);
|
|
|
+ accountTags.add(tempTag);
|
|
|
+ }
|
|
|
+ cache.invalidate(lockKey);
|
|
|
|
|
|
}
|
|
|
|