A cordova plugin, a JS version of Wechat SDK
Share title, description, image, and link to wechat moment(朋友圈)
See cordova-plugin-wechat-example
-
cordova plugin add https://github.com/xu-li/cordova-plugin-wechat --variable wechatappid=YOUR_WECHAT_APPID
, or using plugman, phonegap, ionic -
cordova build ios
orcordova build android
-
(iOS only) if your cordova version <5.1.1,check the URL Type using XCode
Wechat.isInstalled(function (installed) {
alert("Wechat installed: " + (installed ? "Yes" : "No"));
}, function (reason) {
alert("Failed: " + reason);
});
var scope = "snsapi_userinfo";
Wechat.auth(scope, function (response) {
// you may use response.code to get the access token.
alert(JSON.stringify(response));
}, function (reason) {
alert("Failed: " + reason);
});
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.LINK,
webpageUrl: "http://tech.qq.com/zt2012/tmtdecode/252.htm"
}
},
scene: Wechat.Scene.TIMELINE // share to Timeline
}, function () {
alert("Success");
}, function (reason) {
alert("Failed: " + reason);
});
// See https://github.com/xu-li/cordova-plugin-wechat-example/blob/master/server/payment_demo.php for php demo
var params = {
mch_id: '10000100', // merchant id
prepay_id: 'wx201411101639507cbf6ffd8b0779950874', // prepay id
nonce: '1add1a30ac87aa2db72f57a2375d8fec', // nonce
timestamp: '1439531364', // timestamp
sign: '0CB01533B8C1EF103065174F50BCA001', // signed string
};
Wechat.sendPaymentRequest(params, function () {
alert("Success");
}, function (reason) {
alert("Failed: " + reason);
});
Q: After sharing in wechat, it will not get back to my app.
A: (iOS)Please make sure the URL Type is correct. (Android) Your app signature is correct.
Q: Rejected by Apple app store claiming we should provide ways to allow people to authenticate/login with WeChat for people without installing the WeChat app.
A: You can hide the Wechat Login button if the wechat app is not installed.
$scope.showWechatLogin = false;
if (typeof Wechat !== 'undefined') {
Wechat.isInstalled(function (installed) {
if (installed) {
// Only show wechat login button if the Wechat App was detected
$scope.showWechatLogin = true;
}
}, function (reason) {
});
}
(Thanks @winsonchan and @Jeff-Tian)
-
Add android version -
Share to wechat session(聊天) and wechat favorite(收藏) -
Add other media types, including music etc. -
Other APIs
-
Android Version update