Ionic2 分享(微信分享+QQ分享+复制到剪贴板+微博分享)

ionic2 集成微信sdk

github地址:https://github.com/xu-li/cord...
使用示例:
cordova plugin add cordova-plugin-wechat --variable wechatappid=YOUR_WECHAT_APPID(你的微信开放平台id)
cordova build ios or cordova build android
分享朋友圈:(其中toastService是我自己封装的toast方法替换成自己对应的方法就可以了)

shareWxSession(){
    let wechat = (<any>window).Wechat;
    wechat.isInstalled(function (installed) {
      if(!installed){
         this.toastService.show('您没有安装微信!');
        return ;
      }
    }, function (reason) {
         this.toastService.show("Failed: " + reason);
    });
    wechat.share({
    message: {
        title: this.shareImg,
        description: this.shareDesc,
        thumb: this.shareImg,
        media: {
            type: wechat.Type.LINK,
            webpageUrl: this.shareUrl
        }
    },
        scene: wechat.Scene.SESSION   // share to SESSION
    }, function () {
       this.toastService.show('分享成功');
    }, function (reason) {
        console.log("Failed: " + reason);
    });
  }

分享微信好友:

shareWxTimeLine(){
    let wechat = (<any>window).Wechat;
    wechat.isInstalled(function (installed) {
      if(!installed){
        this.toastService.show('您没有安装微信!');
        return ;
      }
    }, function (reason) {
        this.toastService.show("Failed: " + reason);
    });
    wechat.share({
    message: {
        title: this.shareImg,
        description: this.shareDesc,
        thumb: this.shareImg,
        media: {
            type: wechat.Type.LINK,
            webpageUrl: this.shareUrl
        }
    },
        scene: wechat.Scene.TIMELINE   // share to Timeline
    }, function () {
       this.toastService.show('分享成功','bottom',4000);
    }, function (reason) {
        console.log("Failed: " + reason);
    });

  }

ionic2集成QQsdk

github地址:https://github.com/iVanPan/Co...
cordova plugin add https://github.com/iVanPan/Co... --variable QQ_APP_ID=YOUR_QQ_APPID (QQ开放平台appid)
分享QQ:

shareQQ(){
      let qq = (<any>window).QQSDK;
      let that = this;
      qq.checkClientInstalled(function () {
            var args:any = {};
            args.scene = qq.Scene.QQ;//QQSDK.Scene.QQZone,QQSDK.Scene.Favorite
            args.url = that.shareUrl;
            args.title = that.shareTitle;
            args.description = that.shareDesc;
            args.image = that.shareImg;
            qq.shareNews(function () {
                this.toastService.show('分享成功');
            }, function (failReason) {
                // alert(failReason);
            },args);
        }, function () {
        // if installed QQ Client version is not supported sso,also will get this error
            this.toastService.show('您没有安装QQ!');
        });
        
  }

分享QQ空间:

shareQZone(){
  let qq = (<any>window).QQSDK;
  let that = this;
  qq.checkClientInstalled(function () {
        var args:any = {};
        args.scene = qq.Scene.QQZone;//QQSDK.Scene.QQZone,QQSDK.Scene.Favorite
        args.url = that.shareUrl;
        args.title = that.shareTitle;
        args.description = that.shareDesc;
        args.image = that.shareImg;
        qq.shareNews(function () {
            this.toastService.show('分享成功','bottom',4000);
        }, function (failReason) {
            // alert(failReason);
        },args);
    }, function () {
    // if installed QQ Client version is not supported sso,also will get this error
        this.toastService.show('您没有安装QQ!');
    });
  }

复制到剪贴板

文档地址:http://ionicframework.com/doc...
添加Clipboard的插件:ionic plugin add https://github.com/VersoSolut...
使用方法:

clipboard() {
      Clipboard.copy(this.shareUrl);
      this.toastService.show('已复制到剪贴板');
  }

微博分享

github地址:https://github.com/iVanPan/co...

cordova plugin add https://github.com/iVanPan/cordova_weibo.git --variable WEIBO_APP_ID=YOUR_WEIBO_APPID or cordova plugin add cordova-plugin-weibosdk --variable WEIBO_APP_ID=YOUR_WEIBO_APPID

使用方法:

shareWb(){
  let wb = (<any>window).YCWeibo;
  let that = this;
  wb.checkClientInstalled(function(){
    var args:any = {};
    args.url = that.shareUrl;
    args.title = that.shareTitle;
    args.description = that.shareDesc;;
    args.imageUrl = that.shareImg;//if you don't have imageUrl,for android http://www.sinaimg.cn/blog/developer/wiki/LOGO_64x64.png will be the defualt one
    args.defaultText = "";
    wb.shareToWeibo(function () {
        this.toastService.show('分享成功','bottom',4000);
    }, function (failReason) {
        // console.log(failReason);
    }, args);
    }
    ,function(){
        this.toastService.show('您没有安装Weibo!');
  });
}`

相关推荐