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

aliyun-sms-sdk

v1.0.2

Published

阿里云短信模块在node.js上的实现

Downloads

17

Readme

aliyun-sms-sdk

阿里云短信服务Node.js的实现

安装

$ npm install aliyun-sms-sdk --save

阿里云官方文档:短信服务文档

使用方法

在项目中安装aliyun-sms-sdk package后,需要根据官方文档做一些配置

send()

const aliSms = require('aliyun-sms-sdk');
const confSend = {
    accessKeyId: 'Your accessKeyId',
    secretAccessKey: 'Your secretAccessKey',
    recNum: 'Send SMS to ....',
    signName: 'Sign name',
    templateCode: 'SMS template code (SMS_XXXXXX)',
    param: { "username": "Sirius" }
};

aliSms.send(confSend);  //发送短信

返回值:

{   
    Message: 'OK',
    RequestId: '502FC867-40EB-4A9F-8561-3272FBF7C4CB',
    BizId: '109226971936^1112321971296',
    Code: 'OK' 
}

receive()


const aliSms = require('aliyun-sms-sdk');
const confReceive = {
    accessKeyId: 'Your accessKeyId',
    secretAccessKey: 'Your secretAccessKey',
    queueName: 'Alicom-Queue-xxxxxxxxxxxxx-'
};

aliSms.receive(confReceive);   //接收用户发来的短信(短信上行)

返回值:

{
    receiveMsg: {
        "code": 200,
        "headers": {},
        "body": {
            "MessageId": "DD48C8069525249D-2-15DAC6DF8B7-300000001",
            "MessageBodyMD5": "B94416522AF45DA65D66A07BEEB396ED",
            "MessageBody": 'eyJjb250ZW50Ijoi5ZOI5ZOI5ZOI5ZOI5ZOIIiwic2VuZF90aW1lIjoiMjAxNzA4MDcxNTQ4MTIiLCJzcF9pZCI6bnVsbCwicGhvbmVfbnVtYmVyIjoiMTg1MTQyNDMwODgiLCJkZXN0X2NvZGUiOiIxMjQzMzM1Iiwic2VxdWVuY2VfaWQiOjQ4MjExODA5NX0=', //需要进行Base64解码Ï
            "ReceiptHandle": "1-MTI4ODQ5MDE4ODktMTUwMjA4NzUwMi0yLTg=",
            "EnqueueTime": "1501836474551",
            "FirstDequeueTime": "1501836581811",
            "NextVisibleTime": "1502087502000",
            "DequeueCount": "3",
            "Priority": "8"
        }
    },
    deleteMsg: {
        code: 204,
        headers: {
            
        },
        body: undefined
    }
}

作者修改了官方的SDK,因为官方SDK中并没有对已经消费的消息进行删除操作。

receiveMsg是消费一条消息,其中body.MessageBody需要进行Base64解码:

const msgBody = new Buffer(result.body.MessageBody, 'base64').toString();
console.log(msgBody);

结果样例:

{
    "content": "123456789",
    "send_time": "20170804164754",
    "sp_id": null,
    "phone_number": "13800138000",
    "dest_code": "1243335",
    "sequence_id": 481806640
}

Test

#send short message
node test/send

#receive short message upload
node test/receive

补充说明

阿里云提供了Node.js版本的短信服务SDK,但是比较简陋。作者因公司业务需要,没有对本项目进行优化和架构(实在也是简单),如有意见、建议或bug,请直接提issue给我。

官方的SDK中已经实现了查询短信发送记录和短信发送状态回执的方法,我司项目暂时不需要这两个方法,项目完成后,我会把这两个方法补上,一定,一定。