摘要:仿抖音短视频小程序开发一项目的简介仿抖音短视频小程序开发二项目功能分析与具体实现源代码仿抖音短视频小程序开发全栈式实战项目短视频后台管理系统小程序的后台管理系统涉及的技术栈框架一用户列表的获取与分页前端代码用户列表展示的表格底部
</>复制代码
SpringBoot 仿抖音短视频小程序开发(一):项目的简介(https://segmentfault.com/a/11...
SpringBoot 仿抖音短视频小程序开发(二):项目功能分析与具体实现(https://segmentfault.com/a/11...
源代码: SpringBoot 仿抖音短视频小程序开发 全栈式实战项目(https://gitee.com/scau_zns/sh...)
短视频后台管理系统:(https://gitee.com/scau_zns/sh...
小程序的后台管理系统
涉及的技术栈:Bootstrap + jQuery + jGrid + SSM框架 + zookeeper
一、用户列表的获取与分页前端代码:
</>复制代码
jGrid发送请求获取数据封装好展示到页面
</>复制代码
// 用户列表
var handleList = function() {
// 上下文对象路径
var hdnContextPath = $("#hdnContextPath").val();
var apiServer = $("#apiServer").val();
var jqGrid = $("#usersList");
jqGrid.jqGrid({
caption: "短视频用户列表",
url: hdnContextPath + "/users/list.action",
mtype: "post",
styleUI: "Bootstrap",//设置jqgrid的全局样式为bootstrap样式
datatype: "json",
colNames: ["ID", "头像", "用户名", "昵称", "粉丝数", "关注数", "获赞数"],
colModel: [
{ name: "id", index: "id", width: 30, sortable: false, hidden: false },
{ name: "faceImage", index: "username", width: 50, sortable: false,
formatter:function(cellvalue, options, rowObject) {
var src = apiServer + cellvalue;
var img = "
使用jGrid发送请求给后台
二、背景音乐BGM的上传、查询和删除 上传</>复制代码
- // 条件查询所有用户列表
- $("#searchUserListButton").click(function(){
- var searchUsersListForm = $("#searchUserListForm");
- jqGrid.jqGrid().setGridParam({
- page: 1,
- url: hdnContextPath + "/users/list.action?" + searchUsersListForm.serialize(),
- }).trigger("reloadGrid");
- });
</>复制代码
- $("#file").fileupload({
- pasteZone: "#bgmContent",
- dataType: "json",
- done: function(e, data) {
- console.log(data);
- if (data.result.status != "200") {
- alert("长传失败...");
- } else {
- var bgmServer = $("#bgmServer").val();
- var url = bgmServer + data.result.data;
- $("#bgmContent").html("点我播放");
- $("#path").attr("value", data.result.data);
- }
- }
- });
后台接口保存BGM的方法参考上传头像的方法
分页查询参考用户列表信息的分页查询多少
删除BGM三、举报管理 禁止播放</>复制代码
- var deleteBgm = function(bgmId) {
- var flag = window.confirm("是否确认删除???");
- if (!flag) {
- return;
- }
- $.ajax({
- url: $("#hdnContextPath").val() + "/video/delBgm.action?bgmId=" + bgmId,
- type: "POST",
- success: function(data) {
- if (data.status == 200 && data.msg == "OK") {
- alert("删除成功~~");
- var jqGrid = $("#bgmList");
- jqGrid.jqGrid().trigger("reloadGrid");
- }
- }
- })
- }
四、后台管理系统增加或删除BGM,向zookeeper-server创建子节点,让小程序后端监听【重点】 1、首先安装Zookeeper到Linux上,启动服务器 2、编写zk客户端代码:</>复制代码
- var forbidVideo = function(videoId) {
- var flag = window.confirm("是否禁播");
- if (!flag) {
- return;
- }
- $.ajax({
- url: $("#hdnContextPath").val() + "/video/forbidVideo.action?videoId=" + videoId,
- type: "POST",
- async: false,
- success: function(data) {
- if(data.status == 200 && data.msg == "OK") {
- alert("操作成功");
- var jqGrid = $("#usersReportsList");
- //reloadGrid是重新加载表格
- jqGrid.jqGrid().trigger("reloadGrid");
- } else {
- console.log(JSON.stringify(data));
- }
- }
- })
- }
3、在applicationContext-zookeeper.xml配置zookeeper:</>复制代码
- import org.apache.curator.framework.CuratorFramework;
- import org.apache.zookeeper.CreateMode;
- import org.apache.zookeeper.ZooDefs.Ids;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- public class ZKCurator {
- //zk客户端
- private CuratorFramework client = null;
- final static Logger log = LoggerFactory.getLogger(ZKCurator.class);
- public ZKCurator(CuratorFramework client) {
- this.client = client;
- }
- public void init() {
- client = client.usingNamespace("admin");
- try {
- //判断在admin命名空间下是否有bgm节点 /admin/bgm
- if( client.checkExists().forPath("/bgm") == null ) {
- //对于zk来讲,有两种类型的节点,一种是持久节点(永久存在,除非手动删除),另一种是临时节点(会话断开,自动删除)
- client.create().creatingParentContainersIfNeeded()
- .withMode(CreateMode.PERSISTENT) //持久节点
- .withACL(Ids.OPEN_ACL_UNSAFE) //匿名权限
- .forPath("/bgm");
- log.info("zookeeper客户端连接初始化成功");
- log.info("zookeeper服务端状态:{}",client.isStarted());
- }
- } catch (Exception e) {
- log.error("zookeeper客户端连接初始化失败");
- e.printStackTrace();
- }
- }
- /**
- * 增加或者删除Bgm,向zk-server创建子节点,供小程序后端监听
- * @param bgmId
- * @param operType
- */
- public void sendBgmOperator(String bgmId, String operObject) {
- try {
- client.create().creatingParentContainersIfNeeded()
- .withMode(CreateMode.PERSISTENT) //持久节点
- .withACL(Ids.OPEN_ACL_UNSAFE) //匿名权限
- .forPath("/bgm/" + bgmId, operObject.getBytes());
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
4、上传或者删除BGM时调用VideoServiceImpl.java的方法</>复制代码
5、小程序编写代码监听zookeeper的节点,并对其做出相应的删除和上传操作【重点】</>复制代码
- @Autowired
- private ZKCurator zKCurator;
- @Override
- public void addBgm(Bgm bgm) {
- String id = sid.nextShort();
- bgm.setId(id);
- bgmMapper.insert(bgm);
- Map
map = new HashMap<>(); - map.put("operType", BGMOperatorTypeEnum.ADD.type);
- map.put("path", bgm.getPath());
- zKCurator.sendBgmOperator(id, JSONUtils.toJSONString(map));
- }
- @Override
- public void deleteBgm(String id) {
- Bgm bgm = bgmMapper.selectByPrimaryKey(id);
- bgmMapper.deleteByPrimaryKey(id);
- Map
map = new HashMap<>(); - map.put("operType", BGMOperatorTypeEnum.DELETE.type);
- map.put("path", bgm.getPath());
- zKCurator.sendBgmOperator(id, JSONUtils.toJSONString(map));
- }
初始化zookeeper客户端
</>复制代码
- private CuratorFramework client = null;
- final static Logger log = LoggerFactory.getLogger(ZKCuratorClient.class);
- // public static final String ZOOKEEPER_SERVER = "120.79.18.36:2181";
- public void init() {
- if(client != null) {
- return;
- }
- //重试策略
- RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 5);
- //创建zk客户端 120.79.18.36:2181
- client = CuratorFrameworkFactory.builder().connectString(resourceConfig.getZookeeperServer()).sessionTimeoutMs(10000)
- .retryPolicy(retryPolicy).namespace("admin").build();
- //启动客户端
- client.start();
- try {
- addChildWatch("/bgm");
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
监听zk-server的节点,当短视频后台管理系统上传或者删除某个BGM的时候,小程序后台服务器通过Zookeeper监听自动下载背景音乐
</>复制代码
- public void addChildWatch(String nodePath) throws Exception {
- final PathChildrenCache cache = new PathChildrenCache(client, nodePath, true);
- cache.start();
- cache.getListenable().addListener(new PathChildrenCacheListener() {
- @Override
- public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception {
- if(event.getType().equals(PathChildrenCacheEvent.Type.CHILD_ADDED)){
- log.info("监听到事件CHILD_ADDED");
- //1. 从数据库查询bgm对象,获取路径Path
- String path = event.getData().getPath();
- String operatorObjStr = new String(event.getData().getData());
- Map
map = JsonUtils.jsonToPojo(operatorObjStr, Map.class); - String operatorType = map.get("operType");
- String songPath = map.get("path");
- // String[] arr = path.split("/");
- // String bgmId = arr[arr.length-1];
- // Bgm bgm = bgmService.queryBgmById(bgmId);
- // if(bgm == null){
- // return;
- // }
- //1.1 bgm所在的相对路径
- // String songPath = bgm.getPath();
- //2. 定义保存到本地的bgm路径
- // String filePath = "E:imooc_videos_dev" + songPath;
- String filePath = resourceConfig.getFileSpace() + songPath;
- //3. 定义下载的路径(播放url)
- String[] arrPath = songPath.split(""); //windows
- // String[] arrPath = songPath.split("/"); //linux
- String finalPath = "";
- //3.1 处理url的斜杠以及编码
- for(int i=0; i
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/77553.html
摘要:一项目简介模仿抖音做的一个短视频微信小程序,用搭建小程序后台,用框架搭建短视频后台管理系统,小程序后台通过分布式监听节点自动下载或删除短视频后台管理系统上传的视频。 一、项目简介 模仿抖音做的一个短视频微信小程序,用SpringBoot搭建小程序后台,用SSM框架搭建短视频后台管理系统,小程序后台通过分布式zookeeper监听节点自动下载或删除短视频后台管理系统上传的视频。 二、环境...
阅读 913·2021-09-28 09:35
阅读 2718·2019-08-29 11:25
阅读 2248·2019-08-23 18:36
阅读 1987·2019-08-23 16:31
阅读 2171·2019-08-23 14:50
阅读 3249·2019-08-23 13:55
阅读 3399·2019-08-23 12:49
阅读 2220·2019-08-23 11:46