|
|
@@ -136,6 +136,53 @@ public class PolyvVideoServiceImpl extends ServiceImpl<PolyvVideoMapper, PolyvVi
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public String polyvbMobileSignRequest(String VId, String viewerId) throws Exception {
|
|
|
+ viewerId = "MOBILE_"+ viewerId;
|
|
|
+ String redsKey = "PL_VIDEO_"+viewerId+VId;
|
|
|
+ String token = redisCache.getCacheObject(redsKey);
|
|
|
+ if(token!=null){
|
|
|
+ return token;
|
|
|
+ }
|
|
|
+ String secretKey = poliv_token_secretkey;
|
|
|
+ String userId = poliv_token_userid;
|
|
|
+ //业务参数
|
|
|
+ String url = "http://hls.videocc.net/service/v1/token";
|
|
|
+ String videoId = VId;
|
|
|
+ String ts = Long.toString(System.currentTimeMillis());
|
|
|
+ int expireTime = 30;//分钟
|
|
|
+ String disposable = "false"; //true:token仅一次有效
|
|
|
+ String iswxa = "1"; //是否微信小程序播放
|
|
|
+
|
|
|
+ Map<String, String> requestMap = new HashMap<>();
|
|
|
+ requestMap.put("userId", userId);
|
|
|
+ requestMap.put("videoId", videoId);
|
|
|
+ requestMap.put("ts", ts);
|
|
|
+ requestMap.put("viewerId", viewerId);
|
|
|
+ requestMap.put("expires", String.valueOf((expireTime*60))); //令牌有效期半小时
|
|
|
+ requestMap.put("disposable", disposable);
|
|
|
+ requestMap.put("iswxa", iswxa);
|
|
|
+
|
|
|
+ //用md5进行签名
|
|
|
+ requestMap.put("sign", PolyvUtils.getSignMd5(requestMap, secretKey));
|
|
|
+
|
|
|
+ String response = HttpUtils.postFormBody(url, requestMap);
|
|
|
+ try {
|
|
|
+ //解析json
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ TokenResponse tokenResponse = objectMapper.readValue(response, TokenResponse.class);
|
|
|
+ // 响应代码,200为成功,403为ts过期或签名错误,400为参数错误(例如缺少 userId 或 videoId)
|
|
|
+ if (tokenResponse.getCode() == 200) {
|
|
|
+ Map data = (Map) tokenResponse.getData();
|
|
|
+ token = data.get("token").toString();
|
|
|
+ redisCache.setCacheObject(redsKey, token, expireTime, TimeUnit.MINUTES);
|
|
|
+ return token;
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
|
|
|
|
|
|
public void polyvbRequest(String VId) throws Exception {
|