Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

cordova-plugin-wechatv2

guoanfamily2MIT2.1.6

A cordova plugin, a JS version of Wechat SDK,can share screenshot image

cordova, wechat, weixin, screenshot, share, ecosystem:cordova, cordova-ios, cordova-android

readme

cordova-plugin-wechat

A cordova plugin, a JS version of Wechat SDK

Feature

Share title, description, image, and link to wechat moment(朋友圈),choose invoice from Wechat list

can share screenshot image for ios and android

Install

  1. cordova plugin add cordova-plugin-wechatv2 --variable wechatappid=YOUR_WECHAT_APPID, or using plugman, phonegap, ionic

  2. cordova build ios or cordova build android

  3. (iOS only) if your cordova version <5.1.1,check the URL Type using XCode

Usage

Check if wechat is installed

Wechat.isInstalled(function (installed) {
    alert("Wechat installed: " + (installed ? "Yes" : "No"));
}, function (reason) {
    alert("Failed: " + reason);
});

Authenticate using Wechat

var scope = "snsapi_userinfo",
    state = "_" + (+new Date());
Wechat.auth(scope, state, function (response) {
    // you may use response.code to get the access token.
    alert(JSON.stringify(response));
}, function (reason) {
    alert("Failed: " + reason);
});

Share text

Wechat.share({
    text: "This is just a plain string",
    scene: Wechat.Scene.TIMELINE   // share to Timeline
}, function () {
    alert("Success");
}, function (reason) {
    alert("Failed: " + reason);
});
Wechat.share({
    message: {
        title: "Hi, there",
        description: "This is description.",
        thumb: "www/img/thumbnail.png",
        mediaTagName: "TEST-TAG-001",
        messageExt: "这是第三方带的测试字段",
        messageAction: "<action>dotalist</action>",
        media: "YOUR_MEDIA_OBJECT_HERE"
    },
    scene: Wechat.Scene.TIMELINE   // share to Timeline
}, function () {
    alert("Success");
}, function (reason) {
    alert("Failed: " + reason);
});
Wechat.share({
    message: {
        ...
        media: {
            type: Wechat.Type.WEBPAGE,
            webpageUrl: "http://tech.qq.com/zt2012/tmtdecode/252.htm"
        }
    },
    scene: Wechat.Scene.TIMELINE   // share to Timeline
}, function () {
    alert("Success");
}, function (reason) {
    alert("Failed: " + reason);
});

Send payment request

// See https://github.com/xu-li/cordova-plugin-wechat-example/blob/master/server/payment_demo.php for php demo
var params = {
    partnerid: '10000100', // merchant id
    prepayid: 'wx201411101639507cbf6ffd8b0779950874', // prepay id
    noncestr: '1add1a30ac87aa2db72f57a2375d8fec', // nonce
    timestamp: '1439531364', // timestamp
    sign: '0CB01533B8C1EF103065174F50BCA001', // signed string
};

Wechat.sendPaymentRequest(params, function () {
    alert("Success");
}, function (reason) {
    alert("Failed: " + reason);
});

Choose invoices from card list

//offical doc https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1496561749_f7T6D
var params = {
    timeStamp: '1510198391', // timeStamp
    signType: 'SHA1', // sign type
    cardSign: 'dff450eeeed08120159d285e79737173aec3df94', // cardSign
    nonceStr: '5598190f-5fb3-4bff-8314-fd189ab4e4b8', // nonce
};

Wechat.chooseInvoiceFromWX(data,function(data){
    console.log(data);
},function(){
    alert('error');
})

LICENSE

MIT LICENSE

changelog

Change Log

2.1.0 - 2017-11-16

Added

  • iOS OpenSDK1.8.0
  • Choose invoices from card list

2.0.0 - 2017-07-01

Changed

  • Use android sdk from JCenter
  • Upgrade cordova versions
  • More improvements to android version of the plugin

1.4.0 - 2017-01-10

Added

  • iOS OpenSDK1.7.5
  • Android libammsdk 3.1.1

1.3.0 - 2016-09-13

Added

  • iOS openSDK1.7.3

1.2.0 - 2016-07-13

Added

  • iOS openSDK1.7.2

Changed

  • Allow wechat auth on the device without wechat installed.

Removed

  • WeChatSDK_1.5

1.1.5 - 2016-06-13

Fixed

  • fix android src files not being copied during platform add hook

1.1.4 - 2016-05-11

Fixed

  • wxapi directory gets deleted after removing other plugins

1.1.3 - 2016-01-28

Fixed

  • Fixed package name with hyphen issue in android

1.1.2 - 2016-01-22

Fixed

  • Fixed sharing emotion issue (remote file) in Android

1.1.1 - 2016-01-18

Fixed

  • Fixed sharing emotion issue in Android

1.1.0 - 2016-01-15

Added

  • Support Base64 image

Changed

  • Rename payment parameters

Fixed

  • Fixed thumbnail image size issue in iOS

1.0.0 - 2016-01-08

  • Initial release