「小程序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{

        }
      }
    })
  },

image.png

下载需要2次调用api,第一次下载使用api来进行下载,然后使用保存在视频的目录的插件,2次完成视频的下载。

PS:分享和下载小程序在开发中非常的常见。了解文档的api,基本也很方便的实现对应的功能。

转载于:https://www.cnblogs.com/sharpest/p/10316636.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
160个项目开发实例,聊天项目,小游戏适和新手学习(项目采用GBK编码)。 import java.util.*; import java.io.*; import java.awt.*; import java.awt.event.*; import java.applet.*; import javax.swing.*; class Gobang extends JFrame implements Runnable, ActionListener { final static int Player=1; final static int AI =-1; ClassLoader cl = this.getClass().getClassLoader(); Toolkit tk = Toolkit.getDefaultToolkit(); int length=14, game_state, winner, check, step; int grid[][] = new int[length][length]; int locX, locY /* 囱竚 */, count /* 硈囱计 */, x, y /* 既竚 */, displace_x=0, displace_y=0 /* 簿秖 */, direction; ArrayList steps = new ArrayList(); /* 癘魁囱˙ */ JPopupMenu control_menu = new JPopupMenu(); /* 龄匡虫 */ JMenuItem[] command = new JMenuItem[4]; String[] command_str={"囱", "郎", "弄郎", "秨"}; int[][] dir = { {-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}, {1, 1} }; boolean[] dir2 = new boolean[8]; boolean turn; String message; final JDialog dialog = new JDialog(this, "叫匡", true); Font font=new Font("new_font", Font.BOLD, 20); Grid grids[][] = new Grid[length][length]; Image white= tk.getImage(cl.getResource("res/white.png")); Image black= tk.getImage(cl.getResource("res/black.png")); Image title= tk.getImage(cl.getResource("res/title.png")); Image temp; JPanel boardPanel, bigpanel; JRadioButton[] choice = new JRadioButton[2]; final static int Start =0; final static int Select =1; final static int Playing =2; final static int End =3; final static int nil=-1; /* 礚よ */ final static int oblique_1 =0; /* オ */ final static int oblique_2 =1; /* オ */ final static int horizontal =2; /* 绢 */ final static int vertical=3; /*  */ Gobang() { super("き囱"); boardPanel = new JPanel(); boardPanel.setLayout(new GridLayout(length, length, 0, 0)); boardPanel.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); for(int i=0; i<length; i++) for(int j=0; j<length; j++) {
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值