uniapp转小程序分享到朋友圈

uniapp转小程序分享到朋友圈

uniapp转化成小程序,但是目前小程序只支持安卓手机进行朋友圈分享,ios目前还不支持。
文档link
我的项目是uniapp,就直接按照我的写法来进行展示:

<button plain class="wx" open-type='share'>
	<view>
		<img src="http://friend.png" alt="" class="shareimg">
	</view>
	<view>微信好友</view>
</button>
<button plain class="wx" open-type='share'>
	<view>
		<img src="http://pyq.png" alt="" class="shareimg">
	</view>
	<view>朋友圈</view>
</button>

// An highlighted block
// 这两个方法可以直接写在methods里面, 也可以写在和生命周期同级的地方
// 分享到朋友圈     
onShareTimeline: function(e){
	// 配置标题
	var title = this.articleinfo.prop1;
	var contentid = this.contentid
	return {
		title: title,
		// 这里面是配置你的url中?后面的数据
		query: {
			type: 'hot',
			contentid: contentid
		}
	}
},
// 这两个方法都要写上,就算不分享给好友也要有这个方法,下面的showShareMenu配置要用到
onShareAppMessage: function(e) {
// 这里是分享给微信好友的方法, path是分享给好友的小程序页面, 好友点击直接进入path页面
	var path = '/xxxxxxxxxx/fxarticle?type=hot&contentid=' + this.contentid;
	var title = this.articleinfo.prop1;
	return {
		title: title,
		path: path
	}
},

我主要展示分享到朋友圈的部分

shareTimeline(){'&type=Article';
	var that = this
	//console.log(url)
	// --------app分享朋友圈开始------
	// #ifdef APP-PLUS
	uni.share({
	    provider: "weixin",
	    scene: "WXSenceTimeline",//WXSceneSession 微信好友 WXSenceTimeline//微信朋友圈
	    type: 0,
	    href: url,
		title: "分享标题" ,
	    summary: "分享标题",
	    imageUrl: "88888888888888.png",
	    success: function (res) {
	        //console.log("success:" + JSON.stringify(res));
			uni.showToast({
				title: '已分享到朋友圈',
				icon: 'none'
			})
	    },
	    fail: function (err) {
	        console.log("fail:" + JSON.stringify(err));
	    }
	});
	// #endif
	// --------app分享朋友圈结束------	
	// --------小程序分享朋友圈开始------
	// #ifdef MP-WEIXIN
		wx.showShareMenu({
		  withShareTicket: true,
		  menus: ['shareAppMessage','shareTimeline'] // ***这地方两个配置都要写上
		})
	// #endif
	// --------小程序分享朋友圈结束------
}

欢迎各路大佬的指教,共同进步。
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/Someone_like_U_/article/details/107798327