Nodejs的飞信发送类 - fetion-sender

Nodejs的飞信发送类 - fetion-sender

这个类有个 demo 就是飞信喵。地址是 http://fetion.kacaka.ca/ 。当然这个 demo 也有提供发送API服务,详情请看 http://fetion.kacaka.ca/api/intro 或者 http://cnodejs.org/topic/525bc139d0af751c0e1065e9

该API目前只是部署在本人的动态域名树莓上,作测试玩玩用,网络并不稳定,若要用作各种正规用途的情三思。

不过如果你想自己提供飞信的类而不是调用网上别人写的API的话,那么就用这个 fetion-sender 吧。

安装很简单:

$ npm install fetion-sender

git地址是:https://github.com/XadillaX/fetion-sender

飞信的话,用于小群体(比如说小公司成员什么什么的)群发通知比较好用。但是希望大家不要滥用,不然很可能会被 中国移不动 公司察觉了这个bug然后修补了,到时候这个就不能用了。

<hr />

然后下面是 github 上的 README.md

Node Fetion Sender

This node package allows you to send fetion message via node.js.

Get it

You just need to install this module via npm:

$ npm install fetion-sender

Or download it from here and put it to your node_modules directory.

Another way is to clone this repo via git to your node_modules directory.

Usage

Simple

The easiest way to send a message is just shown below:

var from = "152********";
var password = "********";
var to = "152********";
var msg = "Hello world!";
var fetion = require("fetion-sender");
fetion.send(from, password, to, msg, function(status, msg) {
    if(!status) {
        console.log(msg);
    } else {
        console.log("Sent successfully!");
    }
});

Make sure that the receiver is your fetion friend.

If you sent successfully, the status in callback function will be true and msg will be an empty string. Otherwise, status is false and msg contains the error message.

Extra

If you want control the process, you will use the protocol helper.

Protocol Helper is a class of fetion sender. You can get a new protocol helper object by calling:

var helper = require("fetion-sender").createSender();

There’re several functions in that object.

Tip: The callback shown below are all in format of

function callback(status, msg);

  • status stands for the status of the function you’re called. true means succeed and false means failed.
  • msg stands for the result message. If status is true, this msg will be empty or some useful result such as user ID and so on. And if status is false, this parameter will be the error message.

Login

Login function will be called like

helper.login(username, password, callback);

Before you do anything with this helper, make sure you’re logged in.

Send

This is the send function

helper.send(phonenumber, message, callback);

Send to Friend *

This function is called by send function. But you can call it also.

helper.sendToFriend(userid, message, callback);

Caution: The first parameter is not phonenumber but userid which is returned by getUserID function.

Send to Self *

If you’re sending message to yourself (sender number is the receive number), you can’t use sendToFriend function. This function is also called by send function.

helper.sendToSelf(message, callback);

Get CSRF Token *

A CSRF token is required while you’re sending message to your friend. I think this token is something like a session id. Get a CSRF token with a friend means you’ve set up a session with him/her.

This function is called by sendToFriend.

helper.getCsrfToken(userid, callback);

Get User ID *

If you want use sendToFriend function, you must have the user ID of your friend. This function is to get the user ID with phone number.

helper.getUserID(phonenumber, callback);

5 回复

Nodejs的飞信发送类 - fetion-sender

摘要

这个类有一个演示程序叫做“飞信喵”,其地址为 http://fetion.kacaka.ca/。该演示程序还提供了发送API服务,详情请查看 http://fetion.kacaka.ca/api/intro 或者 http://cnodejs.org/topic/525bc139d0af751c0e1065e9

需要注意的是,该API目前仅部署在个人的动态域名树莓上,仅供测试使用,网络可能不稳定。如果需要用于正式用途,请三思而后行。

如果您希望自行实现飞信发送功能,可以使用 fetion-sender 这个库。以下是安装方法:

$ npm install fetion-sender

fetion-sender 的 GitHub 地址为 https://github.com/XadillaX/fetion-sender

使用方法

简单使用

最简单的发送消息的方式如下所示:

var from = "152********"; // 发送方手机号码
var password = "********"; // 发送方密码
var to = "152********"; // 接收方手机号码
var msg = "Hello world!"; // 要发送的消息

var fetion = require("fetion-sender");
fetion.send(from, password, to, msg, function(status, msg) {
    if (!status) {
        console.log(msg); // 打印错误信息
    } else {
        console.log("Sent successfully!"); // 成功发送消息
    }
});

确保接收方已经是您的飞信好友。如果发送成功,回调函数中的 status 会是 true,并且 msg 为空字符串。否则,statusfalsemsg 包含错误信息。

高级用法

如果您想更精细地控制发送过程,可以使用 协议助手(Protocol Helper)。这是一个 fetion-sender 提供的类,可以通过以下方式创建:

var helper = require("fetion-sender").createSender();

Protocol Helper 中包含多个函数:

  • 登录 (login):

    helper.login(username, password, callback);
    
  • 发送 (send):

    helper.send(phonenumber, message, callback);
    
  • 发送给好友 (sendToFriend):

    helper.sendToFriend(userid, message, callback);
    

    注意:第一个参数是 userid,而不是 phonenumberuserid 可以通过 getUserID 函数获取。

  • 发送给自己 (sendToSelf):

    helper.sendToSelf(message, callback);
    
  • 获取CSRF令牌 (getCsrfToken):

    helper.getCsrfToken(userid, callback);
    
  • 获取用户ID (getUserID):

    helper.getUserID(phonenumber, callback);
    

总结

fetion-sender 是一个非常实用的库,适合用于小群体之间的通知发送。但请注意不要滥用,以免引起运营商的关注并导致服务不可用。

希望以上内容对您有所帮助!


我发现乃好像一直在发各种好东西ლ(╹◡╹ლ)

-. - 这为什么算是好东西?东西很简单只不过没人造轮子或者说造了轮子没发上来而已。

楼主太萌了。。。。

对于“Nodejs的飞信发送类 - fetion-sender”这个帖子的内容,以下是基于您所提供的信息的回答:

示例代码

var from = "152********"; // 发送方手机号
var password = "********"; // 发送方密码
var to = "152********"; // 接收方手机号
var msg = "Hello world!"; // 发送的消息内容

// 引入 fetion-sender 模块
var fetion = require("fetion-sender");

// 调用发送函数
fetion.send(from, password, to, msg, function(status, msg) {
    if (!status) {
        console.log(msg); // 打印错误信息
    } else {
        console.log("Sent successfully!"); // 发送成功提示
    }
});

说明

  • 安装: 使用 npm install fetion-sender 安装 fetion-sender 模块。
  • 发送过程: 要发送飞信消息,首先需要从和发送给的人是飞信好友关系。上述代码展示了如何使用 fetion.send 方法来发送消息。该方法接收四个参数:发送方手机号、发送方密码、接收方手机号以及要发送的消息内容,并提供一个回调函数来处理发送结果。

注意: 由于飞信的限制和可能的服务稳定性问题,请谨慎使用此功能,避免对服务造成不必要的负担。

回到顶部