|
@@ -295,9 +295,10 @@ public class LiveController extends AppBaseController {
|
|
|
@GetMapping("/currentActivities")
|
|
@GetMapping("/currentActivities")
|
|
|
@Transactional
|
|
@Transactional
|
|
|
@Login
|
|
@Login
|
|
|
- public R currentActivities(Long liveId) {
|
|
|
|
|
-/* String userId = getUserId();
|
|
|
|
|
- return liveService.currentActivities(liveId,userId);*/
|
|
|
|
|
|
|
+ public R currentActivities(Long liveId, Long currentProgress, Integer replayFlag) {
|
|
|
|
|
+ if (replayFlag != null && replayFlag == 1 && currentProgress != null) {
|
|
|
|
|
+ return liveFacadeService.currentActivitiesWithProgress(liveId, getUserId(), currentProgress, replayFlag);
|
|
|
|
|
+ }
|
|
|
return liveFacadeService.currentActivities(liveId,getUserId());
|
|
return liveFacadeService.currentActivities(liveId,getUserId());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -313,10 +314,10 @@ public class LiveController extends AppBaseController {
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private WxMaProperties properties;
|
|
private WxMaProperties properties;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private RedisCache redisCache;
|
|
private RedisCache redisCache;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
@ApiOperation("微信直播间urlScheme")
|
|
@ApiOperation("微信直播间urlScheme")
|
|
|
@GetMapping("/getAppletScheme")
|
|
@GetMapping("/getAppletScheme")
|
|
|
public R getAppletScheme(@RequestParam(value = "liveId") Long liveId,@RequestParam(value = "companyUserId") Long companyUserId) {
|
|
public R getAppletScheme(@RequestParam(value = "liveId") Long liveId,@RequestParam(value = "companyUserId") Long companyUserId) {
|
|
@@ -337,37 +338,37 @@ public class LiveController extends AppBaseController {
|
|
|
String param = "liveId=" + liveId + "&companyUserId=" + companyUser.getUserId() + "&companyId=" + companyUser.getCompanyId() ;
|
|
String param = "liveId=" + liveId + "&companyUserId=" + companyUser.getUserId() + "&companyId=" + companyUser.getCompanyId() ;
|
|
|
String appId = properties.getConfigs().get(0).getAppid();
|
|
String appId = properties.getConfigs().get(0).getAppid();
|
|
|
String secret = properties.getConfigs().get(0).getSecret();
|
|
String secret = properties.getConfigs().get(0).getSecret();
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 从 Redis 缓存中获取 access_token
|
|
// 从 Redis 缓存中获取 access_token
|
|
|
String cacheKey = "wx:access_token:" + appId;
|
|
String cacheKey = "wx:access_token:" + appId;
|
|
|
String access_token = redisCache.getCacheObject(cacheKey);
|
|
String access_token = redisCache.getCacheObject(cacheKey);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 如果缓存中没有或已过期,则重新获取
|
|
// 如果缓存中没有或已过期,则重新获取
|
|
|
if (StringUtils.isEmpty(access_token)) {
|
|
if (StringUtils.isEmpty(access_token)) {
|
|
|
String rspStr = HttpUtils.sendGet("https://api.weixin.qq.com/cgi-bin/token", "grant_type=client_credential&" + "appid=" + appId + "&secret=" + secret);
|
|
String rspStr = HttpUtils.sendGet("https://api.weixin.qq.com/cgi-bin/token", "grant_type=client_credential&" + "appid=" + appId + "&secret=" + secret);
|
|
|
JSONObject obj = JSONObject.parseObject(rspStr);
|
|
JSONObject obj = JSONObject.parseObject(rspStr);
|
|
|
access_token = obj.getString("access_token");
|
|
access_token = obj.getString("access_token");
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 检查是否获取成功
|
|
// 检查是否获取成功
|
|
|
if (StringUtils.isEmpty(access_token)) {
|
|
if (StringUtils.isEmpty(access_token)) {
|
|
|
log.error("获取微信 access_token 失败: {}", obj);
|
|
log.error("获取微信 access_token 失败: {}", obj);
|
|
|
return R.error("获取微信 access_token 失败");
|
|
return R.error("获取微信 access_token 失败");
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 将 access_token 存入 Redis,缓存时间为 7200 秒
|
|
// 将 access_token 存入 Redis,缓存时间为 7200 秒
|
|
|
redisCache.setCacheObject(cacheKey, access_token, 7200, java.util.concurrent.TimeUnit.SECONDS);
|
|
redisCache.setCacheObject(cacheKey, access_token, 7200, java.util.concurrent.TimeUnit.SECONDS);
|
|
|
log.info("微信 access_token 已刷新并缓存,appId: {}", appId);
|
|
log.info("微信 access_token 已刷新并缓存,appId: {}", appId);
|
|
|
} else {
|
|
} else {
|
|
|
log.debug("从 Redis 缓存中获取 access_token,appId: {}", appId);
|
|
log.debug("从 Redis 缓存中获取 access_token,appId: {}", appId);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
JSONObject jump_wxaObj = new JSONObject();
|
|
JSONObject jump_wxaObj = new JSONObject();
|
|
|
// 跳转直播间
|
|
// 跳转直播间
|
|
|
jump_wxaObj.put("page_url", "pages_course/living.html?" + param);
|
|
jump_wxaObj.put("page_url", "pages_course/living.html?" + param);
|
|
|
String paramStr = jump_wxaObj.toJSONString();
|
|
String paramStr = jump_wxaObj.toJSONString();
|
|
|
String postStr = HttpUtils.sendPost("https://api.weixin.qq.com/wxa/genwxashortlink?access_token=" + access_token, paramStr);
|
|
String postStr = HttpUtils.sendPost("https://api.weixin.qq.com/wxa/genwxashortlink?access_token=" + access_token, paramStr);
|
|
|
JSONObject obj = JSONObject.parseObject(postStr);
|
|
JSONObject obj = JSONObject.parseObject(postStr);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 如果 access_token 失效,清除缓存并重新获取
|
|
// 如果 access_token 失效,清除缓存并重新获取
|
|
|
if (obj != null && (obj.getInteger("errcode") != null && obj.getInteger("errcode") == 40001)) {
|
|
if (obj != null && (obj.getInteger("errcode") != null && obj.getInteger("errcode") == 40001)) {
|
|
|
log.warn("access_token 已失效,清除缓存并重新获取,appId: {}", appId);
|
|
log.warn("access_token 已失效,清除缓存并重新获取,appId: {}", appId);
|
|
@@ -383,7 +384,7 @@ public class LiveController extends AppBaseController {
|
|
|
obj = JSONObject.parseObject(postStr);
|
|
obj = JSONObject.parseObject(postStr);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
//response.addHeader("Access-Control-Allow-Origin", "*");
|
|
//response.addHeader("Access-Control-Allow-Origin", "*");
|
|
|
return R.ok().put("result", obj);
|
|
return R.ok().put("result", obj);
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|