|
@@ -0,0 +1,123 @@
|
|
|
+package com.zhongzheng.modules.tencentcloud.service.impl;
|
|
|
+
|
|
|
+
|
|
|
+import cn.hutool.core.lang.Validator;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.auth0.jwt.JWT;
|
|
|
+import com.auth0.jwt.algorithms.Algorithm;
|
|
|
+import com.auth0.jwt.exceptions.JWTCreationException;
|
|
|
+import com.tencentcloudapi.common.Credential;
|
|
|
+import com.tencentcloudapi.common.exception.TencentCloudSDKException;
|
|
|
+import com.tencentcloudapi.common.profile.ClientProfile;
|
|
|
+import com.tencentcloudapi.common.profile.HttpProfile;
|
|
|
+import com.tencentcloudapi.faceid.v20180301.FaceidClient;
|
|
|
+import com.tencentcloudapi.faceid.v20180301.models.ImageRecognitionRequest;
|
|
|
+import com.tencentcloudapi.faceid.v20180301.models.ImageRecognitionResponse;
|
|
|
+import com.tencentcloudapi.iai.v20200303.IaiClient;
|
|
|
+import com.tencentcloudapi.iai.v20200303.models.CompareFaceRequest;
|
|
|
+import com.tencentcloudapi.iai.v20200303.models.CompareFaceResponse;
|
|
|
+import com.tencentcloudapi.ocr.v20181119.OcrClient;
|
|
|
+import com.tencentcloudapi.ocr.v20181119.models.*;
|
|
|
+import com.tencentcloudapi.vod.v20180717.VodClient;
|
|
|
+import com.tencentcloudapi.vod.v20180717.models.DescribeMediaInfosRequest;
|
|
|
+import com.tencentcloudapi.vod.v20180717.models.DescribeMediaInfosResponse;
|
|
|
+import com.zhongzheng.common.exception.CustomException;
|
|
|
+import com.zhongzheng.common.utils.DateUtils;
|
|
|
+import com.zhongzheng.modules.alioss.bo.OssRequest;
|
|
|
+import com.zhongzheng.modules.alioss.service.OssService;
|
|
|
+import com.zhongzheng.modules.base.service.IUserProfileService;
|
|
|
+import com.zhongzheng.modules.tencentcloud.bo.FaceQueryBo;
|
|
|
+import com.zhongzheng.modules.tencentcloud.bo.InvoiceQueryBo;
|
|
|
+import com.zhongzheng.modules.tencentcloud.service.IFaceOcrService;
|
|
|
+import com.zhongzheng.modules.tencentcloud.service.IVodService;
|
|
|
+import com.zhongzheng.modules.user.service.IUserService;
|
|
|
+import com.zhongzheng.modules.user.vo.UserVo;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class VodServiceImpl implements IVodService {
|
|
|
+
|
|
|
+ @Value("${tencent.cloud.SecretId}")
|
|
|
+ private String SecretId;
|
|
|
+
|
|
|
+ @Value("${tencent.cloud.SecretKey}")
|
|
|
+ private String SecretKey;
|
|
|
+
|
|
|
+ @Value("${aliyun.oss.endpoint}")
|
|
|
+ private String ossHost;
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> describeMediaInfos(String[] fileIds) {
|
|
|
+ try{
|
|
|
+ Credential cred = new Credential(SecretId, SecretKey);
|
|
|
+ // 实例化一个http选项,可选的,没有特殊需求可以跳过
|
|
|
+ HttpProfile httpProfile = new HttpProfile();
|
|
|
+ httpProfile.setEndpoint("vod.tencentcloudapi.com");
|
|
|
+ // 实例化一个client选项,可选的,没有特殊需求可以跳过
|
|
|
+ ClientProfile clientProfile = new ClientProfile();
|
|
|
+ clientProfile.setHttpProfile(httpProfile);
|
|
|
+ // 实例化要请求产品的client对象,clientProfile是可选的
|
|
|
+ VodClient client = new VodClient(cred, "", clientProfile);
|
|
|
+ // 实例化一个请求对象,每个接口都会对应一个request对象
|
|
|
+ DescribeMediaInfosRequest req = new DescribeMediaInfosRequest();
|
|
|
+ req.setSubAppId(1306117675L);
|
|
|
+ String[] fileIdss = new String[]{"3270835015060309946"};
|
|
|
+ req.setFileIds(fileIdss);
|
|
|
+ // 返回的resp是一个DescribeMediaInfosResponse的实例,与请求对象对应
|
|
|
+ DescribeMediaInfosResponse resp = client.DescribeMediaInfos(req);
|
|
|
+
|
|
|
+ Map<String,Object> rs = new HashMap<>();
|
|
|
+ rs.put("name",resp.getMediaInfoSet()[0].getBasicInfo().getName());
|
|
|
+ rs.put("duration",resp.getMediaInfoSet()[0].getMetaData().getDuration());
|
|
|
+ System.out.println(rs);
|
|
|
+ return rs;
|
|
|
+ }catch (TencentCloudSDKException e){
|
|
|
+ System.out.println("错误"+e.getMessage());
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> vodSignRequest(String FileId) {
|
|
|
+ Integer AppId = 1306117675;
|
|
|
+ // String FileId = "4564972818519602447";
|
|
|
+ String AudioVideoType = "RawAdaptive";
|
|
|
+ Integer RawAdaptiveDefinition = 10;
|
|
|
+ Integer ImageSpriteDefinition = 10;
|
|
|
+ Long CurrentTime = DateUtils.getNowTime();
|
|
|
+ Long PsignExpire = DateUtils.getNowTime()+12*3600;
|
|
|
+ String UrlTimeExpire = Long.toHexString(PsignExpire);
|
|
|
+ String PlayKey = "TxtyhLlgo7J3iOADIron";
|
|
|
+ HashMap<String, Object> urlAccessInfo = new HashMap<String, Object>();
|
|
|
+ urlAccessInfo.put("t", UrlTimeExpire);
|
|
|
+ HashMap<String, Object> contentInfo = new HashMap<String, Object>();
|
|
|
+ contentInfo.put("audioVideoType", AudioVideoType);
|
|
|
+ // contentInfo.put("rawAdaptiveDefinition", RawAdaptiveDefinition);
|
|
|
+ contentInfo.put("imageSpriteDefinition", ImageSpriteDefinition);
|
|
|
+ System.out.println(urlAccessInfo);
|
|
|
+ try {
|
|
|
+ Algorithm algorithm = Algorithm.HMAC256(PlayKey);
|
|
|
+ String token = JWT.create().withClaim("appId", AppId).withClaim("fileId", FileId)
|
|
|
+ .withClaim("contentInfo", contentInfo)
|
|
|
+ .withClaim("currentTimeStamp", CurrentTime).withClaim("expireTimeStamp", PsignExpire)
|
|
|
+ .withClaim("urlAccessInfo", urlAccessInfo).sign(algorithm);
|
|
|
+ Map<String,Object> rs = new HashMap<>();
|
|
|
+ rs.put("fileID",FileId);
|
|
|
+ rs.put("appID",AppId);
|
|
|
+ rs.put("psign",token);
|
|
|
+ rs.put("licenseUrl","https://license.vod2.myqcloud.com/license/v2/1306117675_1/v_cube.license");
|
|
|
+ // System.out.println("token:" + token);
|
|
|
+ return rs;
|
|
|
+
|
|
|
+ } catch (JWTCreationException exception) {
|
|
|
+ // Invalid Signing configuration / Couldn't convert Claims.
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+}
|