Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yd-communication
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
xingmin
yd-communication
Commits
04375d70
Commit
04375d70
authored
Jul 31, 2026
by
zhangxingmin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
push
parent
3b15b4e7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
162 additions
and
161 deletions
+162
-161
yd-communication-api/src/main/java/com/yd/communication/api/config/AliyunRtcConfig.java
+18
-18
yd-communication-api/src/main/java/com/yd/communication/api/record/AliyunRtcRecordService.java
+131
-131
yd-communication-service/pom.xml
+13
-12
No files found.
yd-communication-api/src/main/java/com/yd/communication/api/config/AliyunRtcConfig.java
View file @
04375d70
package
com
.
yd
.
communication
.
api
.
config
;
//package com.yd.communication.api.config;
//
import
lombok.Data
;
//import lombok.Data;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
//import org.springframework.boot.context.properties.ConfigurationProperties;
import
org.springframework.stereotype.Component
;
//import org.springframework.stereotype.Component;
//
@Data
//@Data
@Component
//@Component
@ConfigurationProperties
(
prefix
=
"aliyun.rtc"
)
//@ConfigurationProperties(prefix = "aliyun.rtc")
public
class
AliyunRtcConfig
{
//public class AliyunRtcConfig {
private
String
accessKeyId
;
// private String accessKeyId;
private
String
accessKeySecret
;
// private String accessKeySecret;
private
String
regionId
=
"cn-shanghai"
;
// private String regionId = "cn-shanghai";
private
String
appId
;
// private String appId;
private
String
ossBucket
;
// private String ossBucket;
private
String
ossEndpoint
=
"oss-cn-shanghai.aliyuncs.com"
;
// private String ossEndpoint = "oss-cn-shanghai.aliyuncs.com";
}
//}
\ No newline at end of file
\ No newline at end of file
yd-communication-api/src/main/java/com/yd/communication/api/record/AliyunRtcRecordService.java
View file @
04375d70
package
com
.
yd
.
communication
.
api
.
record
;
//package com.yd.communication.api.record;
//
import
com.alibaba.fastjson2.JSONObject
;
//import com.alibaba.fastjson2.JSONObject;
import
com.aliyuncs.CommonRequest
;
//import com.aliyuncs.CommonRequest;
import
com.aliyuncs.CommonResponse
;
//import com.aliyuncs.CommonResponse;
import
com.aliyuncs.DefaultAcsClient
;
//import com.aliyuncs.DefaultAcsClient;
import
com.aliyuncs.IAcsClient
;
//import com.aliyuncs.IAcsClient;
import
com.aliyuncs.http.MethodType
;
//import com.aliyuncs.http.MethodType;
import
com.aliyuncs.live.model.v20161101.StopRtcCloudRecordingRequest
;
//import com.aliyuncs.live.model.v20161101.StopRtcCloudRecordingRequest;
import
com.aliyuncs.live.model.v20161101.StopRtcCloudRecordingResponse
;
//import com.aliyuncs.live.model.v20161101.StopRtcCloudRecordingResponse;
import
com.aliyuncs.profile.DefaultProfile
;
//import com.aliyuncs.profile.DefaultProfile;
import
com.yd.communication.api.config.AliyunRtcConfig
;
//import com.yd.communication.api.config.AliyunRtcConfig;
import
lombok.extern.slf4j.Slf4j
;
//import lombok.extern.slf4j.Slf4j;
import
org.springframework.stereotype.Service
;
//import org.springframework.stereotype.Service;
import
javax.annotation.Resource
;
//import javax.annotation.Resource;
import
java.util.HashMap
;
//import java.util.HashMap;
import
java.util.Map
;
//import java.util.Map;
//
@Service
//@Service
@Slf4j
//@Slf4j
public
class
AliyunRtcRecordService
{
//public class AliyunRtcRecordService {
//
@Resource
// @Resource
private
AliyunRtcConfig
rtcConfig
;
// private AliyunRtcConfig rtcConfig;
//
private
IAcsClient
getClient
()
{
// private IAcsClient getClient() {
DefaultProfile
profile
=
DefaultProfile
.
getProfile
(
// DefaultProfile profile = DefaultProfile.getProfile(
rtcConfig
.
getRegionId
(),
// rtcConfig.getRegionId(),
rtcConfig
.
getAccessKeyId
(),
// rtcConfig.getAccessKeyId(),
rtcConfig
.
getAccessKeySecret
()
// rtcConfig.getAccessKeySecret()
);
// );
return
new
DefaultAcsClient
(
profile
);
// return new DefaultAcsClient(profile);
}
// }
//
public
String
startRecording
(
String
channelId
)
{
// public String startRecording(String channelId) {
try
{
// try {
IAcsClient
client
=
getClient
();
// IAcsClient client = getClient();
CommonRequest
request
=
new
CommonRequest
();
// CommonRequest request = new CommonRequest();
request
.
setSysMethod
(
MethodType
.
POST
);
// request.setSysMethod(MethodType.POST);
request
.
setSysDomain
(
"live.aliyuncs.com"
);
// request.setSysDomain("live.aliyuncs.com");
request
.
setSysVersion
(
"2016-11-01"
);
// request.setSysVersion("2016-11-01");
request
.
setSysAction
(
"StartRtcCloudRecording"
);
// request.setSysAction("StartRtcCloudRecording");
//
request
.
putQueryParameter
(
"AppId"
,
rtcConfig
.
getAppId
());
// request.putQueryParameter("AppId", rtcConfig.getAppId());
request
.
putQueryParameter
(
"ChannelId"
,
channelId
);
// request.putQueryParameter("ChannelId", channelId);
// 订阅所有用户(不传订阅参数则默认订阅所有)
// // 订阅所有用户(不传订阅参数则默认订阅所有)
request
.
putQueryParameter
(
"RecordParams.RecordMode"
,
"1"
);
// request.putQueryParameter("RecordParams.RecordMode", "1");
request
.
putQueryParameter
(
"StorageParams.StorageType"
,
"1"
);
// request.putQueryParameter("StorageParams.StorageType", "1");
request
.
putQueryParameter
(
"StorageParams.OSSParams.OSSEndpoint"
,
rtcConfig
.
getOssEndpoint
());
// request.putQueryParameter("StorageParams.OSSParams.OSSEndpoint", rtcConfig.getOssEndpoint());
request
.
putQueryParameter
(
"StorageParams.OSSParams.OSSBucket"
,
rtcConfig
.
getOssBucket
());
// request.putQueryParameter("StorageParams.OSSParams.OSSBucket", rtcConfig.getOssBucket());
//
CommonResponse
response
=
client
.
getCommonResponse
(
request
);
// CommonResponse response = client.getCommonResponse(request);
String
responseData
=
response
.
getData
();
// String responseData = response.getData();
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
responseData
);
// JSONObject jsonObject = JSONObject.parseObject(responseData);
JSONObject
body
=
jsonObject
.
getJSONObject
(
"Body"
);
// JSONObject body = jsonObject.getJSONObject("Body");
String
taskId
=
body
.
getString
(
"TaskId"
);
// String taskId = body.getString("TaskId");
if
(
taskId
==
null
||
taskId
.
isEmpty
())
{
// if (taskId == null || taskId.isEmpty()) {
throw
new
RuntimeException
(
"启动录制失败,未返回 TaskId,响应:"
+
responseData
);
// throw new RuntimeException("启动录制失败,未返回 TaskId,响应:" + responseData);
}
// }
log
.
info
(
"启动录制成功, TaskId: {}"
,
taskId
);
// log.info("启动录制成功, TaskId: {}", taskId);
return
taskId
;
// return taskId;
}
catch
(
Exception
e
)
{
// } catch (Exception e) {
log
.
error
(
"启动录制失败"
,
e
);
// log.error("启动录制失败", e);
throw
new
RuntimeException
(
"启动云端录制失败: "
+
e
.
getMessage
(),
e
);
// throw new RuntimeException("启动云端录制失败: " + e.getMessage(), e);
}
// }
}
// }
//
public
void
stopRecording
(
String
taskId
)
{
// public void stopRecording(String taskId) {
try
{
// try {
IAcsClient
client
=
getClient
();
// IAcsClient client = getClient();
StopRtcCloudRecordingRequest
request
=
new
StopRtcCloudRecordingRequest
();
// StopRtcCloudRecordingRequest request = new StopRtcCloudRecordingRequest();
request
.
setTaskId
(
taskId
);
// request.setTaskId(taskId);
StopRtcCloudRecordingResponse
response
=
client
.
getAcsResponse
(
request
);
// StopRtcCloudRecordingResponse response = client.getAcsResponse(request);
log
.
info
(
"停止录制成功, TaskId: {}"
,
taskId
);
// log.info("停止录制成功, TaskId: {}", taskId);
}
catch
(
Exception
e
)
{
// } catch (Exception e) {
log
.
error
(
"停止录制失败"
,
e
);
// log.error("停止录制失败", e);
throw
new
RuntimeException
(
"停止云端录制失败: "
+
e
.
getMessage
(),
e
);
// throw new RuntimeException("停止云端录制失败: " + e.getMessage(), e);
}
// }
}
// }
//
/**
// /**
* 查询录制任务详情(文件信息)
// * 查询录制任务详情(文件信息)
* @param taskId
// * @param taskId
* @return
// * @return
*/
// */
public
Map
<
String
,
String
>
queryRecordingInfo
(
String
taskId
)
{
// public Map<String, String> queryRecordingInfo(String taskId) {
try
{
// try {
IAcsClient
client
=
getClient
();
// IAcsClient client = getClient();
CommonRequest
request
=
new
CommonRequest
();
// CommonRequest request = new CommonRequest();
request
.
setSysMethod
(
MethodType
.
POST
);
// request.setSysMethod(MethodType.POST);
request
.
setSysDomain
(
"live.aliyuncs.com"
);
// request.setSysDomain("live.aliyuncs.com");
request
.
setSysVersion
(
"2016-11-01"
);
// request.setSysVersion("2016-11-01");
request
.
setSysAction
(
"DescribeCloudRecording"
);
// request.setSysAction("DescribeCloudRecording");
request
.
putQueryParameter
(
"TaskId"
,
taskId
);
// request.putQueryParameter("TaskId", taskId);
//
CommonResponse
response
=
client
.
getCommonResponse
(
request
);
// CommonResponse response = client.getCommonResponse(request);
String
responseData
=
response
.
getData
();
// String responseData = response.getData();
log
.
info
(
"查询录制信息响应: {}"
,
responseData
);
// log.info("查询录制信息响应: {}", responseData);
//
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
responseData
);
// JSONObject jsonObject = JSONObject.parseObject(responseData);
JSONObject
body
=
jsonObject
.
getJSONObject
(
"Body"
);
// JSONObject body = jsonObject.getJSONObject("Body");
if
(
body
==
null
)
{
// if (body == null) {
return
new
HashMap
<>();
// return new HashMap<>();
}
// }
//
Map
<
String
,
String
>
info
=
new
HashMap
<>();
// Map<String, String> info = new HashMap<>();
// 根据实际返回字段解析,常见字段名
// // 根据实际返回字段解析,常见字段名
if
(
body
.
containsKey
(
"FileUrl"
))
{
// if (body.containsKey("FileUrl")) {
info
.
put
(
"fileUrl"
,
body
.
getString
(
"FileUrl"
));
// info.put("fileUrl", body.getString("FileUrl"));
}
else
if
(
body
.
containsKey
(
"fileUrl"
))
{
// } else if (body.containsKey("fileUrl")) {
info
.
put
(
"fileUrl"
,
body
.
getString
(
"fileUrl"
));
// info.put("fileUrl", body.getString("fileUrl"));
}
// }
if
(
body
.
containsKey
(
"Duration"
))
{
// if (body.containsKey("Duration")) {
info
.
put
(
"duration"
,
body
.
getString
(
"Duration"
));
// info.put("duration", body.getString("Duration"));
}
else
if
(
body
.
containsKey
(
"duration"
))
{
// } else if (body.containsKey("duration")) {
info
.
put
(
"duration"
,
body
.
getString
(
"duration"
));
// info.put("duration", body.getString("duration"));
}
// }
if
(
body
.
containsKey
(
"FileSize"
))
{
// if (body.containsKey("FileSize")) {
info
.
put
(
"size"
,
body
.
getString
(
"FileSize"
));
// info.put("size", body.getString("FileSize"));
}
else
if
(
body
.
containsKey
(
"fileSize"
))
{
// } else if (body.containsKey("fileSize")) {
info
.
put
(
"size"
,
body
.
getString
(
"fileSize"
));
// info.put("size", body.getString("fileSize"));
}
// }
// 可能还有其他字段,如 RecordingStartTime, RecordingEndTime 等
// // 可能还有其他字段,如 RecordingStartTime, RecordingEndTime 等
return
info
;
// return info;
}
catch
(
Exception
e
)
{
// } catch (Exception e) {
log
.
error
(
"查询录制信息失败"
,
e
);
// log.error("查询录制信息失败", e);
throw
new
RuntimeException
(
"查询录制信息失败: "
+
e
.
getMessage
(),
e
);
// throw new RuntimeException("查询录制信息失败: " + e.getMessage(), e);
}
// }
}
// }
}
//}
\ No newline at end of file
\ No newline at end of file
yd-communication-service/pom.xml
View file @
04375d70
...
@@ -74,19 +74,19 @@
...
@@ -74,19 +74,19 @@
<version>
${project.version}
</version>
<version>
${project.version}
</version>
</dependency>
</dependency>
<!-- 阿里云 Java SDK 核心库
-->
<!-- <!– 阿里云 Java SDK 核心库 –>
-->
<dependency
>
<!-- <dependency>--
>
<groupId>
com.aliyun
</groupId
>
<!-- <groupId>com.aliyun</groupId>--
>
<artifactId>
aliyun-java-sdk-core
</artifactId
>
<!-- <artifactId>aliyun-java-sdk-core</artifactId>--
>
<version>
4.6.3
</version
>
<!-- <version>4.6.3</version>--
>
</dependency
>
<!-- </dependency>--
>
<!-- 阿里云视频直播 SDK(包含 RTC 云端录制 API)
-->
<!-- <!– 阿里云视频直播 SDK(包含 RTC 云端录制 API) –>
-->
<dependency
>
<!-- <dependency>--
>
<groupId>
com.aliyun
</groupId
>
<!-- <groupId>com.aliyun</groupId>--
>
<artifactId>
aliyun-java-sdk-live
</artifactId
>
<!-- <artifactId>aliyun-java-sdk-live</artifactId>--
>
<version>
3.9.76
</version
>
<!-- <version>3.9.76</version>--
>
</dependency
>
<!-- </dependency>--
>
</dependencies>
</dependencies>
</project>
</project>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment