http-api-sdk
v2.3.0
Published
扩展你的QQ/微信机器人用途,提供跨框架平台的PHP/Java/Python/NodeJS等编程语言SDK。https://github.com/ksust/HTTP--API
Downloads
1
Maintainers
Readme
HTTP-API-SDK
包含PHP/Java/Python/NodeJS四种编程语言SDK。
Github:https://github.com/ksust/HTTP--API
NodeJS SDK安装:npm install http-api-sdk
| 名称 | 编程语言 | 最新版本 | 适配插件版本 | 备注 | | ------ | ------ | ------| ------ | ------ | | HTTP-API-SDK For PHP | PHP |2.3.0|2.3.0|-| | HTTP-API-SDK For Java | Java8 |2.3.0|2.3.0|-| | HTTP-API-SDK For Python | Python2/3 |2.3.0|2.3.0|-| | HTTP-API-SDK For NodeJS | NodeJS8 |2.3.0|2.3.0|-|
NodeJS Demo
安装依赖:npm install http-api-sdk
引用包:如 const HTTPSDK = require('http-api-sdk');
提交返回
/**
* Demo
* User: yugao
* Date: 2019/2/27
* version 2.2.2
* Note: HTTPSDK for NodeJS(适用于版本2.2.2插件):用于解析插件消息、构造返回数据,以及HTTP推送(发起HTTP请求)
* Contact: 开发者邮箱 [email protected]
* 安装SDK:npm install http-api-sdk
*/
const http = require('http');
const HTTPSDK = require('http-api-sdk');
const server = http.createServer((req, res) => {
req.on('data', function (data) {
let sdk = HTTPSDK.httpGet(data.toString());
//console.log(sdk.getMsg());//获取到的消息
sdk.sendPrivateMsg(sdk.getMsg()['QQ'], '你发送了这样的消息:' + sdk.getMsg()['Msg']);
sdk.getLoginQQ();
//回调演示,提交返回获取群列表、登录QQ等
if (sdk.isCallback() && parseInt(sdk.getMsg()['Type']) === HTTPSDK.TYPE_GET_LOGIN_QQ) {
console.log('Login QQ:' + sdk.getLoginQQ());
}
res.end(sdk.toJsonString());
});
});
server.on('clientError', (err, socket) => {
socket.end('HTTP/1.1 400 Bad Request\r\n\r\n');
});
server.listen(8000);
webSocket()
//与PHP版本类似,传入获取的字符串即可。取决于用什么框架,和上述提交返回使用方法基本相同,这里不再赘述。
HTTP推送
/**
* Demo
* User: yugao
* Date: 2019/2/27
* version 2.2.2
* Note: HTTPSDK for NodeJS(适用于版本2.2.2插件):用于解析插件消息、构造返回数据,以及HTTP推送(发起HTTP请求)
* Contact: 开发者邮箱 [email protected]
* 安装SDK:npm install http-api-sdk
*/
const HTTPSDK = require('http-api-sdk');
//推送演示,需要配置推送
push = HTTPSDK.httpPush('http://127.0.0.1:8080')
push.getGroupList().data(function (data) {
console.log('push ' + data)
});
push.getLoginQQ().data(function (data) {
console.log('push ' + data)
});
push.sendPrivateMsg('QQ', 'Hello').data(function (data) {
console.log('push ' + data)
});
//消息转发演示,插件在线即可用
let forward = HTTPSDK.msgForwardPush('QQ', '授权码');
forward.getLoginQQ().data(function (data) {
console.log('forward ' + data);
});
forward.getGroupList().data(function (data) {
console.log('forward ' + data);
});
forward.sendPrivateMsg('QQ', 'Hello').data(function (data) {
console.log('forward' + data)
});
消息转发
//上述推送中包含消息转发(forward)