Skip to content

Latest commit

 

History

History
98 lines (90 loc) · 3.08 KB

20211112-uniapp分享到微信.md

File metadata and controls

98 lines (90 loc) · 3.08 KB

20211112-uniapp分享到微信

APPshare() {
        console.log("click---")
        
        let that = this;
        plus.share.getServices(function(res) {
          console.log("res---:", res)
          var sweixin = null;
          for (var i = 0; i < res.length; i++) {
            var t = res[i];
            if (t.id == 'weixin') {
              sweixin = t;
            }
          }
          // console.dir("sweixin:",sweixin)
          // 发送给好友/朋友圈
          if (sweixin) {
            sweixin.send({
              type:'miniProgram',//web miniProgram
              // content: "红人拼商城",
              // href: "http://www.dcloud.io/",
              // extra: {
              //   scene: "WXSceneSession" //WXSceneSession  WXSceneTimeline WXSceneFavorite
              // },
              
              thumbs:['/static/images/Team/card.png'],
              miniProgram:{
                id:'gh_8d8225156ae7',//原始ID
                path:'/pages/Goods/page/Detail/Detail?goods_id=10213',
                type:1, // 0-正式版; 1-测试版; 2-体验版。 默认值为0。
                webUrl:'www.baidu.com'
              }
              // pictures:''
            }, function() {
              console.log("分享成功!");
            }, function(e) {
              console.log("分享失败:" + e.message);
            });
            
            // 拉起小程序指定页面
            // sweixin.launchMiniProgram({
            //   id: 'gh_8d8225156ae7', //原始ID
            //   path: '/pages/Goods/page/Detail/Detail?goods_id=10245',
            //   type: 0, // 0-正式版; 1-测试版; 2-体验版。 默认值为0。
            // });
          }
        }, function(res) {
          console.log('error=', JSON.stringify(res));
        })
        var shares = null;
        // 分享操作判断是否认证,如果没有则需要授权认证
        function shareAction() {
          var s = shares[0];
          if (!s.authenticated) {
            s.authorize(() => {
              console.log("认证完成!");
            }, (e) => {
              console.log("未进行认证");
            }, {
              "appid": "XXXXXX"
            });
          }
        }
        // 分享到微信
        function shareWeixinMessage() {
          sweixin.send({
            content: "DCloud HBuilder-做最好的HTML5开发工具",
            href: "http://www.dcloud.io/",
            extra: {
              scene: "WXSceneTimeline"
            }
          }, function() {
            console.log("分享成功!");
          }, function(e) {
            console.log("分享失败:" + e.message);
          });
        }
        // shareWeixinMessage()
      },

系统原生分享

https://www.html5plus.org/doc/zh_cn/share.html#plus.share.sendWithSystem

// 使用系统分享发送分享消息 
function shareSystem(){
	plus.share.sendWithSystem({type:'text',content:'分享内容',href:'http://www.dcloud.io/'}, function(){
		console.log('分享成功');
	}, function(e){
		console.log('分享失败:'+JSON.stringify(e));
	});
}