|
|
|
|
@ -0,0 +1,65 @@
|
|
|
|
|
package com.flossom.system.controller;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
import com.flossom.common.core.constant.CacheConstants;
|
|
|
|
|
import com.flossom.common.core.domain.R;
|
|
|
|
|
import com.flossom.common.core.domain.shuyun.AccessToken;
|
|
|
|
|
import com.flossom.common.redis.service.RedisService;
|
|
|
|
|
import com.flossom.system.utils.shuyun.ShuYunConfig;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
import java.time.ZoneId;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 数云回调接口
|
|
|
|
|
*/
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/shuyun")
|
|
|
|
|
public class ShuYunCallbackController {
|
|
|
|
|
|
|
|
|
|
protected final static Logger logger = LoggerFactory.getLogger(ShuYunCallbackController.class);
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ShuYunConfig shuYunConfig;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private RedisService redisService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 数云回调接口,获取 accessToken,并将 accessToken 缓存起来
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping(value = "/accessToken")
|
|
|
|
|
public R accessToken(@RequestBody List<AccessToken> accessTokenList) {
|
|
|
|
|
logger.info("数云回调结果accessTokenList: {}", accessTokenList);
|
|
|
|
|
/**
|
|
|
|
|
* 缓存 accessToken
|
|
|
|
|
*/
|
|
|
|
|
if (accessTokenList != null && accessTokenList.size() > 0) {
|
|
|
|
|
for (AccessToken accessToken : accessTokenList) {
|
|
|
|
|
if (StringUtils.equals(accessToken.getAppId(), shuYunConfig.getAppid())) {
|
|
|
|
|
logger.info("缓存数云accessToken:{}", accessToken);
|
|
|
|
|
if (StringUtils.isNotBlank(accessToken.getAccessToken())) {
|
|
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
|
|
map.put(CacheConstants.SHUYUN_ACCESS_TOKEN_CACHE_VALUE, JSON.toJSONString(accessToken));
|
|
|
|
|
map.put(CacheConstants.SHUYUN_ACCESS_TOKEN_CACHE_EXPIRY, LocalDateTime.now().plusDays(1).atZone(ZoneId.systemDefault()).toEpochSecond());
|
|
|
|
|
redisService.setCacheMap(CacheConstants.SHUYUN_ACCESS_TOKEN_CACHE, map);
|
|
|
|
|
return R.ok("", "SUCCESS");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
logger.error("缓存数云accessToken失败:{}", accessTokenList);
|
|
|
|
|
return R.fail();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|