|
|
@@ -1,6 +1,7 @@
|
|
|
package com.fs.course.service.impl;
|
|
|
|
|
|
import cn.binarywang.wx.miniapp.api.WxMaService;
|
|
|
+import cn.hutool.crypto.SecureUtil;
|
|
|
import cn.hutool.http.HttpRequest;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
@@ -11,6 +12,7 @@ import com.fs.common.core.domain.R;
|
|
|
import com.fs.common.utils.DateUtils;
|
|
|
import com.fs.common.utils.PubFun;
|
|
|
import com.fs.common.utils.StringUtils;
|
|
|
+import com.fs.common.core.redis.RedisCache;
|
|
|
import com.fs.common.utils.date.DateUtil;
|
|
|
import com.fs.company.domain.Company;
|
|
|
import com.fs.company.domain.CompanyMiniapp;
|
|
|
@@ -78,6 +80,7 @@ import java.time.ZoneId;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collections;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
import static com.fs.course.utils.LinkUtil.generateRandomStringWithLock;
|
|
|
import static com.fs.sop.service.impl.SopUserLogsInfoServiceImpl.convertStringToDate;
|
|
|
@@ -138,6 +141,9 @@ public class FsCourseLinkServiceImpl implements IFsCourseLinkService
|
|
|
@Autowired
|
|
|
private ICompanyService companyService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private RedisCache redisCache;
|
|
|
+
|
|
|
private static String TOKEN_VALID_CODE = "40001";
|
|
|
|
|
|
private volatile Integer version = 0;
|
|
|
@@ -822,6 +828,14 @@ public class FsCourseLinkServiceImpl implements IFsCourseLinkService
|
|
|
*/
|
|
|
@Override
|
|
|
public String getGotoWxAppLink(String linkStr, String appId) {
|
|
|
+ // URL Link缓存:避免重复生成导致85406访问限制
|
|
|
+ String cacheKey = buildUrlLinkCacheKey(linkStr);
|
|
|
+ String cached = redisCache.getCacheObject(cacheKey);
|
|
|
+ if (StringUtils.isNotEmpty(cached)) {
|
|
|
+ log.info("URL Link命中缓存,linkStr:{}", linkStr);
|
|
|
+ return cached;
|
|
|
+ }
|
|
|
+
|
|
|
Long companyId = parseCompanyIdFromLink(linkStr);
|
|
|
|
|
|
List<String> appIdList = getAppIdListByCompanyId(companyId);
|
|
|
@@ -835,7 +849,9 @@ public class FsCourseLinkServiceImpl implements IFsCourseLinkService
|
|
|
currentIndex = appIdList.indexOf(appId);
|
|
|
}
|
|
|
|
|
|
- return generateWxAppLinkWithRetry(linkStr, appIdList, currentIndex);
|
|
|
+ String result = generateWxAppLinkWithRetry(linkStr, appIdList, currentIndex);
|
|
|
+ cacheUrlLinkIfSuccess(cacheKey, result);
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -846,10 +862,26 @@ public class FsCourseLinkServiceImpl implements IFsCourseLinkService
|
|
|
if (StringUtils.isNotBlank(appId) && appIdList.contains(appId)) {
|
|
|
currentIndex = appIdList.indexOf(appId);
|
|
|
}
|
|
|
-
|
|
|
return generateWxAppLinkWithRetryForPreOrder(linkStr, appIdList, currentIndex);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 构建URL Link缓存key
|
|
|
+ */
|
|
|
+ private String buildUrlLinkCacheKey(String linkStr) {
|
|
|
+ return "wx:url_link:" + SecureUtil.md5(linkStr);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成成功时缓存URL Link,有效期25天(微信URL Link有效期为30天)
|
|
|
+ */
|
|
|
+ private void cacheUrlLinkIfSuccess(String cacheKey, String result) {
|
|
|
+ if (StringUtils.isNotEmpty(result) && result.contains("链接1:")) {
|
|
|
+ redisCache.setCacheObject(cacheKey, result, 25, TimeUnit.DAYS);
|
|
|
+ log.info("URL Link已缓存,cacheKey:{}", cacheKey);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 从链接字符串中解析companyId
|
|
|
* @param linkStr 链接字符串,格式如:/pages_course/videovip?course={"companyId":123,...}
|