iis服务器助手广告广告
返回顶部
首页 > 资讯 > 移动开发 >uniapp开发的App(安卓)端跳转uniapp微信小程序
  • 854
分享到

uniapp开发的App(安卓)端跳转uniapp微信小程序

uni-app微信小程序小程序 2023-10-03 11:10:35 854人浏览 泡泡鱼
摘要

本文总结两种跳转方法:!!!适合自己的才是最好的 1、根据微信开放文档提供的方法获取小程序的URL (两种)         !  小程序的URL Scheme  weixin://dl/business/?t= *TICKET*    

本文总结两种跳转方法:!!!适合自己的才是最好的

1、根据微信开放文档提供的方法获取小程序的URL (两种)

        !  小程序URL Scheme 

weixin://dl/business/?t= *TICKET*

        !! 小程序的URL Link 

https://wxaurl.cn/*TICKET* 或 Https://wxmpurl.cn/*TICKET*

 

代码实现: !!!切记本案例是前端调用,应该让后端封装调用(为了安全考虑)

methods: {getUniappURL() {let params = {// path:要跳转到的小程序的目标页面纯路径(不要拼接参数)// 注意:如果该链接要打开的版本是正式版,则这个path一定要已经发布到了正式版,不然无法访问到该页面则链接无法生成成功path: '/pages/index/insex',query: 'a=1&b=2', // 短链的入参env_version: "release", // 正式版expire_type: 1,expire_interval: 30,}this.getAppLink(params)},getAppLink(params) {// AppID(小程序ID)const appid = 'wx******cf'// AppSecret(小程序密钥)const secret = 'afe3D06*******975dcbe4'let tokenURL = ''let urllink = ''// #ifdef APPtokenURL = `https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=${appid}&secret=${secret}`// #endif// 先发起请求获取凭证2小时内有效uni.request({url: tokenURL,method: 'GET',success(res) {// #ifdef APPurllink = `https://api.weixin.qq.com/wxa/generate_urllink?access_token=${res.data.access_token}`//获取 URL Link                //urllink = `https://api.weixin.qq.com/wxa/generatescheme?access_token=${res.data.access_token}`//获取 URL Scheme// #endif// 再发起请求获取urluni.request({url: urllink,method: 'POST',data: {...params},success(result) {console.log('生成网址:', result.data.url_link);// #ifdef APP                        //通过uniapp内置组件WEB-view跳转该链接uni.navigateTo({    url: `/pages/webView/webView?url=${result.data.url_link}`,});// #endif},fail(err) {console.log(err);}})},fail(err) {console.log(err);}})},}

以上可以拿到小程序的两种URL 链接

vebView页面代码:

2、通过App的微信分享跳转微信小程序

!!!打包App时需要在manifest.JSON中APP模块配置Share中微信分享保持开启

!!!打包App时需要在manifest.json中APP模块配置Share中微信分享保持开启

!!!打包App时需要在manifest.json中APP模块配置Share中微信分享保持开启

代码实现:

!!! $appJumpMiniPro方法我放在了Vue原型上
!!!需要小程序的原始ID:以gh_开头的id

$appJumpMiniPro(url)方法: !!!记得在main.js上挂载 否则无效~

Vue.prototype.$appJumpMiniPro = function(url) {// 获取分享服务列表plus.share.getServices(res => {let sweixin = '';for (var i = 0; i < res.length; i++) {let t = res[i];if (t.id == 'weixin') {sweixin = t;}}if (sweixin) {sweixin.launchMiniProgram({id: 'gh_****ab42', // 要跳转小程序的原始IDpath: url, //  可带参数type: 2 // 微信小程序版本类型可取值: 0-正式版; 1-测试版; 2-体验版。 默认值为0。},// 目标小程序点击返回App后执行的回调,在此接收微信小程序传递的参数res2 => {console.log(typeof res2, res2)// res2是微信小程序传递回来的参数 类型为string 需转化为js对象使用let result = JSON.parse(res2)console.log(result)// 拿到参数后执行你需要的逻辑},err2 => {console.log(err2)});} else {                // 没有获取到微信分享服务uni.showToast({icon: 'none',title: '当前环境不支持微信操作!'})}},err => {            // 获取分享服务列表失败console.log(err)})}

到此结束~以上是App跳转微信小程序的两种方法,适合自己的才是最好的

来源地址:https://blog.csdn.net/2201_75870706/article/details/132058988

--结束END--

本文标题: uniapp开发的App(安卓)端跳转uniapp微信小程序

本文链接: https://www.lsjlt.com/news/423006.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作