微信支付插件
配置
- 打开config.xml文件,在插件配置勾选cordova-plugin-wechat
- 右键config.xml文件,点击打开方式,选择XML Editor,编辑cordova-plugin-wechat插件的WECHATAPPID参数。WECHATAPPID代表的是微信开放平台审核应用之后返回的WECHATAPPID。
<import id="cordova-plugin-wechat" type="web" ref="cordova"> <parameter>WECHATAPPID=value</parameter>
</import>
- 打包生成。
用法
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 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 // share to Timeline
}, function () {
alert("Success");
}, function (reason) {
alert("Failed: " + reason);
});
文档更新时间: 2018-05-15 15:28