uniapp写的h5跳转小程序
使用场景:
我们对接第三方支付的时候,对方只提供了原生小程序id和appid,由我们的app和h5平台跳转至小程序。
遇到的问题:
app跳转本地正常,线上报错如下
解决办法:
需要去微信开放平台申请应用appid
易错点:
// #ifdef APP-PLUS
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){
sweixin.launchMiniProgram({
id: 'xxx‘,//原生小程序id gh打头的
type: 0,
path:token_url
});
}
},function(res){
console.log(JSON.stringify(res));
});
// #endif
h5跳转,在网上看到很多关于跳转的,大部分都是需要申请微信公众平台开放权限,使用微信的sdk,但是发现了一种很新的办法。以前对接过富友支付。发现了链接的方式
weixin://dl/business/?appid=wx9f0f95c42bcf73c9&path=pages/pay-plugin/pay-plugin&query=
具体我这边的实现方式如下
str=pages/pay-plugin/pay/plugin?tradeNo=puv*2FWpIPEJr70WQr%2BZ4dAApVNMS192d100TkLSPr1nM3D&member_id=1284250&type=BF
const index = str.indexOf("?");
const path = str.substring(0,index);
let list = str.substring(index+1);
return `weixin://dl/business/?appid=wx9f0f95c42bcf73c9&path=${path}&query=${encodeURIComponent(list)}`
}