uniapp跳转到小程序之后,从小程序返回app
1、首先,从app跳转到小程序,需要调用launchMiniProgram方法,具体用法参考:
调用微信小程序
void obj.launchMiniProgram(options, successCB, errorCB);
launchMiniProgram(params) {
var self = this;
console.log("lauch mini program:",self.shares);
if (!self.shares['weixin']) {
plus.nativeUI.toast('未配置微信分享模块!');
console.log("未配置微信分享模块!--1");
return;
}
if(self.shares['weixin'].nativeClient == false){
plus.nativeUI.toast('请先安装微信客户端');
console.log("未安装微信客户端!--2");
return;
}
var href = "pages/peisong/peisongInfo?"+params;
let jumptype = 0;//0,正式版 2,体验版
if (getApp().globalData.isdev) {
jumptype = 2;
} else {
jumptype = 0;
}
console.log(getApp().globalData.isdev,jumptype);
console.log("跳转路径href",href);
self.shares['weixin'].launchMiniProgram({
id: 'gh_7c596dd9bf4f', //小程序原始
path: href, //跳转到小程序的页面并传参
type: jumptype, //0,正式版 2,体验版
},
res2 => {
console.log(typeof res2, res2)
console.log(JSON.parse(res2))
// res2是微信小程序传递回来的参数 类型为string 需转化为js对象使用
let result = JSON.stringify(res2)
console.log(typeof result,result);
// 拿到参数后执行你需要的逻辑
// uni.switchTab({
// url: '/pages/mainmenu/menu/menu'
// });
},
err2 => {
console.log(err2)
}
);
},
2、小程序处理完各种事物后,返回app,需要借用小程序按钮设置:
<view style="width: 100%;height:10%;display: flex;align-items: center;justify-content: center;">
<button open-type="launchApp" app-parameter='{{successToApp}}' binderror="launchAppError" style="border-radius: 50px;background:#14c2d1;width: 120px;height: 40px;line-height: 40px;color: white;">返回APP</button>
</view>
3、从小程序返回app之后,假如需要进行一些事务处理,可以重新返回到第一步中:
找到launchMiniProgram方法:
void obj.launchMiniProgram(options, successCB, errorCB);
在其回调方法successCB和errorCB中处理,具体可以参考第一段代码
4、
说明:
在微信小程序中打开APP(使用button组件的open-type属性值设置为"launchApp")时,可通过plus.runtime.arguments获取小程序传入的参数(小程序中button组件的app-parameter属性值)。 注意:需在微信开放平台将应用关联小程序才能正常调用。

浙公网安备 33010602011771号