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 🙏

© 2024 – Pkg Stats / Ryan Hefner

fast-node-weixin

v0.0.14

Published

一个基于koa2框架的微信公众号开发框架

Downloads

50

Readme

FastNodeWeiXin

一个基于 Koa2 的微信公众平台开发框架

参考框架:

co-wechat-api

wx-connect

示例项目

Example

使用方法

安装

npm i fast-node-weixin -S

或者

yarn add fast-node-weixin

初始化

const FastNodeWeiXin = require("fast-node-weixin");

var Weixin = new FastNodeWeiXin("appid", "appsecret", "apptoken");

module.exports = Weixin;

在其他类中引用

const WeiXin = require("./WeiXin");

匹配消息和事件

普通消息

1.匹配文本消息,支持匹配多个,支持通配符和精确匹配

WeiXin.text("无", ctx => {
  ctx.text("这里是精确匹配到的无关键词");
})
  .text("买*", ctx => {
    ctx.text("这里是通配符匹配到的买关键词----买东西");
  })
  .text("*买*", ctx => {
    ctx.text("这里是两个通配符匹配到的买关键词----我要买东西");
  })
  .text("好,哈", ctx => {
    ctx.text("这里是匹配多个关键词");
  });

2.匹配图片消息

WeiXin.image(ctx => {});

3.匹配语音消息

WeiXin.voice(ctx => {});

4.匹配视频消息

WeiXin.video(ctx => {});

5.匹配短视频消息

WeiXin.shortvideo(ctx => {});

6.匹配普通位置消息

WeiXin.normalLocation(ctx => {});

7.匹配链接消息

WeiXin.link(ctx => {});

事件

1.匹配按钮事件

WeiXin.menu("LEFT", ctx => {
  ctx.text("你点击了key为LEFT的按钮");
}).menu("RIGHT", ctx => {
  ctx.text("你点击了key为RIGHT的按钮");
});

2.匹配扫码事件

WeiXin.scan("stick_仇", ctx => {
  ctx.text("这里是扫码匹配参数:stick_仇");
}).scan("stick_肥", ctx => {
  ctx.text("这里是扫码匹配参数:stick_肥");
});

3.匹配关注事件

如果是扫码关注的,会先触发扫码事件,再触发关注事件。

WeiXin.subscribe = ctx => {
  ctx.text("欢迎关注我的公众号");
};

4.匹配取消关注事件

WeiXin.unsubscribe = ctx => {
  console.log("取消关注事件");
  ctx.success();
};

5.匹配定位事件

WeiXin.location = ctx => {};

Log 记录事件

文本消息,点击事件,扫码事件 匹配完之后 会触发 log 事件,用于统计分析。这里请不要做回复。

1.文本消息 log 记录 WeiXin.textLog = ctx => {};

2.点击事件 log 记录 WeiXin.clickLog = ctx => {};

3.扫码事件 log 记录 WeiXin.scanLog = ctx => {};

回复消息

1.文本消息

ctx.text("这里是无关键词");

2.图文消息

ctx.news([
  {
    title: "你想知道的都在这里",
    description: "毛孩子的生活哲学。FURLOSOPHY IS THE NEW PHILOSOPHY。",
    picUrl: "https://mmbiz.qpic.cn/mmbiz_jpg",
    url: "https://mp.weixin.qq.com/"
  }
]);

3.视频消息

ctx.video({
  mediaId: ""
});

4.图片消息

ctx.image({
  mediaId: ""
});

5.语音消息

ctx.voice({
  mediaId: ""
});

6.音乐消息

ctx.music({
  title: "",
  description: "",
  url: "",
  hqUrl: ""
});

7.回复 success 字符串,事件未匹配时也会使用这个

ctx.success();

8.转发消息到客服系统,文本消息未匹配时也会使用这个

ctx.transfer();

其他接口

1.发送模板消息

data 数据的 value 为字符串时会转为 json 对象

例如 keyword1: "公众号开发课程" 等同于 keyword1: {value:"公众号开发课程"}

也可以自定义颜色 keyword1: {value:"公众号开发课程",value:"#ff0000"}

var result = await WeiXin.sendTemplate({
  touser: "oG-Wm0yxFP7lSrMASfHevIL8k5WA",
  template_id: "mOJ3pdY0Qc6kuvNPFl5x1EvwNiAzQJe779yZWnLIY6I",
  url: "https://www.baidu.com",
  miniprogram: {},
  topcolor: "#616161",
  data: {
    first: "这个是标题",
    keyword1: "公众号开发课程",
    keyword2: "19.9",
    keyword3: "马云",
    keyword4: "2018年8月6日"
  }
});

2.获取 access_token

const accessToken = await WeiXin.getAccessToken();