uni-app app分享到朋友和朋友圈

app分享到朋友和朋友圈

uni.share(OBJECT)
uni-app的App引擎封装了微信、QQ、微博的分享SDK,开发者可以直接调用相关功能

可以分享到微信、QQ、微博,每个社交平台被称为分享服务提供商,即provider。

可以分享文字、图片、图文、音乐、视频等多种形式。同时注意,分享为小程序也使用本API。即在App里可以通过本API把一个内容以小程序(通常为内容页)方式直接分享给微信好友。

分享到微信好友

wxshare(){
    
    
	let that = this
	let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
	let curRoute = routes[routes.length - 1].$page.fullPath // 获取当前页面路由,也就是最后一个打开的页面路由
	uni.share({
    
    
		provider: "weixin", //分享服务提供商(即weixin|qq|sinaweibo)
		scene: 'WXSceneTimeline',//场景,可取值参考下面说明。
		type: 0, //分享形式
		href: `${
      
      util.base_url}${
      
      curRoute}&sj=${
      
      that.UserInfo.id}`, //跳转链接
		title: '标题', //分享内容的标题
		summary: '摘要', //分享内容的摘要
		imageUrl: '封面图片地址', 
		success: function(res) {
    
    
			 //成功后执行操作
			 uni.showToast({
    
    
				title: '分享成功',
				icon: 'none',
				duration: 2000
			})
			
		},
		fail: function(err) {
    
    
			 //失败后执行操作
			uni.showToast({
    
    
				title: '分享失败',
				icon: 'none',
				duration: 2000
			})
		}
	});
},

分享到微信朋友圈

pyqshare(){
    
    
	let that = this
	let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
	let curRoute = routes[routes.length - 1].$page.fullPath // 获取当前页面路由,也就是最后一个打开的页面路由
	uni.share({
    
    
		provider: "weixin", //分享服务提供商(即weixin|qq|sinaweibo)
		scene: 'WXSceneSession',//场景,可取值参考下面说明。
		type: 0, //分享形式
		href: `${
      
      util.base_url}${
      
      curRoute}&sj=${
      
      that.UserInfo.id}`, //跳转链接
		title: "分享内容的标题", //分享内容的标题
		summary: "分享内容的摘要", //分享内容的摘要
		imageUrl: "封面图片地址", //图片地址
		success: function(res) {
    
    
			//成功后操作
		},
		fail: function(err) {
    
    
			// 失败后操作
		}
	});
},

type 值参数说明

  • 0 图文 weixin、sinaweibo
  • 1 纯文字 weixin、qq
  • 2 纯图片 weixin、qq
  • 3 音乐 weixin、qq
  • 4 视频 weixin、sinaweibo
  • 5 小程序 weixin

scene 值说明

  • WXSceneSession 分享到聊天界面
  • WXSceneTimeline 分享到朋友圈
  • WXSceneFavorite 分享到微信收藏

参数说明
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_44590591/article/details/128375228