「小程序JAVA实战」小程序的分享和下载功能(69)
转自:https://idig8.com/2018/09/25/xiaochengxujavashizhanxiaochengxudefenxianghexiazaigongneng68/
在小程序上无法分享朋友圈,只能通过发送指定用户和指定的用户群来进行扩散,必须掌握分享功能至关重要!
官方介绍
https://developers.weixin.qq.com/miniprogram/dev/framework/app-service/page.html#%E9%A1%B5%E9%9D%A2%E4%BA%8B%E4%BB%B6%E5%A4%84%E7%90%86%E5%87%BD%E6%95%B0

小程序分享代码
videoInfo.js
onShareAppMessage: function (res) {
var me = this;
var videoInfo = me.data.videoInfo;
return {
title: '短视频内容分析',
path: "pages/videoinfo/videoinfo?videoInfo=" + JSON.stringify(videoInfo),
imageUrl: "https://developers.weixin.qq.com/miniprogram/introduction/image/a.png?t=18090718"
}
},

实现小程序转发有二种方式,一种是用户点击右上角转发,一种是在html文件中通过button实现转发功能
- 第一种方式:
在官方文档中搜索转发出现:

点击链接会找到实例的代码:


这样就实现了转发功能了,这个里面的path一定要填路径,不然你转发给好友,好友点击会出现找不到页面的问题
第二中方法:
用户点击button触发转发事件,实现转发功能:
<button plain='true' open-type='share'>
</button>
放到wxml文件中,点击这个就可以实现转发了转发功能就是这么简单,其实只要多看微信的开发文档,这些功能还是很容易就实现的
小程序下载视频代码
- 官方介绍
>https://developers.weixin.qq.com/miniprogram/dev/api/network/download/wx.downloadFile.html

videoInfo
shareMe:function(){
var me = this;
var user = app.getGlobalUserInfo();
wx.showActionSheet({
itemList: ["下载到本地","举报用户","分享到好友"],
success:function(res){
if (res.tapIndex==0){
// 下载
wx.showLoading({
title: '下载中...',
})
wx.downloadFile({
url: app.serverUrl + me.data.videoInfo.videoPath,
success: function (res) {
// 只要服务器有响应数据,就会把响应内容写入文件并进入 success 回调,业务需要自行判断是否下载到了想要的内容
if (res.statusCode === 200) {
console.log(res.tempFilePath);
wx.saveVideoToPhotosAlbum({
filePath: res.tempFilePath,
success: function (res) {
console.log(res.errMsg)
wx.hideLoading();
}
})
}
}
})
} else if (res.tapIndex==1){
// 举报
var videoInfo = JSON.stringify(me.data.videoInfo);
var realUrl = '../videoInfo/videoInfo#videoInfo@' + videoInfo;
if (user == null || user == undefined || user == '') {
wx.navigateTo({
url: '../userLogin/userLogin?realUrl=' + realUrl,
})
} else {
var publishUserId = me.data.videoInfo.userId;
var videoId = me.data.videoInfo.id;
var currentUserId = user.id;
wx.navigateTo({
url: '../report/report?videoId=' + videoId + "&publishUserId=" + publishUserId
})
}
} else{
}
}
})
},

下载需要2次调用api,第一次下载使用api来进行下载,然后使用保存在视频的目录的插件,2次完成视频的下载。
PS:分享和下载小程序在开发中非常的常见。了解文档的api,基本也很方便的实现对应的功能。
「小程序JAVA实战」小程序的分享和下载功能(69)的更多相关文章
- 「小程序JAVA实战」小程序的页面重定向(60)
转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudeyemianzhongdingxiang59/ 在我们正常的浏览网 ...
- 「小程序JAVA实战」小程序的flex布局(22)
转自:https://idig8.com/2018/08/09/xiaochengxu-chuji-22/ 之前已经把小程序的框架说完了,接下来说说小程序的组件,在说组件之前,先说说布局吧.源码:ht ...
- 「小程序JAVA实战」小程序的留言和评价功能(70)
转自:https://idig8.com/2018/10/28/xiaochengxujavashizhanxiaochengxudeliuyanhepingjiagongneng69/ 目前小程序这 ...
- 「小程序JAVA实战」小程序的举报功能开发(68)
转自:https://idig8.com/2018/09/25/xiaochengxujavashizhanxiaochengxudeweixinapicaidancaozuo66-2/ 通过点击举报 ...
- 「小程序JAVA实战」小程序的个人信息作品,收藏,关注(66)
转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudegerenxinxizuopinshoucangguanzhu65 ...
- 「小程序JAVA实战」小程序的关注功能(65)
转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudeguanzhugongneng64/ 在个人页面,根据发布者个人和 ...
- 「小程序JAVA实战」小程序的视频点赞功能开发(62)
转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudeshipindianzangongnengkaifa61/ 视频点 ...
- 「小程序JAVA实战」小程序的springboot后台拦截器(61)
转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudespringboothoutailanjieqi60/ 之前咱们把 ...
- 「小程序JAVA实战」小程序首页视频(49)
转自:https://idig8.com/2018/09/21/xiaochengxujavashizhanxiaochengxushouyeshipin48/ 视频显示的内容是视频的截图,用户的头像 ...
随机推荐
- jxl将list导入到Excel中供下载
jxl操作excel /** * 分隔符 */ private final static String SEPARATOR = "|"; /** * 由List导出至指定的Shee ...
- ZOJ-3962-数位dp
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5594 16进制下的数位dp,由于固定了位数,可以出现前 ...
- 297. Serialize and Deserialize Binary Tree *HARD*
Serialization is the process of converting a data structure or object into a sequence of bits so tha ...
- [转载]c语言指针segmentation fault 指针常常错误的小地方
http://www.cnblogs.com/qingjoin/archive/2012/03/20/2408944.html #include <stdio.h> ] = ] = ] = ...
- 041——VUE中组件之pros数据的多种验证机制实例详解
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 微信小程序navigateTo /redirectTo/navigateBack 三者区别
navigateTo 不会将旧页面出栈: redirectTo 会将旧页面出栈,再将需要跳转到的页面入栈: navigateBack 则是将页面栈最后一个元素出栈,因此倒数第二个元素会成为最后一个元素 ...
- js遍历json的key和value
遍历json对象: 无规律: <script> var json = [{dd:'SB',AA:'东东',re1:123},{cccc:'dd',lk:'1qw'}]; for(var i ...
- 201621123006 《Java程序设计》第11周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多线程相关内容. 2. 书面作业 本次PTA作业题集多线程 1. 源代码阅读:多线程程序BounceThread 1.1 BallR ...
- New Concept English Two 18 46
$课文44 穿过森林 451. Mrs. Anne Sterling did not think of the risk she was taking when she ran through a ...
- HDU 1358
http://acm.hdu.edu.cn/showproblem.php?pid=1358 求某个前缀的周期,用Next求循环节的题目 #include <iostream> #incl ...