|
|
@@ -35,6 +35,8 @@ import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import static com.squareup.okhttp.internal.Util.md5Hex;
|
|
|
+
|
|
|
/**
|
|
|
* 保利威视频信息Service业务层处理
|
|
|
*
|
|
|
@@ -137,49 +139,31 @@ public class PolyvVideoServiceImpl extends ServiceImpl<PolyvVideoMapper, PolyvVi
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public String polyvbMobileSignRequest(String VId, String viewerId) throws Exception {
|
|
|
+ public Map<String,Object> polyvbMobileSignRequest(String VId, String viewerId) throws Exception {
|
|
|
viewerId = "MOBILE_"+ viewerId;
|
|
|
String redsKey = "PL_VIDEO_"+viewerId+VId;
|
|
|
- String token = redisCache.getCacheObject(redsKey);
|
|
|
+/* String token = redisCache.getCacheObject(redsKey);
|
|
|
if(token!=null){
|
|
|
return token;
|
|
|
- }
|
|
|
- String secretKey = poliv_token_secretkey;
|
|
|
+ }*/
|
|
|
+ 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"; //是否微信小程序播放
|
|
|
+ String videoId = VId; // 视频vid
|
|
|
+ long ts = System.currentTimeMillis(); // 时间戳
|
|
|
+ String extraParams = "HTML5"; // 自定义扩展参数
|
|
|
+ boolean disposable = false; // true 表示 token 仅一次有效。false 则表示在有效期内可以多次验证。默认为 false。
|
|
|
|
|
|
- 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;
|
|
|
+ /* 将参数 userId、secretkey、videoId、ts、viewerIp、viewerIp、viewerId、viewerName、extraParams按照ASCKII升序 key + value + key + value ... +value 拼接
|
|
|
+ */
|
|
|
+ String concated = "extraParams" + extraParams + "ts" + ts + "userId" + userId + "videoId" + videoId + "viewerId" + viewerId ;
|
|
|
+ // 首尾加上secretkey值
|
|
|
+ String plain = secretkey + concated + secretkey;
|
|
|
+ // 取大写MD5,可自行选择md5库
|
|
|
+ String sign = md5Hex(plain).toUpperCase();
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
+ map.put("sign",sign);
|
|
|
+ map.put("ts",ts);
|
|
|
+ return map;
|
|
|
}
|
|
|
|
|
|
|