uniapp Use applets (share, call)

App share applet to WeChat:

For parameters and other information, see: share | uni-app official website (dcloud.net.cn)

		uni.share({
			provider: "weixin",//分享服务提供商(即weixin|qq|sinaweibo)
			type: 5,  //分享形式,如图文、纯文字、纯图片、音乐、视频、小程序等
			scene: "WXSceneSession", //场景值 分享到聊天界面
			imageUrl: this.picture,  
			title: '分享的标题',
			miniProgram: {id: '', // 小程序的原始ID 上开放者平台查看
path: 'pages/index/indexpage?user_id=' + this.user_id,  //点击链接进入的页面
type: 0, // 微信小程序版本类型,可取值: 0-正式版; 1-测试版; 2-体验版。 默认值为0。
webUrl: this.LocalHost + '/pages/index?info_no=' + this.info_no  //兼容低版本的网页链接
},
			success() {  // 分享完成,请注意此时不一定是成功分享
				uni.hideLoading()
			},
			fail(e) {  // 分享失败
				uni.hideLoading()
				uni.showModal({
					title: '提示',
					content: e.msg || '分享失败',
					showCancel: false,
					cancelText: '',
					confirmText: '确定',
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			}
		})

 As shown in the figure, the content in the shared past link is related to the configuration of the above code

If the following problems occur: I don’t know why, I should go to the background to configure something

App calls the WeChat applet:

			getPlus() {
				//获取当前显示的webview
				var pages = getCurrentPages()
				var page = pages[pages.length - 1]
				var currentWebview = page.$getAppWebview()
				//调用H5+APP的扩展API
				var shares = null;
				let that = this
				var pusher = plus.share.getServices(function(res) {
					shares = {};
					for (var i in res) {
						var t = res[i];
						shares[t.id] = t;
					}
					that.sweixin = shares['weixin'];
				}, function(e) {
					console.log("获取分享服务列表失败:" + e.message);
				});
				//放入当前的webview
				currentWebview.append(pusher);
			},
			checkWeChat() {
				//调用微信小程序
				this.sweixin.launchMiniProgram({
					id: '', //要跳转小程序的原始ID
					type: 0, //小程序版本 0 正式版 1 测试版 2 体验版
					path: `pages/homepage/home?label_no=` + this.label_no,
				})
				console.log(this.label_no)
			}

uniapp official website api:

getCurrentPages(): The function is used to obtain the instance of the current page stack, which is given in the order of the stack in the form of an array, the first element is the home page, and the last element is the current page

$getAppWebview() : There is a built-in method uni-app in  getCurrentPages()the obtained page  $getAppWebview() to get the object instance of the current webview, only App is supported

App share h5 to WeChat:

Guess you like

Origin blog.csdn.net/m0_65720832/article/details/130078882
Recommended