uniapp 使用小程序(分享、调用)

App分享小程序到微信:

参数等信息详见:分享 | uni-app官网 (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: () => {}
				});
			}
		})

 如图,分享过去的链接里的内容和上面代码的配置有关

如果出现以下问题:不知道为什么,应该要到后台去配置一下什么

App调用微信小程序:

			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官网api:

getCurrentPages(): 函数用于获取当前页面栈的实例,以数组形式按栈的顺序给出,第一个元素为首页,最后一个元素为当前页面

$getAppWebview() :uni-app 在 getCurrentPages()获得的页面里内置了一个方法 $getAppWebview() 可以得到当前webview的对象实例,仅支持App

App分享h5到微信:

猜你喜欢

转载自blog.csdn.net/m0_65720832/article/details/130078882