npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@cordova-ohos/cordova-plugin-wechat

v3.1.0

Published

Cordova Wechat Plugin

Downloads

117

Readme

cordova-plugin-wechat

Cordova/PhoneGap 插件,用于在混合应用(Hybrid App)中集成微信 SDK,支持微信登录、分享、支付等核心功能,适配OHOS平台。

功能特性

✅ 检查微信客户端安装状态

✅ 微信授权登录

✅ 多类型分享(文本、图片、链接、小程序)

✅ 微信支付(基于微信商户平台)

✅ 打开微信客户端 / 指定页面

✅ 完整的错误回调与状态提示

OHOS平台不支持以下功能

(1),微信Harmony SDK仅支持分享到聊天界面,不支持分享到朋友圈、收藏,scene字段无效;

(2),微信Harmony SDK不支持分享APP

(3),微信Harmony SDK不支持分享表情,表情可作为图片分享

(4),微信Harmony SDK不支持分享视频、音乐

支持平台

  • OHOS 5.0+

前置准备

  1. 注册 微信开放平台 账号,创建移动应用

  2. 完善应用信息:

  • OHOS:填写应用包名,上传签名文件等信息
  1. 申请所需接口权限(登录、分享、支付等),等待审核通过

  2. 若需支付功能:注册 微信商户平 账号,绑定开放平台 AppID

安装

通过 HCordova CLI 安装(支持 cordova-openharmony 2.0.0+):

hcordova命令化工具 仓库:OpenHarmony-Cordova/hcordova-cli

通过 npm 安装(推荐)

hcordova plugin add cordova-plugin-wechat --variable WECHATAPPID=YOUR_WECHAT_APPID --platform ohos

卸载

hcordova plugin remove cordova-plugin-wechat --variable WECHATAPPID=YOUR_WECHAT_APPID  --platform ohos

配置说明

OHOS 额外配置

  1. 在开发者的 App module 的 module.json5 里加入下方scheme声明:
"querySchemes": [
   "weixin",
   "wxopensdk"
]
  1. 开发者需要先配置和微信约定的action wxentity.action.open:
"skills": [
   {
   "entities": [
      "entity.system.home"
   ],
   "actions": [
      "action.system.home",
      "ohos.want.action.home",
      "wxentity.action.open"
   ]
   }
]
  1. 修改项目中的oh-package.json5文件,在dependencies中加入微信 opensdk 的依赖项:
{
  "name": "entry",
  "version": "1.0.0",
  "description": "Please describe the basic information.",
  "main": "",
  "author": "",
  "license": "",
  "dependencies": {
    "@tencent/wechat_open_sdk": "^1.0.0",
    "@magongshou/harmony-cordova": "file:../cordova"
  }
}
  1. 修改项目中的EntryAbility的代码,添加微信插件在ArkTS侧监听和初始化:
export default class EntryAbility extends UIAbility {
   onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
      //添加如下代码,注册Wechat监听插件
      //WeChatAction/WeChatAction,动态导入微信插件
      //EntryAbility 微信插件的入口函数
      //wx9dab96bdfa8f16ec为app的appId,在微信的开放平台获取
      PluginRegisterHandle(this,
         want,
         "WeChatAction/WeChatAction",
         "EntryAbility", 
         "wx9dab96bdfa8f16ec" 
      );
   }

   onNewWant(want: Want): void {
      //添加如下代码,注册Wechat监听插件
      //WeChatAction/WeChatAction,动态导入微信插件
      //EntryAbility 微信插件的入口函数
      //wx9dab96bdfa8f16ec为app的appId,在微信的开放平台获取
      PluginRegisterHandle(this,
         want,
         "WeChatAction/WeChatAction",
         "EntryAbility", 
         "wx9dab96bdfa8f16ec" 
      );
   }
}

使用示例

1. 检查微信是否安装

//判断微信是否已经安装
Wechat.isInstalled(function (installed) {
    alert("Wechat installed: " + (installed ? "Yes" : "No"));
}, function (reason) {
    alert("Failed: " + reason);
});

2. 微信登录

//微信授权登录
var scope = "snsapi_userinfo",
    state = "_" + (+new Date());
Wechat.auth(scope, state, function (response) {
    alert("授权成功:根据服务端回调获取数据");
}, function (reason) {
    alert("发送失败");
});

3. 分享文本到聊天界面

//分享文本到聊天界面
/*分享到微信后,无论是否分享成功,
 *如果没有返回应用,js会回调分享成功,但不一定成功,
 *如果返回了应用,分享失败,会通知js侧,分享成功不再通知
 *这些都是SDK限制,插件无法更改
 */
Wechat.share({
    text: "This is just a plain string",
    //scene属性无效
    scene: Wechat.Scene.TIMELINE  
}, function (response) {
    //此处并不能判断是否真的分享成功,如果没有调失败就是成功的
    console.log("Success");
}, function (reason) {
    //如果返回了失败,是真的分享失败,会先调用成功
    alert("Failed: " + reason);
});

4. 分享在线图片到聊天界面

//分享在线图片到聊天界面
/*通知js侧调用微信成功,分享是否成功无法判断,
*即使返回了应用也不通知js侧,
*这些都是SDK限制,插件无法更改
*/
Wechat.share({
    message: {
        media: {
            type:Wechat.Type.IMAGE,
            image:"https://www.chuzhitong.com/images/logo.png"
        }
    },
    //scene属性无效
    scene: Wechat.Scene.TIMELINE 
}, function (response) {
    console.log("Success");
}, function (reason) {
    console.log("Failed: " + reason);
});

5. 分享base64图片到聊天界面

//分享base64图片到聊天界面
/*通知js侧调用微信成功,分享是否成功无法判断,
*即使返回了应用也不通知js侧,
*这些都是SDK限制,插件无法更改
*/
Wechat.share({
    message: {
        media: {
            type:Wechat.Type.IMAGE,
            image:"data:image/jpeg;base64,djfksjfdlsf...."
        }
    },
    //scene属性无效
    scene: Wechat.Scene.TIMELINE 
}, function (response) {
    console.log("Success");
}, function (reason) {
    console.log("Failed: " + reason);
});

6. 分享小程序

//分享小程序
/*分享到微信后,无论是否分享成功,
 *如果没有返回应用,js会回调分享成功,但不一定成功,
 *如果返回了应用,分享失败,会通知js侧,分享成功不再通知
 *这些都是SDK限制,插件无法更改
 */
 Wechat.share({
    message: {
        title: "Hi, there",
        description: "This is description.",
        thumb: "https://www.chuzhitong.com/images/logo.png",
        media: {
            type: Wechat.Type.MINI,
            userName: "gh_946331c270fa", // 小程序原始id
            path: "pages/contact/contact", // 小程序的页面路径
            withShareTicket: true, // 是否使用带shareTicket的分享
            miniprogramType: Wechat.Mini.RELEASE
        }
},
    scene: Wechat.Scene.SESSION   // 小程序仅支持聊天界面
}, function (response) {
    console.log(response);
}, function (reason) {
    console.log(reason);
});

7. 打开小程序

//打开小程序
var params = {
    userName: 'gh_946331c270fa', // userName
    path: 'pages/contact/contact', // open mini program page
    // Developer, trial, and official version
    miniprogramType: Wechat.Mini.RELEASE 
};
Wechat.openMiniProgram(params,function(response){
    alert(response);
},function(reason){
  alert(reason);  
})

8. 调起微信支付

//调起微信支付,数据由web服务端生成返回给APP前端,然后前端调起支付界面
var params = {
    partnerid: '1573080401', // merchant id
    prepayid: 'wx08130020798076c61ca4d6b876b7490000', // prepay id
    noncestr: 'a8a7db499852484dac2a6fa350980a16', // nonce
    timestamp: '1762578047', // timestamp
    sign: 'ChzOmrXDyKJa6AFAZZ....', // signed string
};

Wechat.sendPaymentRequest(params, function () {
    alert("Success");
}, function (reason) {
    alert("Failed: " + reason);
});

许可证

本插件基于 Apache License 2.0 开源,详情见 LICENSE 文件。

官方资源