微信支付插件

配置

  1. 打开config.xml文件,在插件配置勾选cordova-plugin-wechat
  2. 右键config.xml文件,点击打开方式,选择XML Editor,编辑cordova-plugin-wechat插件的WECHATAPPID参数。WECHATAPPID代表的是微信开放平台审核应用之后返回的WECHATAPPID。
    1. <import id="cordova-plugin-wechat" type="web" ref="cordova"> <parameter>WECHATAPPID=value</parameter>
    2. </import>
  3. 打包生成。

用法

Check if wechat is installed

  1. Wechat.isInstalled(function (installed) {
  2. alert("Wechat installed: " + (installed ? "Yes" : "No"));
  3. }, function (reason) {
  4. alert("Failed: " + reason);
  5. });

Authenticate using Wechat

  1. var scope = "snsapi_userinfo",
  2. state = "_" + (+new Date());
  3. Wechat.auth(scope, state, function (response) {
  4. // you may use response.code to get the access token.
  5. alert(JSON.stringify(response));
  6. }, function (reason) {
  7. alert("Failed: " + reason);
  8. });
  1. Wechat.share({
  2. message: {
  3. title: "Hi, there",
  4. description: "This is description.",
  5. thumb: "www/img/thumbnail.png",
  6. mediaTagName: "TEST-TAG-001",
  7. messageExt: "这是第三方带的测试字段",
  8. messageAction: "<action>dotalist</action>",
  9. media: "YOUR_MEDIA_OBJECT_HERE"
  10. },
  11. scene: Wechat.Scene.TIMELINE // share to Timeline
  12. }, function () {
  13. alert("Success");
  14. }, function (reason) {
  15. alert("Failed: " + reason);
  16. });

用例github下载地

文档更新时间: 2018-05-15 15:28