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
Show 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
;
import
lombok.Data
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.stereotype.Component
;
@Data
@Component
@ConfigurationProperties
(
prefix
=
"aliyun.rtc"
)
public
class
AliyunRtcConfig
{
private
String
accessKeyId
;
private
String
accessKeySecret
;
private
String
regionId
=
"cn-shanghai"
;
private
String
appId
;
private
String
ossBucket
;
private
String
ossEndpoint
=
"oss-cn-shanghai.aliyuncs.com"
;
}
\ No newline at end of file
//package com.yd.communication.api.config;
//
//import lombok.Data;
//import org.springframework.boot.context.properties.ConfigurationProperties;
//import org.springframework.stereotype.Component;
//
//@Data
//@Component
//@ConfigurationProperties(prefix = "aliyun.rtc")
//public class AliyunRtcConfig {
// private String accessKeyId;
// private String accessKeySecret;
// private String regionId = "cn-shanghai";
// private String appId;
// private String ossBucket;
// private String ossEndpoint = "oss-cn-shanghai.aliyuncs.com";
//}
\ 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
;
import
com.alibaba.fastjson2.JSONObject
;
import
com.aliyuncs.CommonRequest
;
import
com.aliyuncs.CommonResponse
;
import
com.aliyuncs.DefaultAcsClient
;
import
com.aliyuncs.IAcsClient
;
import
com.aliyuncs.http.MethodType
;
import
com.aliyuncs.live.model.v20161101.StopRtcCloudRecordingRequest
;
import
com.aliyuncs.live.model.v20161101.StopRtcCloudRecordingResponse
;
import
com.aliyuncs.profile.DefaultProfile
;
import
com.yd.communication.api.config.AliyunRtcConfig
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.util.HashMap
;
import
java.util.Map
;
@Service
@Slf4j
public
class
AliyunRtcRecordService
{
@Resource
private
AliyunRtcConfig
rtcConfig
;
private
IAcsClient
getClient
()
{
DefaultProfile
profile
=
DefaultProfile
.
getProfile
(
rtcConfig
.
getRegionId
(),
rtcConfig
.
getAccessKeyId
(),
rtcConfig
.
getAccessKeySecret
()
);
return
new
DefaultAcsClient
(
profile
);
}
public
String
startRecording
(
String
channelId
)
{
try
{
IAcsClient
client
=
getClient
();
CommonRequest
request
=
new
CommonRequest
();
request
.
setSysMethod
(
MethodType
.
POST
);
request
.
setSysDomain
(
"live.aliyuncs.com"
);
request
.
setSysVersion
(
"2016-11-01"
);
request
.
setSysAction
(
"StartRtcCloudRecording"
);
request
.
putQueryParameter
(
"AppId"
,
rtcConfig
.
getAppId
());
request
.
putQueryParameter
(
"ChannelId"
,
channelId
);
// 订阅所有用户(不传订阅参数则默认订阅所有)
request
.
putQueryParameter
(
"RecordParams.RecordMode"
,
"1"
);
request
.
putQueryParameter
(
"StorageParams.StorageType"
,
"1"
);
request
.
putQueryParameter
(
"StorageParams.OSSParams.OSSEndpoint"
,
rtcConfig
.
getOssEndpoint
());
request
.
putQueryParameter
(
"StorageParams.OSSParams.OSSBucket"
,
rtcConfig
.
getOssBucket
());
CommonResponse
response
=
client
.
getCommonResponse
(
request
);
String
responseData
=
response
.
getData
();
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
responseData
);
JSONObject
body
=
jsonObject
.
getJSONObject
(
"Body"
);
String
taskId
=
body
.
getString
(
"TaskId"
);
if
(
taskId
==
null
||
taskId
.
isEmpty
())
{
throw
new
RuntimeException
(
"启动录制失败,未返回 TaskId,响应:"
+
responseData
);
}
log
.
info
(
"启动录制成功, TaskId: {}"
,
taskId
);
return
taskId
;
}
catch
(
Exception
e
)
{
log
.
error
(
"启动录制失败"
,
e
);
throw
new
RuntimeException
(
"启动云端录制失败: "
+
e
.
getMessage
(),
e
);
}
}
public
void
stopRecording
(
String
taskId
)
{
try
{
IAcsClient
client
=
getClient
();
StopRtcCloudRecordingRequest
request
=
new
StopRtcCloudRecordingRequest
();
request
.
setTaskId
(
taskId
);
StopRtcCloudRecordingResponse
response
=
client
.
getAcsResponse
(
request
);
log
.
info
(
"停止录制成功, TaskId: {}"
,
taskId
);
}
catch
(
Exception
e
)
{
log
.
error
(
"停止录制失败"
,
e
);
throw
new
RuntimeException
(
"停止云端录制失败: "
+
e
.
getMessage
(),
e
);
}
}
/**
* 查询录制任务详情(文件信息)
* @param taskId
* @return
*/
public
Map
<
String
,
String
>
queryRecordingInfo
(
String
taskId
)
{
try
{
IAcsClient
client
=
getClient
();
CommonRequest
request
=
new
CommonRequest
();
request
.
setSysMethod
(
MethodType
.
POST
);
request
.
setSysDomain
(
"live.aliyuncs.com"
);
request
.
setSysVersion
(
"2016-11-01"
);
request
.
setSysAction
(
"DescribeCloudRecording"
);
request
.
putQueryParameter
(
"TaskId"
,
taskId
);
CommonResponse
response
=
client
.
getCommonResponse
(
request
);
String
responseData
=
response
.
getData
();
log
.
info
(
"查询录制信息响应: {}"
,
responseData
);
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
responseData
);
JSONObject
body
=
jsonObject
.
getJSONObject
(
"Body"
);
if
(
body
==
null
)
{
return
new
HashMap
<>();
}
Map
<
String
,
String
>
info
=
new
HashMap
<>();
// 根据实际返回字段解析,常见字段名
if
(
body
.
containsKey
(
"FileUrl"
))
{
info
.
put
(
"fileUrl"
,
body
.
getString
(
"FileUrl"
));
}
else
if
(
body
.
containsKey
(
"fileUrl"
))
{
info
.
put
(
"fileUrl"
,
body
.
getString
(
"fileUrl"
));
}
if
(
body
.
containsKey
(
"Duration"
))
{
info
.
put
(
"duration"
,
body
.
getString
(
"Duration"
));
}
else
if
(
body
.
containsKey
(
"duration"
))
{
info
.
put
(
"duration"
,
body
.
getString
(
"duration"
));
}
if
(
body
.
containsKey
(
"FileSize"
))
{
info
.
put
(
"size"
,
body
.
getString
(
"FileSize"
));
}
else
if
(
body
.
containsKey
(
"fileSize"
))
{
info
.
put
(
"size"
,
body
.
getString
(
"fileSize"
));
}
// 可能还有其他字段,如 RecordingStartTime, RecordingEndTime 等
return
info
;
}
catch
(
Exception
e
)
{
log
.
error
(
"查询录制信息失败"
,
e
);
throw
new
RuntimeException
(
"查询录制信息失败: "
+
e
.
getMessage
(),
e
);
}
}
}
\ No newline at end of file
//package com.yd.communication.api.record;
//
//import com.alibaba.fastjson2.JSONObject;
//import com.aliyuncs.CommonRequest;
//import com.aliyuncs.CommonResponse;
//import com.aliyuncs.DefaultAcsClient;
//import com.aliyuncs.IAcsClient;
//import com.aliyuncs.http.MethodType;
//import com.aliyuncs.live.model.v20161101.StopRtcCloudRecordingRequest;
//import com.aliyuncs.live.model.v20161101.StopRtcCloudRecordingResponse;
//import com.aliyuncs.profile.DefaultProfile;
//import com.yd.communication.api.config.AliyunRtcConfig;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.stereotype.Service;
//import javax.annotation.Resource;
//import java.util.HashMap;
//import java.util.Map;
//
//@Service
//@Slf4j
//public class AliyunRtcRecordService {
//
// @Resource
// private AliyunRtcConfig rtcConfig;
//
// private IAcsClient getClient() {
// DefaultProfile profile = DefaultProfile.getProfile(
// rtcConfig.getRegionId(),
// rtcConfig.getAccessKeyId(),
// rtcConfig.getAccessKeySecret()
// );
// return new DefaultAcsClient(profile);
// }
//
// public String startRecording(String channelId) {
// try {
// IAcsClient client = getClient();
// CommonRequest request = new CommonRequest();
// request.setSysMethod(MethodType.POST);
// request.setSysDomain("live.aliyuncs.com");
// request.setSysVersion("2016-11-01");
// request.setSysAction("StartRtcCloudRecording");
//
// request.putQueryParameter("AppId", rtcConfig.getAppId());
// request.putQueryParameter("ChannelId", channelId);
// // 订阅所有用户(不传订阅参数则默认订阅所有)
// request.putQueryParameter("RecordParams.RecordMode", "1");
// request.putQueryParameter("StorageParams.StorageType", "1");
// request.putQueryParameter("StorageParams.OSSParams.OSSEndpoint", rtcConfig.getOssEndpoint());
// request.putQueryParameter("StorageParams.OSSParams.OSSBucket", rtcConfig.getOssBucket());
//
// CommonResponse response = client.getCommonResponse(request);
// String responseData = response.getData();
// JSONObject jsonObject = JSONObject.parseObject(responseData);
// JSONObject body = jsonObject.getJSONObject("Body");
// String taskId = body.getString("TaskId");
// if (taskId == null || taskId.isEmpty()) {
// throw new RuntimeException("启动录制失败,未返回 TaskId,响应:" + responseData);
// }
// log.info("启动录制成功, TaskId: {}", taskId);
// return taskId;
// } catch (Exception e) {
// log.error("启动录制失败", e);
// throw new RuntimeException("启动云端录制失败: " + e.getMessage(), e);
// }
// }
//
// public void stopRecording(String taskId) {
// try {
// IAcsClient client = getClient();
// StopRtcCloudRecordingRequest request = new StopRtcCloudRecordingRequest();
// request.setTaskId(taskId);
// StopRtcCloudRecordingResponse response = client.getAcsResponse(request);
// log.info("停止录制成功, TaskId: {}", taskId);
// } catch (Exception e) {
// log.error("停止录制失败", e);
// throw new RuntimeException("停止云端录制失败: " + e.getMessage(), e);
// }
// }
//
// /**
// * 查询录制任务详情(文件信息)
// * @param taskId
// * @return
// */
// public Map<String, String> queryRecordingInfo(String taskId) {
// try {
// IAcsClient client = getClient();
// CommonRequest request = new CommonRequest();
// request.setSysMethod(MethodType.POST);
// request.setSysDomain("live.aliyuncs.com");
// request.setSysVersion("2016-11-01");
// request.setSysAction("DescribeCloudRecording");
// request.putQueryParameter("TaskId", taskId);
//
// CommonResponse response = client.getCommonResponse(request);
// String responseData = response.getData();
// log.info("查询录制信息响应: {}", responseData);
//
// JSONObject jsonObject = JSONObject.parseObject(responseData);
// JSONObject body = jsonObject.getJSONObject("Body");
// if (body == null) {
// return new HashMap<>();
// }
//
// Map<String, String> info = new HashMap<>();
// // 根据实际返回字段解析,常见字段名
// if (body.containsKey("FileUrl")) {
// info.put("fileUrl", body.getString("FileUrl"));
// } else if (body.containsKey("fileUrl")) {
// info.put("fileUrl", body.getString("fileUrl"));
// }
// if (body.containsKey("Duration")) {
// info.put("duration", body.getString("Duration"));
// } else if (body.containsKey("duration")) {
// info.put("duration", body.getString("duration"));
// }
// if (body.containsKey("FileSize")) {
// info.put("size", body.getString("FileSize"));
// } else if (body.containsKey("fileSize")) {
// info.put("size", body.getString("fileSize"));
// }
// // 可能还有其他字段,如 RecordingStartTime, RecordingEndTime 等
// return info;
// } catch (Exception e) {
// log.error("查询录制信息失败", e);
// throw new RuntimeException("查询录制信息失败: " + e.getMessage(), e);
// }
// }
//}
\ No newline at end of file
yd-communication-service/pom.xml
View file @
04375d70
...
...
@@ -74,19 +74,19 @@
<version>
${project.version}
</version>
</dependency>
<!-- 阿里云 Java SDK 核心库
-->
<dependency
>
<groupId>
com.aliyun
</groupId
>
<artifactId>
aliyun-java-sdk-core
</artifactId
>
<version>
4.6.3
</version
>
</dependency
>
<!-- <!– 阿里云 Java SDK 核心库 –>
-->
<!-- <dependency>--
>
<!-- <groupId>com.aliyun</groupId>--
>
<!-- <artifactId>aliyun-java-sdk-core</artifactId>--
>
<!-- <version>4.6.3</version>--
>
<!-- </dependency>--
>
<!-- 阿里云视频直播 SDK(包含 RTC 云端录制 API)
-->
<dependency
>
<groupId>
com.aliyun
</groupId
>
<artifactId>
aliyun-java-sdk-live
</artifactId
>
<version>
3.9.76
</version
>
</dependency
>
<!-- <!– 阿里云视频直播 SDK(包含 RTC 云端录制 API) –>
-->
<!-- <dependency>--
>
<!-- <groupId>com.aliyun</groupId>--
>
<!-- <artifactId>aliyun-java-sdk-live</artifactId>--
>
<!-- <version>3.9.76</version>--
>
<!-- </dependency>--
>
</dependencies>
</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