微信分享与支付插件

功能特点

lbuilder 插件,  JS 版微信 SDK,分享标题,描述,图片和链接到朋友圈

安装

复制插件到plugins目录下

修改config.xml替换WECHATAPPID值为微信后台获得的ID


检测微信是否安装

Wechat.isInstalled(function (installed) {

    alert("Wechat installed: " + (installed ? "Yes" : "No"));

}, function (reason) {

    alert("Failed: " + reason);

});

微信登录

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);

});


分享到朋友圈


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);

});


微信支付

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);

});


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