实现跳转步骤
1、找到想要跳转的第三方小程序的相关人员,进行允许跳转的配置
2、使用微信下程序的《wx-open-launch-weapp》开放标签
3、需要后端的配合生成验签,此处需要使用到官方文档接口进行
4、前端进行跳转
1.1、联系第三方人员添加配置
** 联系上之后能够获取到
第三方小程序的:appid 和 支持跳转的路径地址
例如(当时我要跳转的第三方提供给我的)–此处 仅为案例实际按照实际情况来:
path:/a/a-page/a-pageindex/index?channel=123465
appid:123***456966
**
2.1、配置完成之后前端可以进行开发,使用的是开放标签wx-open-launch-weapp
微信公众号开放标签官方链接地址可点击此处
想要是标签生效需要以下步骤:
1、在需要加载的页面的 onLoad函数下执行一下配置
onLoad() {
this.miniProgram()
},
2、函数内容包括,引入js文件,判断安卓和ios系统,后台接口验签获取,wx.config配置处理
miniProgram(){
//2.1 引入js文件
var script = document.createElement('script');
script.src = "https://res2.wx.qq.com/open/js/jweixin-1.6.0.js";
document.body.appendChild(script);
//2.2 判断安卓和ios系统(由于获取验签的入参需要当前页面的地址,ios系统由于第一页面有区别因此需要特殊处理,否则开放标签展示失败)
let params;
// 获取系统信息
const systemInfo = uni.getSystemInfoSync();
// 判断是否为iOS系统
const isIOS = /ios/.test(systemInfo.platform);
if(isIOS){
//ios系统获取第一页面
params = {url_params:`ios识别到的公众号的第一页面地址`}//入参必填
}else{
//非ios系统获取当前页面的地址
params = {
url_params:location.href.split('#')[0]
}
}
//2.3 获取后台接口的验签接口
// 后端接口我不太懂,这个是官方文档 附录1-JS-SDK使用权限签名算法
//https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html#62
let res = await app.api(params);//后端需要提供的接口
if (res.code !== 200) {
//提示错误信息
uni.$u.toast(`${res.msg},电子医保凭证功能将无法打开`);
return;
}
let { sign,timestamp,noncestr } = res.data;
//2.4 配置获取权限
wx.config({
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId: '自己的公众号appid', // 必填,公众号的唯一标识
timestamp: timestamp, // 必填,填任意数字即可
nonceStr: noncestr, // 必填,填任意非空字符串即可
signature: sign, // 必填,填任意非空字符串即可
jsApiList: ["onMenuShareTimeline",'wx-open-launch-weapp'], // 必填,需要使用的JS接口列表
openTagList:['wx-open-launch-weapp'], // 可选,需要使用的开放标签列表,例如['wx-open-launch-weapp','wx-open-launch-app']
})
wx.error(res => {
console.log('error',res);
});
}
3、页面开发
<wx-open-launch-weapp
@launch="handleLaunch"
@error="handleError"
id="launch-btn"
appid="第三方的appid"
path="第三方小程序的跳转路径"
style="display: block;"
>
<script type="text/wxtag-template">
<style>
.box{
display:flex;
align-items: center;
flex-direction: column;
justify-content: center;
}
.btn {
outline: none;
font-size: 15px;
background: transparent;
border:transparent solid 1px;
color:#313037
}
.ybImg{
width: 35px;
height: 35px;
margin-bottom: 3px
}
</style>
<view class="box">
<image class="ybImg" src="需要布局的图片"></image>
<button class="btn">想要跳转的名称</button>
</view>
</script>
</wx-open-launch-weapp>
// 监听跳转
handleLaunch(e) {
console.log('跳转',e);
},
// 监听错误
handleError(e) {
console.log('失败',e);
|
个人的开发经验,多谢观看