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!');
  });
}`
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值