ionic realizes wechat, QQ and microblog sharing

1. First of all, you should prepare the following

(1) one android.apk package

(2) application signature (generate signature with android apk package name)

          http://blog.csdn.net/dan_2017/article/details/79138635

(3) fill in application information and apply for appid through various open platforms

QQ: Tencent open platform http://open.qq.com/

Wechat: wechat open platform https://open.weixin.qq.com/

Microblog: microblog open platform http://open.weibo.com/

2. Install each plug-in (fill in the application for appid)

Wechat plug in installation:
ionic cordova plugin add cordova-plugin-wechat --variable wechatappid=wx7b22a8079fcd2f45

QQ plug in installation:
ionic cordova plugin add cordova-plugin-qqsdk --variable QQ_APP_ID=1105786989 --save

Microblog plug-in installation:
ionic cordova plugin add cordova-plugin-weibosdk --variable WEIBO_APP_ID=2690083339

Wechat plug in uninstall:
ionic cordova plugin rm cordova-plugin-wechat --variable wechatappid=wx7b22a8079fcd2f45

QQ plug in uninstall:
ionic cordova plugin rm cordova-plugin-qqsdk --variable QQ_APP_ID=1105786989

Microblog plug-in uninstall:
ionic cordova plugin rm cordova-plugin-weibosdk --variable WEIBO_APP_ID=2690083339

Wechat API: https://github.com/xu-li/cordova-plugin-wechat

QQ  API:https://github.com/iVanPan/Cordova_QQ/blob/master/README_ZH.md

Weibo API: https://github.com/iVanPan/cordova_weibo

3. Let me use QQ as an example:

html

<ion-content >
  <button ion-button  block (click)="textShare()">Text sharing</button>
  <button ion-button  block (click)="newsShare()">Link sharing</button>
  <button ion-button  block (click)="imgShare()">Picture sharing</button>
  <button ion-button  block (click)="flashShare()">Video sharing</button>
</ion-content>
/**
   * Text sharing
   */
  textShare(){
    let actionSheet=this.actionSheetCtrl.create({
      title:'share',
      buttons:[
        {
          text: 'QQ Good friend',
          handler: () => {
              this.shareProvider.qqTextShare(0);
          }
          },
          {
          text: 'QQ space',
          handler: () => {
              this.shareProvider.qqTextShare(1);
          }
          },
          {
          text: 'Wechat friends',
          handler: () => {
              this.shareProvider.wxTextShare(0)
          }
          },
          {
          text: 'Wechat Moments',
          handler: () => {
              this.shareProvider.wxTextShare(1)
          }
          },
          {
            text: 'micro-blog',
            handler: () => {
                this.shareProvider.wbTextShare()
            }
            },
          {
          text: 'cancel',
          role: 'cancel',
          handler: () => {
          }
          }
      ]
    });
    actionSheet.present();

  }
  /**
   * Link sharing
   */
  newsShare(){
    let actionSheet=this.actionSheetCtrl.create({
      title:'share',
      buttons:[
        {
          text: 'QQ Good friend',
          handler: () => {
              this.shareProvider.qqNewsShare(0);
          }
          },
          {
          text: 'QQ space',
          handler: () => {
              this.shareProvider.qqNewsShare(1);
          }
          },
          {
          text: 'Wechat friends',
          handler: () => {
              this.shareProvider.wxNewsShare(0);
          }
          },
          {
          text: 'Wechat Moments',
          handler: () => {
              this.shareProvider.wxNewsShare(1);
          }
          },
          {
            text: 'micro-blog',
            handler: () => {
                this.shareProvider.wbNewsShare();
            }
            },
          {
          text: 'cancel',
          role: 'cancel',
          handler: () => {
          }
          }
      ]
    });
    actionSheet.present();

  }
  /**
   * Picture sharing
   */
  imgShare(){
    let actionSheet=this.actionSheetCtrl.create({
      title:'share',
      buttons:[
        {
          text: 'QQ Good friend',
          handler: () => {
              this.shareProvider.qqImgShare(0);
          }
          },
          {
          text: 'QQ space',
          handler: () => {
              this.shareProvider.qqImgShare(1);
          }
          },
          {
          text: 'Wechat friends',
          handler: () => {
              this.shareProvider.wxImgShare(0);
          }
          },
          {
          text: 'Wechat Moments',
          handler: () => {
              this.shareProvider.wxImgShare(1);
          }
          },
          {
            text: 'micro-blog',
            handler: () => {
                this.shareProvider.wbImgShare()
            }
            },
          {
          text: 'cancel',
          role: 'cancel',
          handler: () => {
          }
          }
      ]
    });
    actionSheet.present();

  }
  /**
   * Video sharing
   */
  flashShare(){
    let actionSheet=this.actionSheetCtrl.create({
      title:'share',
      buttons:[
        {
          text: 'QQ Good friend',
          handler: () => {
              this.shareProvider.qqFlashShare(0);
          }
          },
          {
          text: 'QQ space',
          handler: () => {
              this.shareProvider.qqFlashShare(1);
          }
          },
          {
          text: 'Wechat friends',
          handler: () => {
              this.shareProvider.wxFlashShare(0);
          }
          },
          {
          text: 'Wechat Moments',
          handler: () => {
              this.shareProvider.wxFlashShare(1);
          }
          },
          {
            text: 'micro-blog',
            handler: () => {
                this.shareProvider.wbFlashShare()
            }
            },
          {
          text: 'cancel',
          role: 'cancel',
          handler: () => {
          }
          }
      ]
    });
    actionSheet.present();
import { Injectable } from '@angular/core';
import { LoadingController } from 'ionic-angular';

declare var Wechat;
declare var QQSDK;
declare var WeiboSDK;
/*
  Generated class for the ShareProvider provider.

  See https://angular.io/guide/dependency-injection for more info on providers
  and Angular DI.
*/
@Injectable()
export class ShareProvider {

  //Written words
  text: string = "Blog";
  description: string = "2017_Dan Blog of";
  //Share links
  link: string = "http://blog.csdn.net/Dan_2017";
  //Share pictures
  image: string = "assets/imgs/1.jpg"

  constructor() {
    console.log('Hello ShareProvider Provider');
  }
  /**
   * Wechat text sharing
   * @param index 
   */
  wxTextShare(index) {
    alert(index);
    Wechat.share({
      text: "This is a piece of shared text",
      scene: index == 0 ? Wechat.Scene.SESSION : Wechat.Scene.Timeline
    }, function () {
      alert("Share successfully!");
    }, function (reason) {
      alert("Failed:" + reason)
    });
  }
  /**
    * Wechat link sharing
    * @param index 
    */
  wxNewsShare(index) {
    Wechat.share({
      message: {
        title: this.text,
        thumb: this.image,
        description: this.description,
        mediaTagName: 'TEST-TAG-001',
        messageExt: "This is the third-party test field",
        messageAction: "<action>dotalist</action>",
        media: {
          type: Wechat.Type.WEBPAGE,
          webpageUrl: "https://www.csdn.net/"
        }
      },
      scene: index == 0 ? Wechat.Scene.SESSION : Wechat.Scene.Timeline
    }, function () {
      alert("Share successfully!");
    }, function (reason) {
      alert("Failed:" + reason)
    });
  }
  /**
  * Wechat image sharing
  * @param index 
  */
  wxImgShare(index) {
    Wechat.share({
      message: {
        title: 'My head',
        thumb: 'https://cordova.apache.org/static/img/cordova_bot.png',
        description: 'Cherry balls',
        mediaTagName: 'TEST-TAG-001',
        messageExt: "This is the third-party test field",
        messageAction: "<action>dotalist</action>",
        media: {
          type: Wechat.Type.WEBPAGE,
          webpageUrl: "http://tech.qq.com/zt2012/tmtdecode/252.htm"
        }
      },
      scene: index == 0 ? Wechat.Scene.SESSION : Wechat.Scene.Timeline
    }, function () {
      alert("Share successfully!");
    }, function (reason) {
      alert("Failed:" + reason)
    });
  }
  /**
  * Wechat video sharing
  * @param index 
  */
  wxFlashShare(index) {
    Wechat.share({
      message: {
        title: "Age thief",
        thumb: this.image,
        description: 'Zhou Bichang',
        mediaTagName: 'TEST-TAG-001',
        messageExt: "This is the third-party test field",
        messageAction: "<action>dotalist</action>",
        media: {
          type: Wechat.Type.WEBPAGE,
          webpageUrl: "http://tech.qq.com/zt2012/tmtdecode/252.htm"
        }
      },
      scene: index == 0 ? Wechat.Scene.SESSION : Wechat.Scene.Timeline
    }, function () {
      alert("Share successfully!");
    }, function (reason) {
      alert("Failed:" + reason)
    });
  }

  /**
   * 
   * @param index QQ Share text
   */
  qqTextShare(index) {
    var args: any = {};
    if (index == 0) {
      args.index = QQSDK.Scene.QQ;
    } else {
      args.index = QQSDK.Scene.QQZone;
    }
    args.text = "This is the shared text";
    QQSDK.shareText(function () {
      alert('Share success')
    }, function (reason) {
      alert('Failed:'+reason)
    }, args);
  }
  /**
   * 
   * @param index QQ Share links
   */
  qqNewsShare(index) {
    var args: any = {};
    if (index == 0) {
      args.index = QQSDK.Scene.QQ;
    } else {
      args.index = QQSDK.Scene.QQZone;
    }
    args.url = this.link;
    args.title = this.text;
    args.image = 'https://cordova.apache.org/static/img/cordova_bot.png';
    args.description = this.description;
    QQSDK.shareNews(function () {
      alert('Share success')
    }, function (reason) {
      alert('Failed:'+reason)
    }, args);

  }


  /**
   * QQ Share pictures 
   * @param index
   */
  qqImgShare(index) {
    var args: any = {};
    if (index == 0) {
      args.index = QQSDK.Scene.QQ;
    } else {
      args.index = QQSDK.Scene.QQZone;
    }
    args.title = "cordova";
    args.image = "https://cordova.apache.org/static/img/cordova_bot.png";
    args.description = "cordova";
    QQSDK.shareImage(function () {
      alert('Share success')
    }, function (reason) {
      alert('Failed:'+reason)
    }, args);
  }

  /**
   * 
   * @param index QQ Share flash
   */
  qqFlashShare(index) {
    var args: any = {};
    if (index == 0) {
      args.index = QQSDK.Scene.QQ;
    } else {
      args.index = QQSDK.Scene.QQZone;
    }
    args.title = 'Age thief';
    args.image = 'https://cordova.apache.org/static/img/cordova_bot.png';
    args.description = 'Zhou Bichang';
    args.url = 'https://y.qq.com/n/yqq/song/003K45Q02b0JVS.html';
    args.flashUrl = 'https://y.qq.com/portal/player.html';
    QQSDK.shareAudio(function () {
      alert('Share success')
    }, function (reason) {
      alert('Failed:'+reason)
    }, args);
  }

  /**
   * Microblog text sharing
   */
  wbTextShare() {
    var args: any = {};
    args.text = 'This is a text I want to share!';
    WeiboSDK.shareTextToWeibo(function () {
      alert('Share successfully!');
    }, function (reason) {
      alert('Sharing failed' + reason);
    })
  }
  /**
  * Microblog image sharing
  */
  wbImgShare() {
    var args: any = {};
    args.image = "https://cordova.apache.org/static/img/cordova_bot.png";
    WeiboSDK.shareImgToWeibo(function () {
      alert('Share successfully!');
    }, function (reason) {
      alert('Sharing failed' + reason);
    })
  }
  /**
    * Weibo link sharing
    */
  wbNewsShare() {
    var args: any = {};
    args.url = this.link;
    args.title = this.text;
    args.image = 'https://cordova.apache.org/static/img/cordova_bot.png';
    args.description = this.description;
    WeiboSDK.shareToWeibo(function () {
      alert('Share successfully!');
    }, function (reason) {
      alert('Sharing failed' + reason);
    })
  }
  /**
    * Microblog video sharing
    */
  wbFlashShare() {
    var args: any = {};
    args.title = 'Age thief';
    args.image = 'https://cordova.apache.org/static/img/cordova_bot.png';
    args.description = 'Zhou Bichang';
    args.url = 'https://y.qq.com/n/yqq/song/003K45Q02b0JVS.html';
    args.flashUrl = 'https://y.qq.com/portal/player.html';
    WeiboSDK.shareToWeibo(function () {
      alert('Share successfully!');
    }, function (reason) {
      alert('Sharing failed' + reason);
    })
  }
}

This can complete the basic wechat micro blog QQ sharing.

However, please note that if your signature and package name are inconsistent when you apply, wechat sharing will flash back, Weibo sharing will not succeed, etc.
Recommended blog: http://www.qdfuns.com/notes/15182/372db311ca31a4d868bd8fcb5de0dffa.html









Tags: Apache angular Session github

Posted on Tue, 05 May 2020 10:13:14 -0700 by springo