[uniapp APP share to WeChat]

How to share using uni.share

illustrate

This method uses uniapp third-party service uni.share(); parameters, etc. can be viewed at the bottom link

1. Configuration

1. In the first step, open manifest.json -> App module permission configuration, and check Share;
2. In the second step, configure the parameters of WeChat, Weibo, and QQ according to the following documents.
WeChat Share
In the App module configuration of manifest.json, check WeChat Share (share), and fill in the appid. If you want to use it on the iOS platform, you also need to configure a universal link.

reference documents

WeChat appid application steps: https://ask.dcloud.net.cn/article/208.
General link for iOS platform WeChat SDK configuration: https://ask.dcloud.net.cn/article/36445.
insert image description here

2. Share to the chat page

share pictures

The code example is as follows:

uni.share({
    
    
	provider: "weixin", //分享服务提供商(即weixin|qq|sinaweibo)
	scene: "WXSceneSession",//分享场景,此代表分享到聊天
	type: 2,//分享类型纯图片
	imageUrl: "https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/[email protected]", //分享图片链接,图片大小不要太大,不然会报错,推荐小于20kb
	success: function (res) {
    
    
		console.log("success:" + JSON.stringify(res));
	},
	fail: function (err) {
    
    
		console.log("fail:" + JSON.stringify(err));
	}
});

share text

uni.share({
    
    
	provider: "weixin",
	scene: "WXSceneSession",
	type: 1,
	summary: "我正在使用HBuilderX开发uni-app,赶紧跟我一起来体验!",
	success: function (res) {
    
    
		console.log("success:" + JSON.stringify(res));
	},
	fail: function (err) {
    
    
		console.log("fail:" + JSON.stringify(err));
	}
});

Share pictures and texts

uni.share({
    
    
	provider: "weixin",
	scene: "WXSceneSession",
	type: 0,
	href: "http://uniapp.dcloud.io/",
	title: "分享的标题",
	summary: "分享的内容",
	imageUrl: "https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/[email protected]",
	success: function (res) {
    
    
		console.log("success:" + JSON.stringify(res));
	},
	fail: function (err) {
    
    
		console.log("fail:" + JSON.stringify(err));
	}
});

share as applet

uni.share({
    
    
	provider: 'weixin',
	scene: "WXSceneSession", //分享类型(聊天,朋友圈)
	type: 5,//类型 
	title: "标题",
	imageUrl: '图片地址',//不能大于20kb
	miniProgram: {
    
    
		id: "xxxx",//小程序原始ID
		path: "pages/index/index",//小程序页面路径,传参也是?拼接
		webUrl: "https://ask.dcloud.net.cn/article/287",//地址
		type: 2 //微信小程序版本类型,可取值: 0-正式版; 1-测试版; 2-体验版。 默认值为0。
	},
	success: res => {
    
    
		console.log(res);
	},
	fail: function(err) {
    
    
			console.log(err);
	}
});


If you encounter problems such as error reporting, you can refer to my other article uniapp sharing WeChat applet card error reporting

3. Share to Moments

share pictures

uni.share({
    
    
	provider: "weixin",
	scene: "WXSceneTimeline",
	type: 2,
	imageUrl: "https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/[email protected]",
	success: function (res) {
    
    
		console.log("success:" + JSON.stringify(res));
	},
	fail: function (err) {
    
    
		console.log("fail:" + JSON.stringify(err));
	}
});

share text

uni.share({
    
    
	provider: "weixin",
	scene: "WXSceneTimeline",
	type: 1,
	summary: "内容",
	success: function (res) {
    
    
		console.log("success:" + JSON.stringify(res));
	},
	fail: function (err) {
    
    
		console.log("fail:" + JSON.stringify(err));
	}
});

Share pictures and texts

uni.share({
    
    
	provider: "weixin",
	scene: "WXSceneTimeline",
	type: 0,
	href: "http://uniapp.dcloud.io/",
	title: "标题",
	summary: "内容",
	imageUrl: "https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/[email protected]",
	success: function (res) {
    
    
		console.log("success:" + JSON.stringify(res));
	},
	fail: function (err) {
    
    
		console.log("fail:" + JSON.stringify(err));
	}
});

4. Reference document link

Link: unipp API share

Guess you like

Origin blog.csdn.net/Ge_Daye/article/details/132120779