目录

uniapp开发的APP唤起微信打开小程序

目录

uniapp开发的APP唤起微信打开小程序

uni-app开发的APP跳转到微信小程序需要调用H5+的原生界面控件。

  1. 用到了分享功能,在打包原生应用时,需要注意:首先勾选权限配置,manifest.json->App 模块权限配置->Share。然后,manifest.json->App SDK 配置->分享,按照提示填写微信分享的信息(微信开放平台,不是微信公众平台)。

    https://i-blog.csdnimg.cn/blog_migrate/e6b914954b019dee7e2e80977131473f.png

  2. 因为涉及到第三方 SDK 的配置,需要运行到手机进行测试。

    https://i-blog.csdnimg.cn/blog_migrate/01ccd715df581fe39e45a74bdec034f5.png

  3. 代码

<template>
	<view class="center">
		<view class="text"  @click="checkWeChat">跳转到小程序</view>
	</view>
</template>
<script>
export default {
	data() {
		return {
			sweixin: null
		}
	},
	onLoad() {
		this.getPlus()
	},
	methods: {
		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(s){
				shares={};
				for(var i in s){
					var t=s[i];
					shares[t.id]=t;
				}
				that.sweixin=shares['weixin'];
			}, function(e){
				console.log("获取分享服务列表失败:"+e.message);
			});
			//放入当前的webview
			currentWebview.append(pusher);
		},
		checkWeChat() {
			//调用微信小程序
			this.sweixin.launchMiniProgram({
				id:'gh_244-------' //要跳转小程序的原始ID
			})
		}
	}
}
</script>

原文链接: