
重要说明
Due to the security upgrade of iOS 13 system version, the official WeChat SDK has been adapted from 1.8.6 with supports * Universal Links * mode jumps, and the validity check when sharing.
From version 3.0.0 of our plugin, we changed to the latest WeChat SDK. Before using it, you need to configure the Universal Links service, and pay attention to passing the universallink
variable when installing the plugin, otherwise it will not work properly.
If you don't want to use the new version features, you can fall back to version 3.0.0 prior
cordova-plugin-wechat
A cordova plugin, a JS version of Wechat SDK
Feature
- check wechat client is installed;
- Share text, image, link,music,video,miniprogram to wechat timeline,session or favorite;
- open wechat auth;
- send wechat payment request;
- open wechat miniprogram;
Documentation
文档 · 教程 · FAQ · DEMO
Install
cordova plugin add cordova-plugin-wechat --variable wechatappid=YOUR_WECHAT_APPID --variable universallink=YOUR_UNIVERSAL_LINK
cordova build ios
cordova build android
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) {
alert(JSON.stringify(response));
}, function (reason) {
alert("Failed: " + reason);
});
Share text
Wechat.share({
text: "This is just a plain string",
scene: Wechat.Scene.TIMELINE
}, function () {
alert("Success");
}, function (reason) {
alert("Failed: " + reason);
});
Share media(e.g. link, photo, music, video etc)
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
}, function () {
alert("Success");
}, function (reason) {
alert("Failed: " + reason);
});
Share link
Wechat.share({
message: {
...
media: {
type: Wechat.Type.WEBPAGE,
webpageUrl: "http://www.jason-z.com"
}
},
scene: Wechat.Scene.TIMELINE
}, function () {
alert("Success");
}, function (reason) {
alert("Failed: " + reason);
});
Share mini program
Wechat.share({
message: {
...
media: {
type: Wechat.Type.MINI,
webpageUrl: "https://www.jason-z.com",
userName: "wxxxxxxxx",
path: "user/info",
hdImageData: "http://wwww.xxx.com/xx.jpg",
withShareTicket: true,
miniprogramType: Wechat.Mini.RELEASE
}
},
scene: Wechat.Scene.SESSION
}, function () {
alert("Success");
}, function (reason) {
alert("Failed: " + reason);
});
Send payment request
var params = {
partnerid: '10000100',
prepayid: 'wx201411101639507cbf6ffd8b0779950874',
noncestr: '1add1a30ac87aa2db72f57a2375d8fec',
timestamp: '1439531364',
sign: '0CB01533B8C1EF103065174F50BCA001',
};
Wechat.sendPaymentRequest(params, function () {
alert("Success");
}, function (reason) {
alert("Failed: " + reason);
});
Choose invoices from card list
var params = {
timeStamp: '1510198391',
signType: 'SHA1',
cardSign: 'dff450eeeed08120159d285e79737173aec3df94',
nonceStr: '5598190f-5fb3-4bff-8314-fd189ab4e4b8',
};
Wechat.chooseInvoiceFromWX(params,function(data){
console.log(data);
},function(){
alert('error');
})
open wechat mini program
var params = {
userName: 'gh_d43f693ca31f',
path: 'pages/index/index?name1=key1&name2=key2',
miniprogramType: Wechat.Mini.RELEASE
};
Wechat.openMiniProgram(params,function(data){
console.log(data);
},function(){
alert('error');
})
more usage please see https://jasonz1987.github.io/cordova-wechat-docs/docs/usages
Join us
QQ群:190808518

Donate
we need your support to improve open source software ,if we induce your develop time ,welcome to donate us.


LICENSE
MIT LICENSE