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

@re-ai/wxkf-store

v0.1.0

Published

微信小店客服API SDK

Readme

微信小店客服 SDK

这是一个用于对接微信小店客服API的Node.js SDK,使用TypeScript开发。

安装

npm install @re-ai/wxkf-store

使用方法

初始化客户端

import { WxStoreKfClient, MessageType } from '@re-ai/wxkf-store';

// 不使用Redis
const client = new WxStoreKfClient({
  appId: 'your_app_id',
  appSecret: 'your_app_secret'
});

// 使用Redis缓存访问令牌
const clientWithRedis = new WxStoreKfClient({
  appId: 'your_app_id',
  appSecret: 'your_app_secret',
  redis: {
    host: 'localhost',
    port: 6379,
    username: 'your_redis_username', // 可选
    password: 'your_redis_password', // 可选
 
  }
});

发送文本消息

async function sendTextMessage() {
  const message = {
    type: MessageType.TEXT,
    open_id: 'user_open_id',
    text: {
      content: '您好,这是一条测试消息'
    }
  };

  try {
    await client.sendMessage(message);
    console.log('消息发送成功');
  } catch (error) {
    console.error('消息发送失败:', error);
  }
}

发送图片消息

async function sendImageMessage() {
  const message = {
    type: MessageType.IMAGE,
    open_id: 'user_open_id',
    image: {
      cos_url: 'https://example.com/image.jpg'
    }
  };

  try {
    await client.sendMessage(message);
    console.log('图片消息发送成功');
  } catch (error) {
    console.error('图片消息发送失败:', error);
  }
}

发送商品分享卡片

async function sendProductShareMessage() {
  const message = {
    type: MessageType.PRODUCT_SHARE,
    open_id: 'user_open_id',
    product_share: {
      product_id: '10000147759678'
    }
  };

  try {
    await client.sendMessage(message);
    console.log('商品分享卡片发送成功');
  } catch (error) {
    console.error('商品分享卡片发送失败:', error);
  }
}

上传多媒体资源

import * as fs from 'fs';
import * as path from 'path';

async function uploadMedia() {
  const filePath = path.join(__dirname, 'test_image.jpg');
  const fileStream = fs.createReadStream(filePath);

  try {
    const cosUrl = await client.uploadMedia({
      open_id: 'user_open_id',
      msg_type: MessageType.IMAGE,
      file: fileStream
    });
    console.log(`多媒体资源上传成功,cos_url: ${cosUrl}`);
  } catch (error) {
    console.error('多媒体资源上传失败:', error);
  }
}

处理客服消息推送

import { ReAIWXStoreKFMessageNotifyHandle } from '@re-ai/wxkf-store';

const options = {
  token: 'your_token',
  encodingAesKey: 'your_encodingAesKey',
  appId: 'your_appId'
};

const messageCallback = (message) => {
  console.log('收到解析后的消息:', message);
  // 在这里添加你对解析后消息的处理逻辑
};

// 在HTTP服务器中处理微信推送
app.post('/wxkf/notify', async (req, res) => {
  const result = await ReAIWXStoreKFMessageNotifyHandle(options, {
    query: req.query,
    body: req.body
  }, messageCallback);
  
  if (result === 'success' || result === '') {
    res.send('success');
  } else {
    res.status(500).send('处理失败');
  }
});

API文档

WxStoreKfClient

客服API客户端类,用于发送消息和管理会话。

构造函数

constructor(options: WxStoreKfOptions)

参数:

  • options.appId: 微信小程序的AppID
  • options.appSecret: 微信小程序的AppSecret

方法

sendMessage

发送客服消息。

async sendMessage(message: BaseMessage): Promise<void>

支持的消息类型:

  • 文本消息 (TextMessage)
  • 图片消息 (ImageMessage)
  • 文件消息 (FileMessage)
  • 商品分享消息 (ProductShareMessage)
  • 订单分享消息 (OrderShareMessage)
uploadMedia

上传多媒体资源。

async uploadMedia(options: UploadMediaOptions): Promise<string>