app端跳转小程序要先去微信开放平台申请,这个步骤自行百度吧。
申请审核成功后,app跳转小程序的功能自动获得。
注意注意注意:若移动应用未上架,则最多只能跳转小程序100次/天,用于满足调试需求。 这个是微信官方的规则。
微信开放平台:https://open.weixin.qq.com/
app拉起小程序功能介绍:https://developers.weixin.qq.com/doc/oplatform/Mobile_App/Launching_a_Mini_Program/Launching_a_Mini_Program.html
app拉起小程序:
appToMp(){
let that = this
let url = ''//跳转小程序的路径
plus.share.getServices(function(res){
var sweixin = null;
for (var i = 0; i < res.length; i++){
var t = res[i];
if (t.id == 'weixin') {
sweixin = t;
}
}
if (sweixin) {
that.wxPay = true
sweixin.launchMiniProgram({
id:'',//这里写你的小程序原始id(以gh开头)
type:0,//这里是不同的环境(默认0)
path:url
})
}
},function(err){
console.log(JSON.stringify(err));
})
}
小程序返回app:
<!-- 小程序页面 -->
<button open-type="launchApp" app-parameter="orderId" @error="openError">返回</button>
app-parameter是需要的参数传给app
app接收页面:
onShow(){
// #ifdef APP-PLUS
setTimeout(()=>{
let orderId = plus.runtime.arguments
if(orderId) {
plus.runtime.arguments = ''
...
}
},10)
// #endif
}
安卓不加setTimeout,plus.runtime.arguments可以获取到正确的参数(orderId),但是ios的不行,后面试了下,加setTimeout就可以正常获取。