微信小程序唤起app

1、前提

1、app与小程序主体需一致,可以前往微信公众平台关联。

2、小程序的场景值为1069,也就是得从app打开小程序,小程序才能唤起app。

2、vue3代码示例

<template>
	<view class="maxBox bgc">
		<button 
			open-type="launchApp" 
			:app-parameter="appParams" 
			@launchapp="launchAppSuccess" 
			@error="launchAppError"
			class="button">
			返回APP
		</button>
	</view>
</template>

<script setup>
import { onLoad } from "@dcloudio/uni-app"
import { ref } from "vue"
onLoad(()=>{
	// 传给app的参数  最好是json格式的字符串
	let obj = {
		type: 'pay',
	}
	appParams.value = `${JSON.stringify(obj)}`
})
const appParams = ref();//传给app的参数
const launchAppSuccess = (e) => {
  console.log('✅ App 打开成功:', e);
};

// 打开App失败
const launchAppError = (e) => {
  console.error('⚠️ App 打开失败:', e);
  uni.showToast({
    title: '打开App失败,请重试',
    icon: 'none'
  });
};
</script>

<style lang="scss" scoped>
.maxBox {
    min-height: 100vh;
    padding-bottom: 7vh;
    box-sizing: border-box;
    position: relative;
    font-size: 24rpx;
	.button{
		position: absolute;
		top: 40%;
		left: 50%;
		transform: translate(-50%, -50%);
		background-color: #0268CF;
		color: #fff;
	}
}
</style>