第一步,通过微信接口(https://api.weixin.qq.com/cgi-bin/token)获取小程序access_token 微信官方文档 第二步,通过微信接口(Https://api.weixin.qq.com/wxa/gen
微信官方文档
我这里用的uni-app,所以请求用的uni.request,其他的同理,比如ajax和axiOS,不多赘述
// 第一步获取token uni.request({ method: "GET", // 这里的appid写你需要跳转的小程序的appid,secret秘钥也一样,grant_type=client_credential是固定的参数,不用改 url: "https://api.weixin.qq.com/cgi-bin/token?appid=wxe109dd058as8sdf88&secret=9eb3d6dec783bc55sdfs32sdf2f2aa0&grant_type=client_credential", success: (res1) => { alert("获取token成功"); console.log(res1.data); // 第2步获取小程序跳转链接 uni.request({ method: "POST", // access_token就是请求上一个接口拿到的回调结果 url: "https://api.weixin.qq.com/wxa/generatescheme?access_token=" + res1.data.access_token, data: { // path跳转到的小程序目标页面,query跳转需要携带参数,在目标页面onload里面接收options里面,其他参数固定,获取看文档了解 jump_wxa: { path: "/app/test/test", query: "url=" + urls, env_version: "trial", // 正式版为"release",体验版为"trial",开发版为"develop" }, is_expire: true, expire_type: 1, expire_interval: 1, // env_version: "trial", }, success: (res2) => { alert("获取小程序跳转链接1"); console.log(res2.data); let a = document.createElement("a"); //创建一个a标签元素 a.href = res2.data.openlink; //设置跳转地址 document.body.appendChild(a); //加入 a.click(); //触发点击跳转 document.body.removeChild(a);删除元素 }, fail:(err) =>{ alert('获取微信跳转链接失败') alert(JSON.stringify(err)) } }); }, fail:(err) =>{ alert('获取微信token失败') alert(JSON.stringify(err)) } });
来源地址:https://blog.csdn.net/m0_46156566/article/details/128917461
--结束END--
本文标题: 通过weixin://dl/business/?t=打开微信小程序
本文链接: https://www.lsjlt.com/news/372440.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0