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

mm_sms

v1.0.8

Published

这是超级美眉发送短信类,基于实现,支持异步操作。

Downloads

18

Readme

mm_sms

npm version License

一个基于短信宝API的短信发送模块,支持发送文本短信和批量发送。继承自 mm_expand.Base 类,提供日志记录功能。

特性

  • 📱 支持短信宝API
  • 🔄 异步操作,支持Promise
  • 📨 批量发送短信
  • ⏱️ 可配置发送间隔
  • 📝 完善的错误处理
  • 🔧 易于集成和使用

安装

npm install mm_sms

快速开始

const { Sms } = require('mm_sms');

// 配置短信信息
const config = {
    username: 'your_username',   // 短信宝用户名
    password: 'your_password',   // 短信宝密码
    host: 'api.smsbao.com',      // 短信宝API地址(默认)
    interval: 1000               // 发送间隔(毫秒,默认1000)
};

// 创建实例
const sms = new Sms(config);

// 发送短信
async function sendSms() {
    try {
        const result = await sms.send(
            '【签名】您的验证码是:123456,5分钟内有效',
            '13800138000'
        );
        console.log('发送结果:', result);
    } catch (err) {
        console.error('发送失败:', err);
    }
}

sendSms();

API 文档

类:Sms

继承自 mm_expand.Base 类。

构造函数

new Sms(config)

参数说明:

  • config (Object): 短信配置对象
    • host (String): 短信宝API地址,默认为 'api.smsbao.com'
    • username (String): 短信宝用户名
    • password (String): 短信宝密码
    • to (Array): 默认收件人手机号列表,默认为空数组
    • interval (Number): 批量发送间隔(毫秒),默认为 1000

方法

send(content, ...to)

发送短信的主要方法。

参数说明:

  • content (String): 短信内容
  • ...to (String): 收件人手机号,支持多个收件人

返回值:

  • Promise<Array>: 返回发送结果数组,每个对象包含:
    • mobile (String): 手机号
    • error (String|null): 错误信息,成功时为null
    • result (Object): 发送结果详情
add(...to)

添加收件人到默认列表。

参数说明:

  • ...to (String): 收件人手机号

返回值:

  • Sms: 当前实例,支持链式调用
del(...to)

从默认列表中删除收件人。

参数说明:

  • ...to (String): 收件人手机号

返回值:

  • Sms: 当前实例,支持链式调用
close()

关闭短信连接。

返回值:

  • Promise

示例

发送单条短信

const { Sms } = require('mm_sms');

const sms = new Sms({
    username: 'your_username',
    password: 'your_password'
});

const result = await sms.send(
    '【签名】您的验证码是:123456,5分钟内有效',
    '13800138000'
);

console.log('发送结果:', result);

批量发送短信

const { Sms } = require('mm_sms');

const sms = new Sms({
    username: 'your_username',
    password: 'your_password',
    interval: 2000 // 设置2秒间隔
});

const results = await sms.send(
    '【签名】系统通知:服务器将于今晚10点进行维护,请提前做好准备。',
    '13800138000',
    '13800138001',
    '13800138002'
);

results.forEach(result => {
    if (result.error) {
        console.error(`发送失败 ${result.mobile}:`, result.error);
    } else {
        console.log(`发送成功 ${result.mobile}`);
    }
});

使用默认收件人列表

const { Sms } = require('mm_sms');

const sms = new Sms({
    username: 'your_username',
    password: 'your_password',
    to: ['13800138000', '13800138001'] // 默认收件人
});

// 添加更多收件人
sms.add('13800138002', '13800138003');

// 发送给所有收件人
const results = await sms.send('【签名】群发测试消息');

// 删除特定收件人
sms.del('13800138003');

错误处理示例

const { Sms } = require('mm_sms');

const sms = new Sms({
    username: 'your_username',
    password: 'your_password'
});

try {
    // 发送空内容会抛出错误
    await sms.send('', '13800138000');
} catch (err) {
    console.error('发送失败:', err.message);
}

try {
    // 没有收件人会抛出错误
    await sms.send('测试消息');
} catch (err) {
    console.error('发送失败:', err.message);
}

全局实例

如果存在全局 $ 对象且没有 $.sms 属性,模块会自动创建全局实例:

// 自动创建全局实例
$.sms.send('【签名】测试消息', '13800138000');

注意事项

  1. 需要先在短信宝平台注册账号并获取用户名和密码
  2. 短信内容需要包含短信签名,格式为 【签名】内容
  3. 批量发送时会按照配置的间隔时间依次发送,避免触发频率限制
  4. 确保手机号格式正确(11位数字)
  5. 模块继承自 mm_expand.Base,可以使用 logger 方法记录日志

依赖

开发

# 运行测试
npm test

# 开发模式(使用nodemon)
npm run dev

许可证

ISC License

贡献

欢迎提交 Issue 和 Pull Request!

作者

邱文武