在小程序上無法分享朋友圈,只能通過發送指定用戶和指定的用戶羣來進行擴散,必須掌握分享功能至關重要!源碼:https://github.com/limingios/wxProgram.git 中No.15和springboot
官方介紹
小程序分享代碼
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{ } } }) },
image.png
下載需要2次調用api,第一次下載使用api來進行下載,然後使用保存在視頻的目錄的插件,2次完成視頻的下載。
PS:分享和下載小程序在開發中非常的常見。瞭解文檔的api,基本也很方便的實現對應的功能。