uniapp app打开小程序/app分享小程序卡片

发布于:2025-06-22 ⋅ 阅读:(15) ⋅ 点赞:(0)

app打开小程序

plus.share.getServices(function(services) {
    var service = services.find(function(service) {
      return service.id === 'weixin';
    });
    if (service) {
      service.launchMiniProgram({
        id: 'gh_**********02', // 替换为实际的小程序"原始id"
        success: function() {
          console.log('成功打开小程序');
        },
        fail: function(err) {
          console.error('打开小程序失败', err);
        }
      });
    } else {
      console.log('未找到微信服务');
    }
}, function(err) {
    console.error('获取分享服务失败', err);
});

小程序打开另一个小程序

uni.navigateToMiniProgram({
	appId: 'wx7a*************', // 替换为实际的小程序appId
	path: 'pages/index/index', // 小程序打开的页面路径,默认为首页
	extraData: {
	  foo: 'bar' // 需要传递给目标小程序的数据,目标小程序可在App.onLaunch(),App.onShow()中获取到这份数据
	},
	// envVersion: 'develop', // 打开的小程序的版本。仅在当前小程序为开发版或体验版时此参数有效。如果当前小程序是正式版,则打开的小程序必定是正式版。
	success(res) {
	  // 打开成功
	  console.log('成功打开小程序', res);
	},
	fail(err) {
	  // 打开失败
	  console.error('打开小程序失败', err);
	}
});

app分享小程序卡片

uni.share({
    provider: 'weixin',
    scene: "WXSceneSession", //仅支持分享好友
    type: 5,
    title: '你好',
    imageUrl: 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/share-logo@3.png',
    miniProgram: {
        id: 'gh_abcdefg', // 原始id
        path: 'pages/index/index',
        type: 0,
        webUrl: 'http://uniapp.dcloud.io' //必须得有,地址随便
    },
    success: ret => {
        console.log(JSON.stringify(ret));
    }
});

网站公告

今日签到

点亮在社区的每一天
去签到