zoukankan      html  css  js  c++  java
  • Ionic 分享功能(微博 微信 QQ)

    1.安装插件

        cordova plugin add cordova-plugin-wechat --variable wechatappid=你申请微信appid

        cordova plugin add cordova-plugin-qqsdk --variable QQ_APP_ID=你申请QQ的appid

        cordova plugin add cordova-plugin-weibosdk --variable WEIBO_APP_ID=你申请微博的appid

    2 js代码

        $scope.goshare=function() {
    
          $scope.myPopup = $ionicPopup.show({
            //这里简单列一下
            //template: '',
            templateUrl:'templates/home/share.html',
            title: '分享文章',
            scope: $scope,
            buttons: [ { text: '取消' }]
          });
          $scope.myPopup.then(function(res) {
    
          });
        }
    
        $scope.offshare= function (tp) {
    
          var params = {
            scene: 1
          };
          params.message = {
            title: "[TEST] send-photo-local" ,
            description: "[TEST]Sending from test application",
            mediaTagName: "TEST-TAG-001",
            messageExt: "send-photo-local",
            messageAction: "<action>dotalist</action>",
            media: {}
          };
          params.message.title = $scope.details.title;
          params.message.description = $scope.details.title;
          params.message.thumb = "www/img/logo.png";
          params.message.media.type = Wechat.Type.LINK;
          params.message.media.webpageUrl = $scope.details.ShareUrl;
    
    
          switch(tp){
            case 0://微博
              WeiboSDK.checkClientInstalled(function () {
                var args = {};
                args.url = $scope.details.ShareUrl;
                args.title = $scope.details.title;
                args.description = $scope.details.title;
                args.image = 'http://dzlyinhe.com/images/logo_1.png';
                WeiboSDK.shareToWeibo(function () {
                  //alert('share success');
                  $scope.myPopup.close();
                }, function (failReason) {
                  /*
                  $ionicLoading.show({
                    noBackdrop: false,
                    template: failReason,
                    duration: 1500
                  });*/
                }, args);
              }, function () {
                $ionicLoading.show({
                  noBackdrop: false,
                  template: "请安装微博客户端",
                  duration: 1500
                });
              });
                  break;
            case 1://会话
              params.scene=0;
              Wechat.isInstalled(function (installed) {
                if(installed){
                  Wechat.share(params
                    , function () {
                      //alert("Success");
                      $scope.myPopup.close();
                    }, function (reason) {
                      //alert("Failed: " + reason);
                      /* $ionicLoading.show({
                        noBackdrop: false,
                        template: reason,
                        duration: 1500
                      });*/
                    });
                }else{
                  $ionicLoading.show({
                    noBackdrop: false,
                    template: "请安装微信客户端",
                    duration: 1500
                  });
                }
              }, function (reason) {
               // alert("Failed: " + reason);
              });
    
              break;
            case 2:
              params.scene=1;
              Wechat.isInstalled(function (installed) {
                if(installed){
                  Wechat.share(params
                    , function () {
                      //alert("Success");
                      $scope.myPopup.close();
                    }, function (reason) {
                      //alert("Failed: " + reason);
                      /*
                      $ionicLoading.show({
                        noBackdrop: false,
                        template: reason,
                        duration: 1500
                      });*/
                    });
                }else{
                  $ionicLoading.show({
                    noBackdrop: false,
                    template: "请安装微信客户端",
                    duration: 1500
                  });
                }
              }, function (reason) {
                // alert("Failed: " + reason);
              });
    
              break;
            case 3:
              params.scene=2;
              Wechat.isInstalled(function (installed) {
                if(installed){
                  Wechat.share(params
                    , function () {
                      //alert("Success");
                      $scope.myPopup.close();
                    }, function (reason) {
                      //alert("Failed: " + reason);
                      /* $ionicLoading.show({
                        noBackdrop: false,
                        template: reason,
                        duration: 1500
                      });*/
                    });
                }else{
                  $ionicLoading.show({
                    noBackdrop: false,
                    template: "请安装微信客户端",
                    duration: 1500
                  });
                }
              }, function (reason) {
                // alert("Failed: " + reason);
              });
    
              break;
            case 4://qq好友
              var args = {};
              args.client = QQSDK.ClientType.QQ;//QQSDK.ClientType.QQ,QQSDK.ClientType.TIM;
    
              QQSDK.checkClientInstalled(function () {
    
                args.scene = QQSDK.Scene.QQ;//QQSDK.Scene.QQZone,QQSDK.Scene.Favorite
                args.url = $scope.details.ShareUrl;
                args.title = $scope.details.title;
                args.description = $scope.details.title;
                args.image = 'http://dzlyinhe.com/images/logo_1.png';
    
                QQSDK.shareNews(function () {
                  $scope.myPopup.close();
                }, function (failReason) {
    
                }, args);
              }, function () {
                $ionicLoading.show({
                  noBackdrop: false,
                  template: "请安装QQ客户端",
                  duration: 1500
                });
              }, args);
    
              break;
            case 5:
              var args = {};
              args.client = QQSDK.ClientType.QQ;//QQSDK.ClientType.QQ,QQSDK.ClientType.TIM;
              args.scene =QQSDK.Scene.QQZone ;//QQSDK.Scene.QQ QQSDK.Scene.QQZone,QQSDK.Scene.Favorite
              args.url = $scope.details.ShareUrl;
              args.title = $scope.details.title;
              args.description = $scope.details.title;
              args.image = 'http://dzlyinhe.com/images/logo_1.png';
              QQSDK.checkClientInstalled(function () {
                QQSDK.shareNews(function () {
                  $scope.myPopup.close();
                }, function (failReason) {
    
                }, args);
              }, function () {
                $ionicLoading.show({
                  noBackdrop: false,
                  template: "请安装QQ客户端",
                  duration: 1500
                });
              }, args);
              break;
          }
        }

    3.templates/home/share.html 

    <div class="row" style="font-size: 12px;">
      <div class="col" ng-click="offshare(0)"><img src="img/weibo.png" class="shareimg" /><br/>新浪微博</div>
      <div class="col" ng-click="offshare(1)"><img src="img/wechat.png" class="shareimg" /><br/>微信好友</div>
      <div class="col" ng-click="offshare(2)"><img  src="img/wechat_moment.png" class="shareimg"/><br/>微信朋友圈</div>
    </div>
    <div class="row" style="font-size: 12px;">
      <div class="col" ng-click="offshare(3)"><img src="img/wechat_fav.png" class="shareimg" /><br/>微信收藏</div>
      <div class="col" ng-click="offshare(4)"><img src="img/qq.png" class="shareimg" /><br/>QQ好友</div>
      <div class="col" ng-click="offshare(5)"><img  src="img/qzone.png" class="shareimg"/><br/>QQ空间</div>
    </div>

    4.实例图片

  • 相关阅读:
    理解构造器
    if与switch的性能比较
    Java对象的内存(一)
    shell编程_条件判断if
    shell编程_基础&变量
    集群架构篇:Nginx架构演进<拆分数据库 多台web节点共享静态资源>
    集群架构篇:Nginx流行架构LNMP
    集群架构篇:Nginx常用模块
    LInux系统@安装CentOS7虚拟机
    docker pull越来越慢的解决方法
  • 原文地址:https://www.cnblogs.com/linsu/p/7651897.html
Copyright © 2011-2022 走看看