项目目前使用到的是微信支付和微信登录。
github上作者demo
https://github.com/xu-li/cordova-plugin-wechat
一、准备
1.微信开发者平台-创建移动应用 安卓需要绑定签名和包名,ios绑定BundleID
2.第一步申请通过之后就可以进行分享和授权了,如果还需要微信支付需要进一步申请。
二、使用
1.登录
var scope = “snsapi_userinfo”,
state = “_” + (+new Date());
Wechat.auth(scope, state, function (response) {
// you may use response.code to get the access token.这里可以直接得到返回的,之后可以进行https://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b468d75.html的第二步
alert(JSON.stringify(response));
}, function (reason) {
alert(“Failed: ” + reason);
});
2.支付
先发送ajax,后台下单。取得以下参数调用,注意作者有把官方参数的下划线去掉。
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);
});
项目出现报普通错误的情况,经查验是签名的问题。