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

@neuroo_fe/wechat-template-mass

v0.1.0

Published

微信模版消息群发功能模块

Downloads

3

Readme

wechat-template-mass

微信模版消息群发功能模块。

Usage

npm install @neuroo_fe/wechat-template-mass -S
const MassFactory = require('wechat-template-mass')
const massFactory = new MassFactory(appId, appSecret [,getTokenFunction])

const openIds = [ 'oDetxwdKb1uyCTogQzFvYymlrcLc' ]
const concurrent = 10
const templateId = 'D_vgWaYRVADAtXKYPxWPlsRQ5tBY3R70Hig4W_LhsX8'
const url = 'https://google.com/'
const data = {
  first: {
    value: '测试内容',
    color: '#000000'
  },
  remark: {
    value: '测试内容',
    color: '#000000'
  }
}

const mass = massFactory.createMass(openIds, concurrent, templateId, url, data)

mass.on('finish', console.log)

mass.start()

/*
{ ok: 0,
  fail: 1,
  complete: 1,
  total: 1,
  startTime: '2017-8-18 14:53:41',
  endTime: '2017-8-18 14:53:45',
  duration: 23 }
*/

MassFactory 构造函数

new MassFactory([appId, appSecret, getTokenFunction])

生成一个MassFactory实例对象

参数

| 名称 | 类型 | 必填 | 描述 | | --- | --- | --- | --- | | appId | String | 否 | 微信公众号appId | | appSecret | String | 否 | 微信公众号appSecret | | getTokenFunction | String | 否 | 获取公众号接口access_token方法 |

注意:需要传入 appIdgetTokenFunction 其中一个。

返回值

MassFactory实例对象。

MassFactory 实例方法

createMass

生成 Mass 实例

参数

| 名称 | 类型 | 必填 | 描述 | | --- | --- | --- | --- | | openIds | Array | 是 | 群发目标的openId数组 | | concurrent | Number | 是 | 并发数 | | templateId | String | 是 | 模板Id | | url | String | 是 | 模板点击后跳转的URL | | data | Object | 是 | 模板插值的填充数据 |

返回值

Mass 实例对象。

Mass 实例方法

start

开始群发任务。重复调用无效。

stop

停止群发任务。重复调用无效,先恢复后才能再次暂停。

resume

恢复群发任务。重复调用无效,先暂停后才能再次恢复。

Mass 实例事件

ok

当群发的消息中有一条成功时触发。参数为result对象。

result 对象属性

| 名称 | 类型 | 描述 | | --- | --- | --- | | openId | String | 用户openId | | status | String | 发送状态 |

fail

当群发的消息中有一条失败时触发。参数为result对象。

result 对象属性

| 名称 | 类型 | 描述 | | --- | --- | --- | | openId | String | 用户openId | | status | String | 发送状态 | | response | Object | 错误对象 |

finish

当全部群发完成时触发。参数为result对象。

result 对象属性

| 名称 | 类型 | 描述 | | --- | --- | --- | | ok | Number | 成功数量 | | fail | Number | 失败数量 | | complete | Number | 完成的数量 | | total | Number | 总数量。一般应该等于complete。 | | startTime | String | 开始发送的时间。 | | endTime | String | 完成时的时间。 | | duration | Number | 发送的持续时间。单位:ms。当调用stop()方法暂停发送时,只在重新调用resume()方法恢复发送时才会重新计算duration,因此中间的等待时间不计入此属性。 |

progress

进度事件。参数为result对象。

result 对象属性

| 名称 | 类型 | 描述 | | --- | --- | --- | | ok | Number | 成功数量 | | fail | Number | 失败数量 | | complete | Number | 完成的数量 | | total | Number | 总数量。一般应该等于complete。 | | percent | String | 进度百分比。 |