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

@wxbot/wechat-api-sdk

v1.1.0

Published

chat 协议 API SDK

Readme

WeChat API SDK

即时通讯第三方协议 API SDK - 简洁、高效的接口封装

📦 特性

  • 🎯 专注 第三方 协议:专为第三方协议优化
  • 📝 TypeScript:完整的类型定义,提供良好的开发体验
  • 🏗️ 模块化设计:按功能模块划分,职责清晰
  • 🔄 事件驱动:内置事件总线,方便消息监听和处理
  • 零外部依赖:仅依赖 axios,轻量简洁

📥 安装

npm install wechat-api-sdk

或使用 yarn:

yarn add wechat-api-sdk

🚀 快速开始

基本使用

import { wechatApi, ProtocolType } from 'wechat-api-sdk';

// 初始化API实例
const api = wechatApi(
  'http://your-api-url:port',  // GeWe API服务地址
  ProtocolType.WX_GeWe,              // 协议类型
  'your-token'                       // 可选的认证token
);

// 使用API
const result = await api.login.getLoginQrCode({});
console.log(result);

简化调用(默认使用 GeWe)

import { wechatApi } from 'wechat-api-sdk';

// protocolType 参数可省略,默认使用 GeWe
const api = wechatApi('http://localhost:8080', undefined, 'token');

📚 API文档

API实例提供以下模块:

1. 登录模块 (login)

处理微信账号的登录、心跳、在线状态等功能。

// 获取登录二维码
await api.login.getLoginQrCode({});

// 检查登录状态
await api.login.getLoginQrStatus({});

// 检查在线状态
await api.login.checkOnline({});

// 心跳
await api.login.heartBeat({});

// 登出
await api.login.logOut({});

2. 消息模块 (message)

发送各类消息和同步消息。

// 发送文本消息
await api.message.sendTxt({
  toWxid: 'wxid_xxx',
  content: 'Hello World'
});

// 发送图片
await api.message.sendImage({
  toWxid: 'wxid_xxx',
  imagePath: '/path/to/image.jpg'
});

// 发送文件
await api.message.sendFile({
  toWxid: 'wxid_xxx',
  filePath: '/path/to/file.pdf'
});

// 同步消息
await api.message.syncMessage({});

// 撤回消息
await api.message.revokeMsg({
  msgId: 'message_id'
});

3. 好友模块 (friend)

管理好友相关操作。

// 获取联系人列表
await api.friend.getContactList({});

// 获取联系人详情
await api.friend.getContactDetail({
  wxid: 'wxid_xxx'
});

// 搜索联系人
await api.friend.searchContact({
  keyword: 'nickname'
});

// 通过好友验证
await api.friend.passVerify({
  v3: 'v3_xxx',
  v4: 'v4_xxx'
});

4. 群聊模块 (chatRoom)

管理微信群聊操作。

// 获取群成员列表
await api.chatRoom.getChatroomMemberList({
  chatRoomId: 'chatroom_id'
});

// 获取群成员信息
await api.chatRoom.getChatroomMemberInfo({
  chatRoomId: 'chatroom_id',
  wxid: 'wxid_xxx'
});

// 获取群二维码
await api.chatRoom.getChatroomQRCode({
  chatRoomId: 'chatroom_id'
});

5. 工具模块 (tools)

提供文件上传下载、Webhook配置等工具功能。

// 上传文件
await api.tools.uploadFile({
  filePath: '/path/to/file'
});

// 下载图片
await api.tools.downloadImg({
  aesKey: 'key',
  url: 'image_url'
});

// 设置Webhook
await api.tools.setWebhook({
  url: 'http://your-webhook-url',
  token: 'your-token'
});

🔔 事件监听

SDK内置事件总线,可以监听消息事件:

import { eventBus } from 'wechat-api-sdk';

// 监听新消息
eventBus.on('newMessage', (msgData) => {
  console.log('收到新消息:', msgData);
  // 处理消息逻辑
});

// 取消监听
eventBus.off('newMessage');

🏗️ 项目结构

⚙️ 开发

# 克隆项目
git clone <repository-url>

# 安装依赖
npm install

# 构建
npm run build

# 监听模式构建
npm run build:watch

# 清理
npm run clean

📝 许可证

MIT License

🤝 贡献

欢迎提交 Issue 和 Pull Request!

⚠️ 免责声明

本SDK仅供学习和研究使用,请勿用于非法用途。使用本SDK所产生的一切后果由使用者自行承担。

📮 联系方式

如有问题或建议,请提交 Issue。