├── .gitignore ├── LICENSE ├── MIT-License ├── Makefile ├── README.md ├── doc ├── api.html ├── assets │ ├── base.css │ ├── bootstrap │ │ ├── css │ │ │ ├── bootstrap-theme.css │ │ │ ├── bootstrap-theme.min.css │ │ │ ├── bootstrap.css │ │ │ └── bootstrap.min.css │ │ ├── fonts │ │ │ ├── glyphicons-halflings-regular.eot │ │ │ ├── glyphicons-halflings-regular.svg │ │ │ ├── glyphicons-halflings-regular.ttf │ │ │ └── glyphicons-halflings-regular.woff │ │ └── js │ │ │ ├── bootstrap.js │ │ │ └── bootstrap.min.js │ ├── bs-docs-masthead-pattern.png │ ├── jquery-1.8.2.min.js │ └── prettify.js └── index.html ├── index.js ├── lib ├── api_chatroom.js ├── api_common.js ├── api_group.js ├── api_history.js ├── api_message.js ├── api_user.js ├── api_wordfilter.js └── util.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage 15 | 16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 17 | .grunt 18 | 19 | # node-waf configuration 20 | .lock-wscript 21 | 22 | # Compiled binary addons (http://nodejs.org/api/addons.html) 23 | build/Release 24 | 25 | # Dependency directory 26 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git 27 | node_modules 28 | 29 | *.sublime* 30 | 31 | doc -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Nick Ma 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /MIT-License: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 Jackson Tian 2 | http://weibo.com/shyvo 3 | 4 | The MIT License 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining 7 | a copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be 15 | included in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | TESTS = test/*.js 2 | REPORTER = spec 3 | TIMEOUT = 20000 4 | ISTANBUL = ./node_modules/.bin/istanbul 5 | MOCHA = ./node_modules/mocha/bin/_mocha 6 | COVERALLS = ./node_modules/coveralls/bin/coveralls.js 7 | 8 | test: 9 | @NODE_ENV=test $(MOCHA) -R $(REPORTER) -t $(TIMEOUT) \ 10 | $(MOCHA_OPTS) \ 11 | $(TESTS) 12 | 13 | test-cov: 14 | @$(ISTANBUL) cover --report html $(MOCHA) -- -t $(TIMEOUT) -R spec $(TESTS) 15 | 16 | test-coveralls: 17 | @$(ISTANBUL) cover --report lcovonly $(MOCHA) -- -t $(TIMEOUT) -R spec $(TESTS) 18 | @echo TRAVIS_JOB_ID $(TRAVIS_JOB_ID) 19 | @cat ./coverage/lcov.info | $(COVERALLS) && rm -rf ./coverage 20 | 21 | test-all: test test-coveralls 22 | 23 | dox: 24 | @doxmate build 25 | 26 | .PHONY: test 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | RongCloud Server API(ES6版) 2 | =========================== 3 | 融云服务器端API。 4 | 5 | 6 | ## 功能列表 7 | - 用户服务 8 | - 群组服务 9 | - 敏感词服务 10 | - 聊天室服务 11 | - 历史消息服务 12 | - 发送消息(文本、图片、语音、视频、音乐、图文) 13 | 14 | ## 更新历史 15 | - 1.1.0 增加“加入聊天室”接口,更改API域名地址。 16 | - 1.0.1 修复若干BUG。 17 | - 1.0.0 第一版发布。 18 | 19 | 详细参见[API文档](http://www.rongcloud.cn/docs/server.html) 20 | 21 | ## Installation 22 | 23 | ```sh 24 | $ npm install co-rongcloud-api 25 | ``` 26 | 27 | ## Usage 28 | 29 | ```js 30 | var RongAPI = require('co-rongcloud-api'); 31 | 32 | var api = new RongAPI(appid, appsecret); 33 | var token = yield* api.getToken('nick-ma'); 34 | ``` 35 | 36 | ## Make Document 37 | 38 | ```sh 39 | npm install doxmate -g 40 | make dox 41 | ``` 42 | 43 | 文档在 ./doc/index.html 处。 44 | 45 | ## License 46 | The MIT license. 47 | 48 | -------------------------------------------------------------------------------- /doc/api.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 |43 | 融云服务端Node库API,ES6版本 44 |
45 |创建聊天室
http://www.rongcloud.cn/docs/server.html#创建聊天室_方法
举例:
// 创建聊天室
368 | var chatroomData = {
369 | 'chatroom[0001]': '1号聊天室',
370 | 'chatroom[0002]': '2号聊天室',
371 | 'chatroom[0003]': '3号聊天室',
372 | 'chatroom[0004]': '4号聊天室',
373 | }
374 | var flag = yield api.chatroomCreate(chatroomData);
375 | if (flag){
376 | // 操作成功
377 | } else {
378 | // 操作失败
379 | }
380 |
381 |
382 | 方法签名
383 |方法 | 387 |exports.chatroomCreate() | 388 |||
参数 | 393 |chatroomData(Array) | 394 |要创建或者加入的聊天室的数据结构(必填) |
395 |
加入聊天室
http://www.rongcloud.cn/docs/server.html#加入聊天室_方法
举例:
var chatroomData = {
userId: ['1','2','3','4'], // 最多不超过 50 个 (必传)
chatroomId: '0001' // 要加入的聊天室 Id。(必传)
}
var flag = yield api.chatroomJoin(chatroomData);
if (flag) {
// 操作成功
} else {
// 操作失败
}
方法签名
410 |方法 | 414 |exports.chatroomJoin() | 415 |||
参数 | 420 |chatroomData(Object) | 421 |要加入的聊天室的数据结构(必填) |
422 |
销毁聊天室
http://www.rongcloud.cn/docs/server.html#销毁聊天室_方法
举例:
// 销毁聊天室
435 | var chatroomId=['0001','0002','0003','0004'];
436 | var flag = yield api.chatroomDestroy(chatroomId);
437 | if (flag){
438 | // 操作成功
439 | } else {
440 | // 操作失败
441 | }
442 |
443 |
444 | 方法签名
445 |方法 | 449 |exports.chatroomDestroy() | 450 |||
参数 | 455 |chatroomId(Array) | 456 |要销毁的聊天室的数据结构(必填) |
457 |
查询聊天室信息
http://www.rongcloud.cn/docs/server.html#查询聊天室信息_方法
举例:
// 查询聊天室信息
470 | var chatroomId=['0001','0002'];
471 | var chatRooms = yield api.chatroomQuery(chatroomId);
472 | if (chatRooms){
473 | // 操作成功
474 | } else {
475 | // 操作失败
476 | }
477 |
478 |
479 | 方法签名
480 |方法 | 484 |exports.chatroomQuery() | 485 |||
参数 | 490 |chatroomId(Array) | 491 |要查询的聊天室(必填) |
492 |
查询聊天室内用户
http://www.rongcloud.cn/docs/server.html#查询聊天室内用户_方法
举例:
// 查询聊天室内用户
505 | var chatroomId='0001';
506 | var users = yield api.chatroomUserQuery(chatroomId);
507 | if (users){
508 | // 操作成功
509 | } else {
510 | // 操作失败
511 | }
512 |
513 |
514 | 方法签名
515 |方法 | 519 |exports.chatroomUserQuery() | 520 |||
参数 | 525 |chatroomId(String) | 526 |要查询的聊天室(必填) |
527 |
API构造函数
Examples:
// 创建api实例
570 | var api = new API("appkey", "appsecret");
571 |
572 |
573 | 方法签名
574 |函数 | 578 |API() | 579 |||
参数 | 584 |appKey(String) | 585 |融信应用的app key |
586 | |
参数 | 591 |appSecret(String) | 592 |融信应用的app secret |
593 |
计算签名。单独使用可以用于验证各种回调接口的签名。
Examples:
// 计算签名
606 | var shasum = api.getSignature("nonce", "timestamp");
607 |
608 |
609 | 方法签名
610 |方法 | 614 |API.prototype.getSignature() | 615 |||
参数 | 620 |nonce(String) | 621 |622 | | |
参数 | 627 |timestamp(String) | 628 |629 | |
设置HTTP请求的参数
Examples:
// 设定超时为15秒
642 | var token = api.setOpts({
643 | timeout: 15000
644 | });
645 |
646 |
647 | 方法签名
648 |方法 | 652 |API.prototype.setOpts() | 653 |||
参数 | 658 |obj(Object) | 659 |请求的配置参数 |
660 |
换取用户的token
Examples:
// 获取用户的token
673 | var token = yield api.getToken(userid, <name>, <portrait_url>);
674 |
675 |
676 | 方法签名
677 |方法 | 681 |API.prototype.getToken() | 682 |||
参数 | 687 |userid(String) | 688 |用户的userid(必填) |
689 | |
参数 | 694 |name(String) | 695 |姓名(选填) |
696 | |
参数 | 701 |portrait_url(String) | 702 |头像url(选填) |
703 |
用于支持对象合并。将对象合并到API.prototype上,使得能够支持扩展
Examples:
// 加入用户管理模块
716 | API.mixin(require('./lib/api_user'));
717 |
718 |
719 | 方法签名
720 |方法 | 724 |API.mixin() | 725 |||
参数 | 730 |obj(Object) | 731 |要合并的对象 |
732 |
方法签名
761 |声明 | 765 |extend | 766 |
消息历史记录下载地址获取
http://www.rongcloud.cn/docs/server.html#消息历史记录下载地址获取_方法
举例:
// 消息历史记录下载地址获取
797 | var date='2014010101';
798 | var chat_data = yield api.historyFetch(date);
799 | if (chat_data){
800 | // 操作成功
801 | chat_data.url
802 | } else {
803 | // 操作失败
804 | }
805 |
806 |
807 | 方法签名
808 |方法 | 812 |exports.historyFetch() | 813 |||
参数 | 818 |date(String) | 819 |指定北京时间某天某小时,格式为2014010101,表示:2014年1月1日凌晨1点。(必填) |
820 |
消息历史记录删除
http://www.rongcloud.cn/docs/server.html#消息历史记录删除_方法
举例:
// 消息历史记录删除
833 | var date='2014010101';
834 | var flag = yield api.historyDelete(date);
835 | if (flag){
836 | // 操作成功
837 | } else {
838 | // 操作失败
839 | }
840 |
841 |
842 | 方法签名
843 |方法 | 847 |exports.historyDelete() | 848 |||
参数 | 853 |date(String) | 854 |指定北京时间某天某小时,格式为2014010101,表示:2014年1月1日凌晨1点。(必填) |
855 |
方法签名
884 |声明 | 888 |extend | 889 |
刷新用户信息
http://www.rongcloud.cn/docs/server.html#刷新用户信息_方法
举例:
// 刷新用户信息
944 | var flag = yield api.refresh(userid, <name>, <portrait_url>);
945 | if (flag){
946 | // 操作成功
947 | } else {
948 | // 操作失败
949 | }
950 |
951 |
952 | 方法签名
953 |方法 | 957 |exports.refresh() | 958 |||
参数 | 963 |userid(String) | 964 |用户的userid(必填) |
965 | |
参数 | 970 |name(String) | 971 |姓名(选填) |
972 | |
参数 | 977 |portrait_url(String) | 978 |头像url(选填) |
979 |
检测用户是否在线
http://www.rongcloud.cn/docs/server.html#检查用户在线状态_方法
举例:
// 检测用户是否在线
992 | var flag = yield api.checkOnline(userid);
993 | if (flag){
994 | // 在线
995 | } else {
996 | // 不在线
997 | }
998 |
999 |
1000 | 方法签名
1001 |方法 | 1005 |exports.checkOnline() | 1006 |||
参数 | 1011 |userid(String) | 1012 |用户的userid(必填) |
1013 |
封禁用户
http://www.rongcloud.cn/docs/server.html#封禁用户_方法
举例:
// 封禁用户
1026 | var flag = yield api.userBlock(userid, minute);
1027 | if (flag){
1028 | // 操作成功
1029 | } else {
1030 | // 操作失败
1031 | }
1032 |
1033 |
1034 | 方法签名
1035 |方法 | 1039 |exports.userBlock() | 1040 |||
参数 | 1045 |userid(String) | 1046 |用户的userid(必填) |
1047 | |
参数 | 1052 |minute(String) | 1053 |封禁时长,单位为分钟,最大值为43200分钟。(必填) |
1054 |
解除封禁用户
http://www.rongcloud.cn/docs/server.html#解除封禁用户_方法
举例:
// 解除封禁用户
1067 | var flag = yield api.userUnblock(userid);
1068 | if (flag){
1069 | // 操作成功
1070 | } else {
1071 | // 操作失败
1072 | }
1073 |
1074 |
1075 | 方法签名
1076 |方法 | 1080 |exports.userUnblock() | 1081 |||
参数 | 1086 |userid(String) | 1087 |用户的userid(必填) |
1088 |
获取被封禁用户
http://www.rongcloud.cn/docs/server.html#获取被封禁用户_方法
举例:
// 获取被封禁用户
1101 | var users = yield api.userBlockQuery(userid);
1102 | if (users){
1103 | // 操作成功,返回被封禁的用户清单
1104 | } else {
1105 | // 操作失败
1106 | }
1107 |
1108 |
1109 | 方法签名
1110 |方法 | 1114 |exports.userBlockQuery() | 1115 |||
参数 | 1120 |userid(String) | 1121 |用户的userid(必填) |
1122 |
添加用户到黑名单
http://www.rongcloud.cn/docs/server.html#添加用户到黑名单_方法
举例:
// 添加用户到黑名单
1135 | var flag = yield api.userBlacklistAdd(userid, blackUserId);
1136 | if (flag){
1137 | // 操作成功
1138 | } else {
1139 | // 操作失败
1140 | }
1141 |
1142 |
1143 | 方法签名
1144 |方法 | 1148 |exports.userBlacklistAdd() | 1149 |||
参数 | 1154 |userid(String) | 1155 |用户的userid(必填) |
1156 | |
参数 | 1161 |blackUserId(String) | 1162 |被加黑的用户Id。(必填) |
1163 |
从黑名单中移除用户
http://www.rongcloud.cn/docs/server.html#从黑名单中移除用户_方法
举例:
// 从黑名单中移除用户
1176 | var flag = yield api.userBlacklistRemove(userid, blackUserId);
1177 | if (flag){
1178 | // 操作成功
1179 | } else {
1180 | // 操作失败
1181 | }
1182 |
1183 |
1184 | 方法签名
1185 |方法 | 1189 |exports.userBlacklistRemove() | 1190 |||
参数 | 1195 |userid(String) | 1196 |用户的userid(必填) |
1197 | |
参数 | 1202 |blackUserId(String) | 1203 |被移除的用户Id。(必填) |
1204 |
获取某用户的黑名单列表
http://www.rongcloud.cn/docs/server.html#获取某用户的黑名单列表_方法
举例:
// 获取某用户的黑名单列表
1217 | var users = yield api.userBlacklistQuery(userid);
1218 | if (users){
1219 | // 操作成功,返回黑名单列表的用户清单
1220 | } else {
1221 | // 操作失败
1222 | }
1223 |
1224 |
1225 | 方法签名
1226 |方法 | 1230 |exports.userBlacklistQuery() | 1231 |||
参数 | 1236 |userid(String) | 1237 |用户的userid(必填) |
1238 |
添加敏感词
http://www.rongcloud.cn/docs/server.html#添加敏感词_方法
举例:
// 添加敏感词
1273 | var flag = yield api.wordfilterAdd(word);
1274 | if (flag){
1275 | // 操作成功
1276 | } else {
1277 | // 操作失败
1278 | }
1279 |
1280 |
1281 | 方法签名
1282 |方法 | 1286 |exports.wordfilterAdd() | 1287 |||
参数 | 1292 |word(String) | 1293 |敏感词,最长不超过 32 个字符。(必填) |
1294 |
移除敏感词
http://www.rongcloud.cn/docs/server.html#移除敏感词_方法
举例:
// 移除敏感词
1307 | var flag = yield api.wordfilterDelete(word);
1308 | if (flag){
1309 | // 操作成功
1310 | } else {
1311 | // 操作失败
1312 | }
1313 |
1314 |
1315 | 方法签名
1316 |方法 | 1320 |exports.wordfilterDelete() | 1321 |||
参数 | 1326 |word(String) | 1327 |敏感词,最长不超过 32 个字符。(必填) |
1328 |
查询敏感词列表
http://www.rongcloud.cn/docs/server.html#查询敏感词列表_方法
举例:
// 查询敏感词列表
1341 | var words = yield api.wordfilterList();
1342 | if (words){
1343 | // 操作成功,敏感词列表
1344 | } else {
1345 | // 操作失败
1346 | }
1347 |
1348 |
1349 | 方法签名
1350 |方法 | 1354 |exports.wordfilterList() | 1355 |
43 | 融云服务端Node库API,ES6版本 44 |
45 |融云服务器端API。
84 |详细参见API文档
94 |$ npm install co-rongcloud-api
96 |
97 | var RongAPI = require('co-rongcloud-api');
99 |
100 | var api = new RongAPI(appid, appsecret);
101 | var token = yield* api.getToken('nick-ma');
102 |
103 | The MIT license.
105 | 106 |