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

wechatmp-kit

v0.1.2

Published

微信公众号工具包

Readme

🎉 微信公众号开发工具包 🛠️

一个基于TypeScript的微信公众号开发工具包,提供核心API接口和实用工具。

🚀 核心功能

  • 🔑 Access Token管理
    • ✅ 自动获取和缓存Access Token
    • 🛠️ 支持自定义Token缓存实现
  • 📨 消息处理
    • 📝 XML消息解析与生成
    • 📦 消息服务封装
  • 👤 用户管理
    • 🛠️ 提供用户服务接口
  • 🌐 通用请求
    • 📡 封装微信API请求

📦 安装

npm install wechatmp-kit
# 或者
yarn add wechatmp-kit

⚡ 快速开始

初始化

import { WechatMpApi } from 'wechatmp-kit'

const wechatApi = new WechatMpApi({
  appId: '你的应用ID',
  appSecret: '你的应用密钥',
})

获取Access Token

const token = await wechatApi.getAccessToken()
console.log('Access Token:', token)

处理消息

const messageService = wechatApi.getMessageService('your-token')
const parsedMessage = messageService.parseXML(xmlMessage)

使用用户服务 👤

const userService = wechatApi.userService

// 获取用户列表
const userList = await userService.userGet()

// 按标签获取用户
const taggedUsers = await userService.userTagGet(tagId)

// 获取所有标签
const tags = await userService.tagsGet()

// 发送模板消息
await userService.messageTemplateSend({
  touser: openId,
  template_id: 'TEMPLATE_ID',
  data: {
    key1: { value: '内容1' },
    key2: { value: '内容2' },
  },
})

📚 API 参考

WechatMpApi

构造函数

new WechatMpApi(options: {
  appId: string
  appSecret: string
  tokenCache?: WehcatMpAccessTokenCacheManager
})

主要方法

  • getAccessToken(): 获取当前Access Token
  • getMessageService(token: string, encodingAESKey?: string): 获取消息处理服务
  • request<T>(options: RequestOptions): 发送微信API请求

WehcatMpAccessTokenCacheManager

Token缓存管理接口,默认提供内存缓存实现。

方法

  • get(appId: string): 获取缓存Token
  • set(appId: string, value: AccessTokenApiResult): 设置缓存Token

工具函数

  • parseWehcatMessageXML<T>(xml: string): 解析微信XML消息
  • renderXML(data: Record<string, string | number | object>): 生成XML消息

🤝 贡献指南

欢迎提交Pull Request。请确保代码风格一致并通过所有测试。

📜 许可证

本项目采用 MIT 许可证。