| @@ -1,13 +1,17 @@ | |||
| package com.iformall.controller; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.base.BaseEntity; | |||
| import com.iformall.domain.po.sm.MouldPatch; | |||
| import com.iformall.domain.po.sm.MouldPatchSign; | |||
| import com.iformall.domain.po.sm.UserMouldVideo; | |||
| import com.iformall.enums.EnumColour; | |||
| import com.iformall.enums.EnumMouldPatchType; | |||
| import com.iformall.enums.EnumMouldSendType; | |||
| import com.iformall.enums.EnumaMouldPatchStatus; | |||
| import com.iformall.language.LanguageDetect; | |||
| import com.iformall.service.sm.MouldPatchService; | |||
| import com.iformall.service.sm.MouldPatchSignService; | |||
| import io.swagger.annotations.Api; | |||
| @@ -60,4 +64,24 @@ public class MouldPatchController extends BaseController { | |||
| return new ResultData(mouldPatch); | |||
| } | |||
| @ApiOperation("根据输入文案获取音色") | |||
| @GetMapping("voiceList") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) | |||
| public ResultData voiceList(@RequestBody UserMouldVideo record, Integer pageNum, Integer pageSize) { | |||
| logger.debug("[" + getIpAddr() + "] MouldPatchController::voiceList"); | |||
| if (record == null || StringUtils.isBlank(record.getPaperwork())) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||
| } | |||
| LanguageDetect.detect(record.getPaperwork()); | |||
| MouldPatch mouldPatch = new MouldPatch(); | |||
| mouldPatch.setType(EnumMouldPatchType.voice_mould.getCode()); | |||
| mouldPatch.setSendType(EnumMouldSendType.auto.getCode()); | |||
| mouldPatch.setStatus(EnumaMouldPatchStatus.put_on.getCode()); | |||
| mouldPatch.setSortColumns(BaseEntity.SortField.UpdateDate_DESC); | |||
| return new ResultData(); | |||
| } | |||
| } | |||
| @@ -65,6 +65,10 @@ public class UserInviteCodeController extends BaseController { | |||
| UserInviteCode inviteCode = new UserInviteCode(); | |||
| inviteCode.setUserId(getMemberId()); | |||
| inviteCode = userInviteCodeService.selectOne(inviteCode); | |||
| if(inviteCode == null){ | |||
| inviteCode = new UserInviteCode(); | |||
| inviteCode.setStatus(EnumYesOrNo.YES.getCode()); | |||
| } | |||
| return new ResultData(inviteCode); | |||
| } | |||
| @@ -13,6 +13,8 @@ import com.iformall.enums.EnumaMouldPatchStatus; | |||
| import com.iformall.service.sm.MouldPatchService; | |||
| import com.iformall.service.sm.MouldPatchSignService; | |||
| import com.iformall.service.sm.UserMouldVideoService; | |||
| import com.iformall.video.VideoFactory; | |||
| import com.iformall.video.entity.VideUploadResult; | |||
| import io.swagger.annotations.Api; | |||
| import io.swagger.annotations.ApiImplicitParam; | |||
| import io.swagger.annotations.ApiImplicitParams; | |||
| @@ -39,6 +41,12 @@ public class UserMouldVideoController extends BaseController { | |||
| @Autowired | |||
| private MouldPatchService mouldPatchService; | |||
| @Autowired | |||
| private VideoFactory videoFactory; | |||
| @Autowired | |||
| String videoType; | |||
| @ApiOperation("分页列表接口") | |||
| @GetMapping("list") | |||
| @ApiImplicitParams({ | |||
| @@ -120,4 +128,18 @@ public class UserMouldVideoController extends BaseController { | |||
| return new ResultData(userMouldVideo); | |||
| } | |||
| @GetMapping(value = "/videoDetial") | |||
| @ApiOperation("视频详情") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "videoId", value = "视频编号", dataType = "String", paramType = "query", required = true)}) | |||
| public ResultData videoDetial(String videoId) { | |||
| try { | |||
| VideUploadResult videoDetail = videoFactory.getExcutor(videoType).getVideoDetailWithCache(videoId); | |||
| return new ResultData(videoDetail); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| return new ResultData(ErrorCode.PICTURE_ANALYZING_ERROR); | |||
| } | |||
| } | |||
| } | |||
| @@ -160,10 +160,15 @@ alipay: | |||
| callback: https://callbacktest.malls.iformall.com/api/alipay/notify/callback | |||
| video: | |||
| aliyun: | |||
| accessKeyId: LTAI4G7ixY4AhvM35F8o3W3V | |||
| accessKeySecret: VfWqGb83qIQrS9us45utskl8itd7ry | |||
| regionId: cn-beijing | |||
| aliyun: | |||
| accessKeyId: LTAI5tQs4MBjzLFbiQLjsMYy | |||
| accessKeySecret: nYmnexFJxrsBu0AGVIOSbUaSaweJu7 | |||
| regionId: cn-beijing | |||
| endPoint: https://oss-cn-beijing.aliyuncs.com | |||
| corePoolSize: 6 | |||
| maxPoolSize: 20 | |||
| queueCapacity: 1000 | |||
| namePrefix: aliyun-video-upload | |||
| jasypt: | |||
| encryptor: | |||
| @@ -1,8 +0,0 @@ | |||
| package com.iformall.service; | |||
| import com.iformall.domain.po.FengNiaoMapConfig; | |||
| public interface FengNiaoMapService { | |||
| FengNiaoMapConfig getConfigByTenantId(String tenantId); | |||
| } | |||
| @@ -68,7 +68,7 @@ | |||
| and `age` = #{age} | |||
| </if> | |||
| <if test=" null != sex "> | |||
| <if test=" null != colour "> | |||
| and `colour` = #{colour} | |||
| </if> | |||
| @@ -3,19 +3,25 @@ package com.iformall.video; | |||
| import java.io.File; | |||
| import java.io.InputStream; | |||
| import com.iformall.video.entity.VideTransResult; | |||
| import com.iformall.video.entity.VideUploadResult; | |||
| public interface VideoExcutor { | |||
| /** | |||
| * 上传视频 | |||
| * title:视频标题 | |||
| */ | |||
| public VideUploadResult uploadVideoStream(String title,InputStream inputStream,String ex); | |||
| public String getVedioUploadProgress(String videoId); | |||
| public String getVedioContentLength(String videoId); | |||
| VideUploadResult getVideoDetail(String videoId); | |||
| VideUploadResult getVideoDetailWithCache(String videoId); | |||
| VideUploadResult getVideoDetailFromApi(String videoId); | |||
| public VideTransResult transVideo(String videoId); | |||
| public VideTransResult getTransVideoResult(String videoId, String taskId); | |||
| } | |||
| @@ -8,8 +8,11 @@ import java.util.UUID; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.aliyuncs.vod.model.v20170321.CreateUploadVideoResponse; | |||
| import com.aliyuncs.vod.model.v20170321.GetPlayInfoResponse; | |||
| import com.aliyuncs.vod.model.v20170321.GetTranscodeTaskResponse; | |||
| import com.aliyuncs.vod.model.v20170321.SubmitTranscodeJobsResponse; | |||
| import com.baomidou.mybatisplus.core.toolkit.IdWorker; | |||
| import com.iformall.video.entity.VideTransResult; | |||
| import org.apache.commons.io.FileUtils; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| @@ -33,14 +36,14 @@ public class AliyunVideoExcutor implements VideoExcutor { | |||
| @Autowired | |||
| AliyunVideoConfig config; | |||
| @Autowired | |||
| AliyunVideoUploadThread thread; | |||
| @Autowired | |||
| @Qualifier("objectCommonRedisTemplate") | |||
| RedisTemplate<String, Object> redisTemplate; | |||
| @Autowired | |||
| @Qualifier("objectCommonRedisTemplate") | |||
| RedisTemplate<String, Object> redisTemplate; | |||
| private String getUrlByVeidoId(String videoId) { | |||
| try { | |||
| return AliyunVedioServer.getVedioUrl(config, videoId); | |||
| @@ -49,14 +52,14 @@ public class AliyunVideoExcutor implements VideoExcutor { | |||
| } | |||
| return null; | |||
| } | |||
| public DefaultAcsClient initVodClient() throws ClientException { | |||
| String regionId = config.getRegionId(); // 点播服务接入区域 | |||
| DefaultProfile profile = DefaultProfile.getProfile(regionId, config.getAccessKeyId(), config.getAccessKeySecret()); | |||
| DefaultAcsClient client = new DefaultAcsClient(profile); | |||
| return client; | |||
| String regionId = config.getRegionId(); // 点播服务接入区域 | |||
| DefaultProfile profile = DefaultProfile.getProfile(regionId, config.getAccessKeyId(), config.getAccessKeySecret()); | |||
| DefaultAcsClient client = new DefaultAcsClient(profile); | |||
| return client; | |||
| } | |||
| /** | |||
| * https://help.aliyun.com/document_detail/61063.html?spm=a2c4g.11186623.6.1036.2f81d418ydqsX8 | |||
| * https://help.aliyun.com/document_detail/55407.htm?spm=a2c4g.11186623.2.12.77aad4180Hg9y0#doc-api-vod-CreateUploadVideo | |||
| @@ -75,6 +78,11 @@ public class AliyunVideoExcutor implements VideoExcutor { | |||
| FileUtils.copyInputStreamToFile(inputStream, targetFile); | |||
| CreateUploadVideoResponse response =AliyunVedioServer.createUploadVideo(config, title, _tempfilepath); | |||
| result.setVideoId(response.getVideoId()); | |||
| if((!StringUtils.isBlank(config.getAutoTrans())) && ("Y".equals(config.getAutoTrans()) || "y".equals(config.getAutoTrans()))) { | |||
| result.setAutoTrans(true); | |||
| }else { | |||
| result.setAutoTrans(false); | |||
| } | |||
| //result.setVideoUrl(getUrlByVeidoId(response.getVideoId())); | |||
| result.setSuccess(true); | |||
| //TODO 线程池的方式 | |||
| @@ -110,47 +118,107 @@ public class AliyunVideoExcutor implements VideoExcutor { | |||
| } | |||
| @Override | |||
| public VideUploadResult getVideoDetail(String videoId) { | |||
| public VideUploadResult getVideoDetailWithCache(String videoId) { | |||
| VideUploadResult videoDetail = UploadCacheHelper.getVideoDetail(redisTemplate, videoId); | |||
| if(videoDetail != null){ | |||
| return videoDetail; | |||
| }else{ | |||
| VideUploadResult result = new VideUploadResult(); | |||
| result.setVideoId(videoId); | |||
| try { | |||
| GetPlayInfoResponse response = AliyunVedioServer.getPlayInfoResponse(config, videoId); | |||
| log.info("shipin---Detail{}"+JSON.toJSONString(response)); | |||
| if(response != null){ | |||
| List<GetPlayInfoResponse.PlayInfo> playInfoList = response.getPlayInfoList(); | |||
| //播放地址 | |||
| for (GetPlayInfoResponse.PlayInfo playInfo : playInfoList) { | |||
| result.setVideoUrl(playInfo.getPlayURL()); | |||
| break; | |||
| } | |||
| GetPlayInfoResponse.VideoBase videoBase = response.getVideoBase(); | |||
| result.setDuration(videoBase.getDuration()); | |||
| result.setCoverURL(videoBase.getCoverURL()); | |||
| result.setTitle(videoBase.getTitle()); | |||
| result.setSuccess(true); | |||
| if(StringUtils.isNotBlank(result.getCoverURL()) | |||
| && StringUtils.isNotBlank(result.getDuration()) | |||
| && !"0.0".equals(result.getDuration())){ | |||
| UploadCacheHelper.cacheVideoDetail(redisTemplate, videoId,result); | |||
| } | |||
| }else{ | |||
| result.setSuccess(false); | |||
| result.setMsg("未获取到视频"); | |||
| VideUploadResult result = getVideoDetailFromApi(videoId); | |||
| if(StringUtils.isNotBlank(result.getCoverURL()) | |||
| && StringUtils.isNotBlank(result.getDuration()) | |||
| && !"0.0".equals(result.getDuration())){ | |||
| UploadCacheHelper.cacheVideoDetail(redisTemplate, videoId,result); | |||
| } | |||
| return result; | |||
| } | |||
| } | |||
| @Override | |||
| public VideUploadResult getVideoDetailFromApi(String videoId) { | |||
| VideUploadResult result = new VideUploadResult(); | |||
| result.setVideoId(videoId); | |||
| try { | |||
| GetPlayInfoResponse response = AliyunVedioServer.getPlayInfoResponse(config, videoId); | |||
| log.info("shipin---Detail{}"+JSON.toJSONString(response)); | |||
| if(response != null){ | |||
| List<GetPlayInfoResponse.PlayInfo> playInfoList = response.getPlayInfoList(); | |||
| //播放地址 | |||
| for (GetPlayInfoResponse.PlayInfo playInfo : playInfoList) { | |||
| result.setVideoUrl(playInfo.getPlayURL()); | |||
| result.setHeight(playInfo.getHeight()); | |||
| result.setWidth(playInfo.getWidth()); | |||
| break; | |||
| } | |||
| } catch (ClientException e) { | |||
| GetPlayInfoResponse.VideoBase videoBase = response.getVideoBase(); | |||
| result.setDuration(videoBase.getDuration()); | |||
| result.setCoverURL(videoBase.getCoverURL()); | |||
| result.setTitle(videoBase.getTitle()); | |||
| result.setSuccess(true); | |||
| }else{ | |||
| result.setSuccess(false); | |||
| result.setMsg("获取视频请求异常"); | |||
| result.setMsg("未获取到视频"); | |||
| } | |||
| return result; | |||
| } catch (ClientException e) { | |||
| result.setSuccess(false); | |||
| result.setMsg("获取视频请求异常"); | |||
| } | |||
| return result; | |||
| } | |||
| @Override | |||
| public String getVedioContentLength(String videoId) { | |||
| return UploadCacheHelper.getContentLength(redisTemplate, videoId); | |||
| } | |||
| @Override | |||
| public VideTransResult transVideo(String videoId) { | |||
| VideTransResult result = new VideTransResult(); | |||
| //解码 | |||
| if ((!StringUtils.isBlank(videoId)) && (!StringUtils.isBlank(config.getTransTemplateId()))) { | |||
| result.setVideoId(videoId); | |||
| SubmitTranscodeJobsResponse transResponse = new SubmitTranscodeJobsResponse(); | |||
| try { | |||
| transResponse = AliyunVedioServer.submitTranscodeJobs(config, videoId, config.getTransTemplateId()); | |||
| //任务ID | |||
| //System.out.println("JobId = " + transResponse.getTranscodeJobs().get(0).getJobId()); | |||
| result.setTaskId(transResponse.getTranscodeTaskId()); | |||
| result.setSuccess(true); | |||
| return result; | |||
| }catch(Exception e) { | |||
| log.error(" aliyun uploadVideo trans error."+ videoId,e); | |||
| result.setSuccess(false); | |||
| result.setMsg(e.getLocalizedMessage()); | |||
| return result; | |||
| } | |||
| }else { | |||
| result.setSuccess(false); | |||
| result.setMsg("videoId或者转码模板编号为空"); | |||
| return result; | |||
| } | |||
| } | |||
| @Override | |||
| public VideTransResult getTransVideoResult(String videoId,String taskId) { | |||
| VideTransResult result = new VideTransResult(); | |||
| try { | |||
| GetTranscodeTaskResponse response = AliyunVedioServer.getTransTask(config, taskId); | |||
| if (null != response && "CompleteAllSucc".equals(response.getTranscodeTask().getTaskStatus())) { | |||
| result.setSuccess(true); | |||
| result.setTaskId(taskId); | |||
| result.setVideoId(videoId); | |||
| }else { | |||
| result.setSuccess(false); | |||
| result.setTaskId(taskId); | |||
| result.setVideoId(videoId); | |||
| result.setMsg(response.getTranscodeTask().getTaskStatus()); | |||
| } | |||
| } catch (Exception e) { | |||
| log.error(" aliyun uploadVideo getTransVideoResult error."+ videoId,e); | |||
| result.setSuccess(false); | |||
| result.setMsg(e.getLocalizedMessage()); | |||
| return result; | |||
| } | |||
| return result; | |||
| } | |||
| } | |||
| @@ -13,4 +13,6 @@ public class AliyunVideoConfig { | |||
| private String accessKeySecret; | |||
| private String regionId;//cn-shanghai 点播服务接入区域 | |||
| private String endPoint;//以华东1(杭州)为例,Endpoint填写为https://oss-cn-hangzhou.aliyuncs.com | |||
| private String transTemplateId;//转码的模板编号 | |||
| private String autoTrans; | |||
| } | |||
| @@ -9,6 +9,7 @@ import java.net.URL; | |||
| import java.util.Base64; | |||
| import java.util.List; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.springframework.data.redis.core.RedisTemplate; | |||
| import com.alibaba.fastjson.JSON; | |||
| @@ -24,55 +25,60 @@ import com.aliyuncs.vod.model.v20170321.CreateUploadVideoRequest; | |||
| import com.aliyuncs.vod.model.v20170321.CreateUploadVideoResponse; | |||
| import com.aliyuncs.vod.model.v20170321.GetPlayInfoRequest; | |||
| import com.aliyuncs.vod.model.v20170321.GetPlayInfoResponse; | |||
| import com.aliyuncs.vod.model.v20170321.GetTranscodeTaskRequest; | |||
| import com.aliyuncs.vod.model.v20170321.GetTranscodeTaskResponse; | |||
| import com.aliyuncs.vod.model.v20170321.RefreshUploadVideoRequest; | |||
| import com.aliyuncs.vod.model.v20170321.RefreshUploadVideoResponse; | |||
| import com.aliyuncs.vod.model.v20170321.SubmitTranscodeJobsRequest; | |||
| import com.aliyuncs.vod.model.v20170321.SubmitTranscodeJobsResponse; | |||
| import com.iformall.video.aliyun.config.AliyunVideoConfig; | |||
| import lombok.extern.slf4j.Slf4j; | |||
| import com.aliyuncs.exceptions.ClientException; | |||
| import com.aliyuncs.exceptions.ServerException; | |||
| import com.aliyuncs.http.FormatType; | |||
| @Slf4j | |||
| public class AliyunVedioServer { | |||
| private static DefaultAcsClient initVodClient(AliyunVideoConfig config) throws ClientException { | |||
| DefaultProfile profile = DefaultProfile.getProfile(config.getRegionId(), config.getAccessKeyId(), config.getAccessKeySecret()); | |||
| DefaultAcsClient client = new DefaultAcsClient(profile); | |||
| return client; | |||
| DefaultProfile profile = DefaultProfile.getProfile(config.getRegionId(), config.getAccessKeyId(), config.getAccessKeySecret()); | |||
| DefaultAcsClient client = new DefaultAcsClient(profile); | |||
| return client; | |||
| } | |||
| /** | |||
| * 获取视频上传地址和凭证 | |||
| * @param | |||
| * @return CreateUploadVideoResponse 获取视频上传地址和凭证响应数据 | |||
| * @throws Exception | |||
| */ | |||
| */ | |||
| public static CreateUploadVideoResponse createUploadVideo(AliyunVideoConfig config,String title,String fileName) throws Exception { | |||
| DefaultAcsClient client = initVodClient(config); | |||
| CreateUploadVideoRequest request = new CreateUploadVideoRequest(); | |||
| request.setTitle(title); | |||
| request.setFileName(fileName); | |||
| //UserData,用户自定义设置参数,用户需要单独回调URL及数据透传时设置(非必须) | |||
| //JSONObject userData = new JSONObject(); | |||
| //UserData回调部分设置 | |||
| //JSONObject messageCallback = new JSONObject(); | |||
| //messageCallback.put("CallbackURL", "http://192.168.0.0/16"); | |||
| //messageCallback.put("CallbackType", "http"); | |||
| //userData.put("MessageCallback", messageCallback.toJSONString()); | |||
| //UserData透传数据部分设置 | |||
| //JSONObject extend = new JSONObject(); | |||
| //extend.put("MyId", "user-defined-id"); | |||
| //userData.put("Extend", extend.toJSONString()); | |||
| //request.setUserData(userData.toJSONString()); | |||
| return client.getAcsResponse(request); | |||
| CreateUploadVideoRequest request = new CreateUploadVideoRequest(); | |||
| request.setTitle(title); | |||
| request.setFileName(fileName); | |||
| //UserData,用户自定义设置参数,用户需要单独回调URL及数据透传时设置(非必须) | |||
| //JSONObject userData = new JSONObject(); | |||
| //UserData回调部分设置 | |||
| //JSONObject messageCallback = new JSONObject(); | |||
| //messageCallback.put("CallbackURL", "http://192.168.0.0/16"); | |||
| //messageCallback.put("CallbackType", "http"); | |||
| //userData.put("MessageCallback", messageCallback.toJSONString()); | |||
| //UserData透传数据部分设置 | |||
| //JSONObject extend = new JSONObject(); | |||
| //extend.put("MyId", "user-defined-id"); | |||
| //userData.put("Extend", extend.toJSONString()); | |||
| //request.setUserData(userData.toJSONString()); | |||
| return client.getAcsResponse(request); | |||
| } | |||
| private static String toLanEndpoint(String bucket) { | |||
| return bucket.replace(".aliyuncs.com", "-internal.aliyuncs.com"); | |||
| } | |||
| @@ -83,15 +89,15 @@ public class AliyunVedioServer { | |||
| JSONObject uploadAuth = JSON.parseObject(uploadAuthStr); | |||
| JSONObject uploadAddress = JSON.parseObject(uploadAddressStr); | |||
| String bucket = uploadAddress.getString("Bucket"); | |||
| String endpoint = uploadAddress.getString("Endpoint"); | |||
| String fileName = uploadAddress.getString("FileName"); | |||
| String accessKeyId = uploadAuth.getString("AccessKeyId"); | |||
| String accessKeySecret = uploadAuth.getString("AccessKeySecret"); | |||
| String securityToken = uploadAuth.getString("SecurityToken"); | |||
| OSS client = new OSSClientBuilder().build(toLanEndpoint(endpoint), accessKeyId, accessKeySecret,securityToken); | |||
| return new OssUploadClient(bucket, toLanEndpoint(endpoint), fileName, client); | |||
| String endpoint = uploadAddress.getString("Endpoint"); | |||
| String fileName = uploadAddress.getString("FileName"); | |||
| String accessKeyId = uploadAuth.getString("AccessKeyId"); | |||
| String accessKeySecret = uploadAuth.getString("AccessKeySecret"); | |||
| String securityToken = uploadAuth.getString("SecurityToken"); | |||
| OSS client = new OSSClientBuilder().build(toLanEndpoint(endpoint), accessKeyId, accessKeySecret,securityToken); | |||
| return new OssUploadClient(bucket, toLanEndpoint(endpoint), fileName, client); | |||
| } | |||
| private static OssUploadClient initOssClient(RefreshUploadVideoResponse response) throws UnsupportedEncodingException { | |||
| final Base64.Decoder decoder = Base64.getDecoder(); | |||
| String uploadAddressStr = new String(decoder.decode(response.getUploadAddress().getBytes("UTF-8"))); | |||
| @@ -99,15 +105,15 @@ public class AliyunVedioServer { | |||
| JSONObject uploadAuth = JSON.parseObject(uploadAuthStr); | |||
| JSONObject uploadAddress = JSON.parseObject(uploadAddressStr); | |||
| String bucket = uploadAddress.getString("Bucket"); | |||
| String endpoint = uploadAddress.getString("Endpoint"); | |||
| String fileName = uploadAddress.getString("FileName"); | |||
| String accessKeyId = uploadAuth.getString("AccessKeyId"); | |||
| String accessKeySecret = uploadAuth.getString("AccessKeySecret"); | |||
| String securityToken = uploadAuth.getString("SecurityToken"); | |||
| OSS client = new OSSClientBuilder().build(toLanEndpoint(endpoint), accessKeyId, accessKeySecret,securityToken); | |||
| return new OssUploadClient(bucket, toLanEndpoint(endpoint), fileName, client); | |||
| String endpoint = uploadAddress.getString("Endpoint"); | |||
| String fileName = uploadAddress.getString("FileName"); | |||
| String accessKeyId = uploadAuth.getString("AccessKeyId"); | |||
| String accessKeySecret = uploadAuth.getString("AccessKeySecret"); | |||
| String securityToken = uploadAuth.getString("SecurityToken"); | |||
| OSS client = new OSSClientBuilder().build(toLanEndpoint(endpoint), accessKeyId, accessKeySecret,securityToken); | |||
| return new OssUploadClient(bucket, toLanEndpoint(endpoint), fileName, client); | |||
| } | |||
| public static void uploadVideo(AliyunVideoConfig config,CreateUploadVideoResponse response,String localFile,RedisTemplate<String, Object> redisTemplate) throws UnsupportedEncodingException { | |||
| OssUploadClient ossClient = initOssClient(response); | |||
| // 创建PutObjectRequest对象。 | |||
| @@ -121,10 +127,10 @@ public class AliyunVedioServer { | |||
| // metadata.setObjectAcl(CannedAccessControlList.Private); | |||
| // putObjectRequest.setMetadata(metadata); | |||
| // 上传文件。 | |||
| String videoId = response.getVideoId(); | |||
| try { | |||
| PutObjectResult result = ossClient.getOssClient().putObject(new PutObjectRequest(ossClient.getBucket(), ossClient.getFileName(), new File(localFile)). | |||
| <PutObjectRequest>withProgressListener(new PutObjectProgressListener(redisTemplate,response.getVideoId(),localFile))); | |||
| <PutObjectRequest>withProgressListener(new PutObjectProgressListener(redisTemplate,response.getVideoId(),localFile))); | |||
| }catch(Exception e) { | |||
| String msg = e.getLocalizedMessage(); | |||
| if (msg.contains("InvalidAccessKeyId")) { | |||
| @@ -133,34 +139,51 @@ public class AliyunVedioServer { | |||
| RefreshUploadVideoResponse refrshResoponse = refreshUploadVideo(config,response.getVideoId()); | |||
| ossClient1 = initOssClient(refrshResoponse); | |||
| ossClient1.getOssClient().putObject(new PutObjectRequest(ossClient1.getBucket(), ossClient1.getFileName(), new File(localFile)). | |||
| <PutObjectRequest>withProgressListener(new PutObjectProgressListener(redisTemplate,refrshResoponse.getVideoId(),localFile))); | |||
| <PutObjectRequest>withProgressListener(new PutObjectProgressListener(redisTemplate,refrshResoponse.getVideoId(),localFile))); | |||
| videoId = refrshResoponse.getVideoId(); | |||
| } catch (Exception e1) { | |||
| UploadCacheHelper.cacheError(redisTemplate, response.getVideoId()); | |||
| log.error(" aliyun uploadVideo error."+ response.getVideoId(),e); | |||
| videoId = ""; | |||
| } | |||
| if (null != ossClient1) { | |||
| ossClient1.getOssClient().shutdown(); | |||
| ossClient1.getOssClient().shutdown(); | |||
| } | |||
| }else { | |||
| UploadCacheHelper.cacheError(redisTemplate, response.getVideoId()); | |||
| log.error(" aliyun uploadVideo error."+ response.getVideoId(),e); | |||
| videoId = ""; | |||
| } | |||
| } | |||
| // 关闭OSSClient。 | |||
| ossClient.getOssClient().shutdown(); | |||
| ossClient.getOssClient().shutdown(); | |||
| } | |||
| /** | |||
| * 提交转码 | |||
| */ | |||
| public static SubmitTranscodeJobsResponse submitTranscodeJobs(AliyunVideoConfig config,String videoId,String templateId) throws Exception { | |||
| DefaultAcsClient client = initVodClient(config); | |||
| SubmitTranscodeJobsRequest request = new SubmitTranscodeJobsRequest(); | |||
| //需要转码的视频ID | |||
| request.setVideoId(videoId); | |||
| //转码模板ID | |||
| request.setTemplateGroupId(templateId); | |||
| return client.getAcsResponse(request); | |||
| } | |||
| public static RefreshUploadVideoResponse refreshUploadVideo(AliyunVideoConfig config,String videoId) throws Exception { | |||
| RefreshUploadVideoRequest request = new RefreshUploadVideoRequest(); | |||
| request.setVideoId("VideoId"); | |||
| request.setAcceptFormat(FormatType.JSON); | |||
| request.setSysReadTimeout(1000); | |||
| request.setSysConnectTimeout(1000); | |||
| DefaultAcsClient client = initVodClient(config); | |||
| return client.getAcsResponse(request); | |||
| RefreshUploadVideoRequest request = new RefreshUploadVideoRequest(); | |||
| request.setVideoId("VideoId"); | |||
| request.setAcceptFormat(FormatType.JSON); | |||
| request.setSysReadTimeout(1000); | |||
| request.setSysConnectTimeout(1000); | |||
| DefaultAcsClient client = initVodClient(config); | |||
| return client.getAcsResponse(request); | |||
| } | |||
| //获取视频播放地址 | |||
| //https://help.aliyun.com/document_detail/61064.html?spm=a2c4g.11186623.6.1043.7c2d3838K6wQPZ | |||
| public static String getVedioUrl(AliyunVideoConfig config,String videoId) throws ClientException { | |||
| @@ -168,16 +191,16 @@ public class AliyunVedioServer { | |||
| GetPlayInfoResponse response = new GetPlayInfoResponse(); | |||
| try { | |||
| GetPlayInfoRequest request = new GetPlayInfoRequest(); | |||
| request.setVideoId(videoId); | |||
| response = client.getAcsResponse(request); | |||
| List<GetPlayInfoResponse.PlayInfo> playInfoList = response.getPlayInfoList(); | |||
| //播放地址 | |||
| for (GetPlayInfoResponse.PlayInfo playInfo : playInfoList) { | |||
| return playInfo.getPlayURL(); | |||
| } | |||
| } catch (Exception e) { | |||
| log.error("getVedioUrl error.",e); | |||
| } | |||
| request.setVideoId(videoId); | |||
| response = client.getAcsResponse(request); | |||
| List<GetPlayInfoResponse.PlayInfo> playInfoList = response.getPlayInfoList(); | |||
| //播放地址 | |||
| for (GetPlayInfoResponse.PlayInfo playInfo : playInfoList) { | |||
| return playInfo.getPlayURL(); | |||
| } | |||
| } catch (Exception e) { | |||
| log.error("getVedioUrl error.",e); | |||
| } | |||
| return null; | |||
| } | |||
| @@ -195,4 +218,42 @@ public class AliyunVedioServer { | |||
| } | |||
| return null; | |||
| } | |||
| //查询转码任务详情 | |||
| //https://help.aliyun.com/document_detail/109342.html | |||
| public static GetTranscodeTaskResponse getTransTask(AliyunVideoConfig config,String taskId) throws ClientException { | |||
| DefaultAcsClient client = initVodClient(config); | |||
| try { | |||
| GetTranscodeTaskResponse response = new GetTranscodeTaskResponse(); | |||
| response = getTranscodeTask(client,taskId); | |||
| return response; | |||
| // //转码任务ID | |||
| // System.out.println("TranscodeTaskId = " + response.getTranscodeTask().getTranscodeTaskId()); | |||
| // //转码任务状态 | |||
| // System.out.println("TaskStatus = " + response.getTranscodeTask().getTaskStatus()); | |||
| // for (GetTranscodeTaskResponse.TranscodeTask.TranscodeJobInfo jobInfo : response.getTranscodeTask().getTranscodeJobInfoList()) { | |||
| // //转码作业ID | |||
| // System.out.println("TranscodeJobId = " + jobInfo.getTranscodeJobId()); | |||
| // //转码作业状态 | |||
| // System.out.println("TranscodeJobStatus = " + jobInfo.getTranscodeJobStatus()); | |||
| // //转码处理进度 | |||
| // System.out.println("TranscodeProgress = " + jobInfo.getTranscodeProgress()); | |||
| // //转码作业完成时间 | |||
| // System.out.println("CompleteTime = " + jobInfo.getCompleteTime()); | |||
| // | |||
| // } | |||
| } catch (Exception e) { | |||
| log.error("getTransTask error.",e); | |||
| } | |||
| return null; | |||
| // System.out.println("RequestId = " + response.getRequestId()); | |||
| } | |||
| private static GetTranscodeTaskResponse getTranscodeTask(DefaultAcsClient client,String taskId) throws Exception { | |||
| GetTranscodeTaskRequest request = new GetTranscodeTaskRequest(); | |||
| request.setTranscodeTaskId(taskId); | |||
| return client.getAcsResponse(request); | |||
| } | |||
| } | |||
| @@ -0,0 +1,11 @@ | |||
| package com.iformall.video.entity; | |||
| import lombok.Data; | |||
| @Data | |||
| public class VideTransResult { | |||
| private String videoId; | |||
| private boolean success = false; | |||
| private String msg; | |||
| private String taskId; | |||
| } | |||
| @@ -6,10 +6,15 @@ import lombok.Data; | |||
| public class VideUploadResult { | |||
| private String videoId; | |||
| private String videoUrl; | |||
| private Long height; | |||
| private Long Width; | |||
| private String coverURL;//视频封面 | |||
| private String duration;//视频时长 | |||
| private String title;//视频标题 | |||
| private String size;//视频大小 | |||
| private boolean success = false; | |||
| private String msg; | |||
| private boolean autoTrans;//是否自动转码 | |||
| } | |||