uniapp 跳转到 微信小程序
步骤一:在 onload 生命周期里面 初始化 跳转数据,需要区分 移动端系统(android和ios)
let getServices = () => {
plus.share.getServices(
res => {
var sweixin = null;
for (var i = 0; i < res.length; i++) {
var t = res[i];
if (t.id == 'weixin') {
sweixin = t;
}
}
this.sweixin = sweixin;
},
err => {
console.log(JSON.stringify(err));
}
);
}
if (clientCode.platform === 'android') {
getServices();
} else if (clientCode.platform === 'ios') {
uni.login({
provider: 'weixin',
success: (res) => {
getServices()
},
fail: (err) => {
this.$toast({
title: '登录失败'
});
}
});
}
步骤二:调用 onload 初始化好的 跳转数据 里面的 launchMiniProgram 方法 ( id:小程序的原始id g开头 path:跳转的路径 type:小程序的版本 )
// 0-正式版; 1-测试版; 2-体验版。 默认值为0。
this.sweixin.launchMiniProgram({
id: 'gh_6db2979ccdfc',
path: `pages/payment/payment?miniPayRequest=${JSON.stringify(data.miniPayRequest)}&order_id=${this.order_id}&from=${this.from}`,
type: 2
});
微信小程序 返回 App
注意事项:必须是App跳转到小程序,点击按钮才有效
<button type="primary" size="lg" class="br60" open-type="launchApp" app-parameter="wechat" binderror="launchAppError">返回APP</button>