|
|
@@ -86,9 +86,7 @@ public class LiveController extends AppBaseController {
|
|
|
private ICompanyUserService companyUserService;
|
|
|
@Autowired
|
|
|
private IFsUserService userService;
|
|
|
- @Autowired
|
|
|
- @Qualifier("JSTErpOrderServiceImpl")
|
|
|
- private IErpOrderService jSTOrderService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private ILiveOrderService liveOrderService;
|
|
|
@Autowired
|
|
|
@@ -332,10 +330,10 @@ public class LiveController extends AppBaseController {
|
|
|
|
|
|
@Autowired
|
|
|
private WxMaProperties properties;
|
|
|
-
|
|
|
+
|
|
|
@Autowired
|
|
|
private RedisCache redisCache;
|
|
|
-
|
|
|
+
|
|
|
@ApiOperation("微信直播间urlScheme")
|
|
|
@GetMapping("/getAppletScheme")
|
|
|
public R getAppletScheme(@RequestParam(value = "liveId") Long liveId,@RequestParam(value = "companyUserId") Long companyUserId) {
|
|
|
@@ -356,37 +354,37 @@ public class LiveController extends AppBaseController {
|
|
|
String param = "liveId=" + liveId + "&companyUserId=" + companyUser.getUserId() + "&companyId=" + companyUser.getCompanyId() ;
|
|
|
String appId = properties.getConfigs().get(0).getAppid();
|
|
|
String secret = properties.getConfigs().get(0).getSecret();
|
|
|
-
|
|
|
+
|
|
|
// 从 Redis 缓存中获取 access_token
|
|
|
String cacheKey = "wx:access_token:" + appId;
|
|
|
String access_token = redisCache.getCacheObject(cacheKey);
|
|
|
-
|
|
|
+
|
|
|
// 如果缓存中没有或已过期,则重新获取
|
|
|
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);
|
|
|
JSONObject obj = JSONObject.parseObject(rspStr);
|
|
|
access_token = obj.getString("access_token");
|
|
|
-
|
|
|
+
|
|
|
// 检查是否获取成功
|
|
|
if (StringUtils.isEmpty(access_token)) {
|
|
|
log.error("获取微信 access_token 失败: {}", obj);
|
|
|
return R.error("获取微信 access_token 失败");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 将 access_token 存入 Redis,缓存时间为 7200 秒
|
|
|
redisCache.setCacheObject(cacheKey, access_token, 7200, java.util.concurrent.TimeUnit.SECONDS);
|
|
|
log.info("微信 access_token 已刷新并缓存,appId: {}", appId);
|
|
|
} else {
|
|
|
log.debug("从 Redis 缓存中获取 access_token,appId: {}", appId);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
JSONObject jump_wxaObj = new JSONObject();
|
|
|
// 跳转直播间
|
|
|
jump_wxaObj.put("page_url", "pages_course/living.html?" + param);
|
|
|
String paramStr = jump_wxaObj.toJSONString();
|
|
|
String postStr = HttpUtils.sendPost("https://api.weixin.qq.com/wxa/genwxashortlink?access_token=" + access_token, paramStr);
|
|
|
JSONObject obj = JSONObject.parseObject(postStr);
|
|
|
-
|
|
|
+
|
|
|
// 如果 access_token 失效,清除缓存并重新获取
|
|
|
if (obj != null && (obj.getInteger("errcode") != null && obj.getInteger("errcode") == 40001)) {
|
|
|
log.warn("access_token 已失效,清除缓存并重新获取,appId: {}", appId);
|
|
|
@@ -402,7 +400,7 @@ public class LiveController extends AppBaseController {
|
|
|
obj = JSONObject.parseObject(postStr);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
//response.addHeader("Access-Control-Allow-Origin", "*");
|
|
|
return R.ok().put("result", obj);
|
|
|
} catch (Exception e) {
|