当前位置:首页 > JavaScript > Uni-app 之APP打开小程序与分享小程序页面

Uni-app 之APP打开小程序与分享小程序页面

一叶知秋2024-04-09 03:21:11JavaScript9

一、配置

1、微信开放平台,创建移动应用与绑定小程序

2、manifest.json,填写移动应用的appid

二、打开小程序

plus.share.getServices(res => {
  var is_weixin = res.find(i => i.id === 'weixin');
  if (is_weixin) {
    is_weixin.launchMiniProgram({
      id: weixin_id,
      path: '/pages/index/index' //要打开小程序的路径
    }, res => {
      console.log(JSON.stringify(res));
      //成功
    }, res => {
      //失败
    })
  }
}, res => {
  
})

三、分享小程序

uni.share({
  provider: "weixin",
  scene: "WXSceneSession",
  type: 5,
  imageUrl: imgUrl, //图片地址。type为0时,推荐使用小于20Kb的图片
  title: title, //分享内容的标题
  miniProgram: {
    id: weixin_id, //微信小程序原始id
    path: 'pages/index/index', //点击链接进入的页面
    type: 0,
    webUrl: '' //兼容低版本的网页链接
  },
  success: ret => {
    console.log(JSON.stringify(ret));
  },
  fail(res) {
    console.log(JSON.stringify(res))
  }
})

扫描二维码推送至手机访问。

版权声明:本站部分文章来自AI创作、互联网收集,请查看免责申明

本文链接:https://www.yyzq.team/post/334655.html

分享给朋友: