Procházet zdrojové kódy

保利威小程序播放凭证

he2802 před 4 roky
rodič
revize
d05776b3fe

+ 51 - 0
zhongzheng-api/src/main/java/com/zhongzheng/controller/polyv/PolyvVideoController.java

@@ -0,0 +1,51 @@
+package com.zhongzheng.controller.polyv;
+
+import com.zhongzheng.common.core.controller.BaseController;
+import com.zhongzheng.common.core.domain.AjaxResult;
+import com.zhongzheng.common.core.domain.model.LoginUser;
+import com.zhongzheng.common.utils.ServletUtils;
+import com.zhongzheng.framework.web.service.TokenService;
+import com.zhongzheng.framework.web.service.WxTokenService;
+import com.zhongzheng.modules.polyv.service.IPolyvVideoService;
+import com.zhongzheng.modules.polyv.vo.PolyvVideoQuerVo;
+import com.zhongzheng.modules.user.entity.ClientLoginUser;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.RequiredArgsConstructor;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * 保利威视频信息Controller
+ *
+ * @author ruoyi
+ * @date 2021-06-11
+ */
+@Api(value = "保利威视频信息控制器", tags = {"保利威视频信息管理"})
+@RequiredArgsConstructor(onConstructor_ = @Autowired)
+@RestController
+@RequestMapping("/polyv/video")
+public class PolyvVideoController extends BaseController {
+
+    private final IPolyvVideoService iPolyvVideoService;
+
+    @Autowired
+    private WxTokenService wxTokenService;
+
+
+    @ApiOperation("获取保利威视频小程序播放凭证")
+    @PreAuthorize("@ss.hasPermi('modules.polyv:video:query')")
+    @GetMapping("/sign/{vid}")
+    public AjaxResult<String> getPlayPcSign(@PathVariable("vid") String vid) throws Exception {
+        ClientLoginUser loginUser = wxTokenService.getLoginUser(ServletUtils.getRequest());
+        String viewerId = String.valueOf(loginUser.getUser().getUserId());
+        String token = iPolyvVideoService.polyvbMobileSignRequest(vid,viewerId);
+        return AjaxResult.success("成功",token);
+    }
+
+
+}

+ 2 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/polyv/service/IPolyvVideoService.java

@@ -52,4 +52,6 @@ public interface IPolyvVideoService extends IService<PolyvVideo> {
 	Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
 
 	String polyvbPcSignRequest(String VId,String viewerId) throws Exception;
+
+	String polyvbMobileSignRequest(String VId,String viewerId) throws Exception;
 }

+ 47 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/polyv/service/impl/PolyvVideoServiceImpl.java

@@ -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 {