├── README.md ├── SDK ├── Java │ ├── http-api-sdk-2.3.0-jar-with-dependencies.jar │ └── http-api-sdk-2.3.0.jar ├── NodeJS │ └── install ├── PHP │ ├── HTTPSDK.php │ └── composer install └── Python │ └── install ├── demo ├── Java │ └── HTTP-API-Java-Demo ├── NodeJS │ ├── demo-push.js │ ├── demo-server.js │ └── package.json ├── PHP │ ├── .gitignore │ ├── HTTPSDK.php │ ├── LICENSE │ ├── README.md │ ├── composer.json │ └── demo │ │ ├── demo-forwardPush.php │ │ ├── demo-push.php │ │ ├── demo-ws.php │ │ └── demo.php └── Python │ ├── demo-flask.py │ ├── demo-push.py │ └── demo-server.py ├── plugin ├── HTTP-API.IR.dll ├── com.ksust.qq.http-api.cpk ├── com.ksust.qq.http-api.ql.dll └── com.ksust.qq.http-api.qyk.dll └── resources ├── appInstall1.png ├── appInstall2.png ├── appList.png ├── appTest.png ├── bindMaster.png ├── donate.png ├── myAppList.png ├── setting1.png ├── setting2.png ├── setting3.png └── verifyList.png /README.md: -------------------------------------------------------------------------------- 1 | HTTP-API: CoolQ/QQLight/QY Extensioin 2 | --- 3 | 4 | 扩展你的QQ/微信机器人用途,提供跨框架平台的PHP/Java/Python/NodeJS等编程语言SDK。 5 | 6 | ------ 7 | 8 | ## HTTP-API简介 9 | --- 10 | HTTP-API是一款主要通过HTTP协议(另外也包含使用webSocket、socket等协议)与机器人进行通信的插件,主要提供PHP/Java/Python/NodeJS等编程语言SDK,以便将机器人用于WEB、大数据、机器学习等领域,尽可能地提现数据的价值。 11 | 目前插件主要支持酷Q、QQLight、契约机器人框架,开发者可以通过使用SDK非常方便地对机器人进行操作,比如控制机器人发送消息、公告,获取机器人群列表、好友列表,通过及监听获取近一个月、或者几年的聊天记录。开发者可通过简单的操作完成一些小程序、小应用对的开发,亦可应用于大型应用中。 12 | 此外,通过配合使用[WEB管理平台](http://work.ksust.com),开发者可将自己开发的应用发布到应用商店中,通过用户安装的方式获得收入、使用数据等。用户可直接通过WEB平台安装、管理应用,以及可以批量管理机器人在线状态、收发消息等,让用户用最少的时间完成尽可能多的事。 13 | **注:以下表格描述中QQLight简称QL,CoolQ(酷Q)简称CQ,契约简称QY** 14 | 交流群:(QQ群,用户加入)537419179 15 | 开发群:(QQ群,开发者加入)598629636 16 | 管理平台:http://work.ksust.com 17 | 18 | ### 版本分布(来源) 19 | |名称|最新版本|协议版本|状态|来源|备注|Demo地址| 20 | |----|----|----|----|----|----|----| 21 | |HTTP-API For CleverQQ|2.3.0|2.3.0|已跑路|标准插件|HTTP-API CleverQQ DLL插件|[插件下载](https://github.com/ksust/HTTP--API/blob/master/plugin/HTTP-API.IR.dll)| 22 | |HTTP-API For CoolQ|2.3.6|2.3.6|已发布|标准插件|HTTP-API 酷Q cpk插件|[插件下载](https://github.com/ksust/HTTP--API/blob/master/plugin/com.ksust.qq.http-api.cpk)| 23 | |HTTP-API For QQLight|2.3.6|2.3.6|已发布|标准插件|HTTP-API QQLight 3.x插件|[插件下载](https://github.com/ksust/HTTP--API/blob/master/plugin/com.ksust.qq.http-api.ql.dll)| 24 | |HTTP-API For QY|2.3.6|2.3.6|已发布|标准插件|HTTP-API 契约多Q/单Q版|[插件下载](https://github.com/ksust/HTTP--API/blob/master/plugin/com.ksust.qq.http-api.qyk.dll)| 25 | |HTTP-API PHP SDK|2.3.0|2.3.0|已发布|标准SDK|PHP SDK|[PHP Demo](https://github.com/ksust/HTTP--API#php-demo)| 26 | |HTTP-API Java SDK|2.3.0|2.3.0|已发布(Maven)|标准SDK|Java SDK|[Java Demo](https://github.com/ksust/HTTP--API#java-demo)| 27 | |HTTP-API Python SDK|2.3.0|2.3.0|已发布(Pypi)|标准SDK|Python SDK|[Python Demo](https://github.com/ksust/HTTP--API#python-demo)| 28 | |HTTP-API NodeJS SDK|2.3.0|2.3.0|已发布(npm)|标准SDK|NodeJS SDK|[NodeJS Demo](https://github.com/ksust/HTTP--API#nodejs-demo)| 29 | |HTTP-API Cloud API|v1|2.3.0|已发布|标准|REST API|[在线文档](https://www.kancloud.cn/ksust/cloud-api/1150005)| 30 | |SDK Name|SDK版本|HTTP-API协议版本|完成状态...|来源,其他GITHub仓库|开发者备注|-| 31 | * **注:允许开发者发布自己的SDK(参考标准SDK中HTTP-API协议),若需要将SDK加入上述版本仓库,请联系admin@ksust.com** 32 | 33 | ------ 34 | ## 功能介绍 35 | --- 36 | 本插件主要包含三种工作机制,即**提交返回、主动推送、消息转发**,第一种为被动接受,后两种为主动操作,其中提交返回包括HTTP方式、webSocket方式,主动推送使用HTTP方式,消息转发目前仅公开使用HTTP方式,几种方式中HTTP提交返回最常用也最通用。 37 | 下面将简单介绍插件的几种工作方式,相关配置请结合插件进行(页底使用引导)。 38 | ### 提交返回 39 | 提交返回是最常用的一种工作方式,其原理为:机器人插件作为客户端(做网页请求),开发者开发WEB服务端;在工作时,插件将收到的消息(如QQ消息)经过协议封装后发送到开发者的WEB服务,该服务队发送过来的数据进行处理并返回给插件一些操作命令(如发送消息)。至此,一次简单的工作流程结束。 40 | 显然,该工作流程是被动的,开发者的WEB服务必须等待插件访问才能执行相关逻辑,在这种机制下某些操作不能完成。于是,本插件引入WEB回调,即WEB服务向插件发送回调指令(当然得插件先访问WEB服务),表达自己想要的数据(如获取群列表),插件再收到回调指令后会立即将相关数据封装(如群列表)后发送到WEB服务。 41 | 在具体开发中,常用的协议为HTTP,即在插件中填入http://...的地址,将程序部署到WEB服务器上;另外,为了更便于双向通信,同时提供了webSocket支持,只需在相关位置填入类似ws://...地址即可。 42 | ### 主动推送 43 | 主动推送是通过HTTP协议对机器人插件进行相关操作的一种方式。其原理为:插件作为HTTP服务器,开发者的应用(使用SDK)作为客户端,开发者可直接主动地操作插件(如主动发送消息、主动获取群列表等)。 44 | 此方式的相关操作均为主动操作,一般结合提交返回进行使用,并一般要求插件所在服务器/电脑有固定的公网IP(该条件限制太大,如果没有公网IP,下述消息转发是一种可用的替代方式)。 45 | ### 消息转发 46 | 消息转发解决了无公网IP以及不能主动操作的问题,原则上开发者不需要服务器也能获得提交返回、主动推送的功能,并且更加便捷。其原理为:除插件和开发者外,存在若干的转发服务器(转发服务器集群),这些服务器对开发者的操作以及插件产生的消息进行转发,以达到开发者与插件通信的目的。 47 | 目前本方式只开放HTTP方式,即只能完成上述主动推送的任务(但是不要求有公网IP)。开发者只需要直到机器人的QQ、授权码即可对机器人进行主动操作,任意一方均不要求有公网IP。 48 | ## 快速开始 49 | --- 50 | 以下将使用提供的PHP/Java/Python/NodeJS编程语言SDK开发Demo,以便开发者快速入门。 51 | 以下操作建立在配置好插件基础上,相关步骤参考请到跳转到页面底部了解。Demo中使用的SDK均可在本项目GITHUB上下载到,Demo适配的最低版本为2.2.2。 52 | 所示Demo包含本插件三大功能(提交返回[包含webSocket]、HTTP主动推送、消息转发推送),相关demo可在本项目demo中下载。 53 | 54 | ### PHP Demo 55 | >提交返回 56 | ``` 57 | getMsg();//插件发送过来的消息 64 | $sdk->sendPrivateMsg($msg['QQ'], '你发送了这样的消息:' . $msg['Msg']);//逻辑代码,向发送者回消息 65 | echo $sdk->toJsonString();//命令返回 66 | ``` 67 | >webSocket(结合使用workman) 68 | ``` 69 | count = 4; 81 | // Emitted when new connection come 82 | $ws_worker->onConnect = function ($connection) { 83 | echo "New connection\n"; 84 | }; 85 | // Emitted when data received 86 | $ws_worker->onMessage = function ($connection, $data) { 87 | $json = json_decode(urldecode(urldecode($data)), true); 88 | if (isset($json['type']) && $json['type'] == 'init') { 89 | $connection->send('{"type":"success"}'); 90 | } else { 91 | //消息操作 92 | $sdk = HTTPSDK::webSocket($data); 93 | $msg = $sdk->getMsg(); 94 | if ($msg['Msg'] == 'demo') { 95 | $sdk->sendPrivateMsg($msg['QQ'], '你发送了这样的消息:' . $msg['Msg']);//逻辑代码,向发送者回消息 96 | } 97 | //echo $sdk->toJsonString(); 98 | $connection->send($sdk->toJsonString()); 99 | } 100 | 101 | }; 102 | // Emitted when connection closed 103 | $ws_worker->onClose = function ($connection) { 104 | echo "Connection closed\n"; 105 | }; 106 | // Run worker 107 | Worker::runAll(); 108 | ``` 109 | >HTTP推送 110 | ``` 111 | getLoginQQ());//获取登录的QQ 117 | var_dump($push->sendPrivateMsg('QQ', 'hello~'));//向QQ发送消息 118 | var_dump($push->getFriendList());//获取好友列表 119 | 120 | ``` 121 | >消息转发 122 | ``` 123 | getLoginQQ());//获取登录的QQ 129 | var_dump($forward->sendPrivateMsg('QQ', 'hello~'));//向QQ发送消息 130 | var_dump($forward->getFriendList());//获取好友列表 131 | 132 | ``` 133 | ### Java Demo 134 | >Java Demo项目地址:https://github.com/ksust/HTTP-API-Java-Demo 135 | 136 | >SDK引入方式 137 | 138 | 1. **Maven引入** 139 | Java SDK已经提交Maven中央仓库,直接在pom文件中配置。在pom中加入如下代码即可: 140 | ``` 141 | 142 | 143 | com.ksust.qq 144 | http-api-sdk 145 | 2.3.0.RELEASE 146 | 147 | 148 | ``` 149 | 150 | 2. **jar包引入(需要手动解决依赖)** 151 | 可直接使用jar包(包名如:http-api-sdk-2.2.2.jar),在项目中下载即可,需要手动解决依赖。所需要的依赖及版本如下:(另外可以直接使用3提供的独立jar包,不用解决依赖问题) 152 | ``` 153 | 154 | 3.8.1 155 | 4.2.0.Final 156 | 1.16.10 157 | 1.2.31 158 | 159 | 160 | 161 | org.hibernate 162 | hibernate-validator 163 | ${validator.version} 164 | 165 | 166 | org.projectlombok 167 | lombok 168 | ${lombok.version} 169 | 170 | 171 | com.alibaba 172 | fastjson 173 | ${fastjson.version} 174 | 175 | 176 | com.squareup.okhttp3 177 | okhttp 178 | ${okttp.version} 179 | 180 | 181 | 182 | ``` 183 | 3. **jar包引入(包含所需依赖,独立jar包)** 184 | 包含后缀-with-dependencies的jar包中已经包含依赖,如http-api-sdk-2.2.2-jar-with-dependencies.jar 185 | 186 | >提交返回 187 | ``` 188 | //本样例基于SpringBoot,可运行的Demo在项目中可直接下载。主要代码如下: 189 | @RestController 190 | public class HTTPSDKDemo { 191 | @GetMapping("/test") 192 | public String test() { 193 | return "success"; 194 | } 195 | 196 | 197 | private void test(MessageGet msg) { 198 | System.out.println(JSON.toJSONString(msg)); 199 | } 200 | 201 | //提交返回演示:外部地址(插件中填的请求地址):http://yourIP:9999/ip 202 | @PostMapping(value = "/qq") 203 | public String qq(@RequestBody String data) throws Exception { 204 | //外部消息通过这个方法进入,请求地址即为 POST host:port/qq 205 | //开始演示:发送消息回复(点赞等),并且演示通过提交返回获取群列表 206 | HTTPSDK httpsdk = HTTPSDK.httpGet(data); 207 | //插件发来的消息 208 | MessageGet msg = httpsdk.getMsg(); 209 | test(msg); 210 | if (httpsdk.getMsg().getType() == TypeEnum.FRIEND.getCode() && !httpsdk.isCallback()) { 211 | //私聊消息 212 | //点赞、抖窗、回复 213 | httpsdk.sendLike(msg.getQQ(), 2); 214 | httpsdk.sendShake(msg.getQQ()); 215 | httpsdk.sendPrivateMsg(msg.getQQ(), "Hello,这里是HTTP-API演示程序,你发送的消息为:" + msg.getMsg() 216 | + "。我还给你点了两个赞哦~"); 217 | //发起获取群列表的请求(提交请求下不能立即得到),待下一次请求时携带消息 218 | httpsdk.getGroupList(); 219 | } 220 | 221 | //接收 WEB回调消息。 222 | if (httpsdk.isCallback()) { 223 | //打印群列表 224 | if (msg.getType() == TypeEnum.GET_GROUP_LIST.getCode()) { 225 | for (Group group : httpsdk.getGroupList()) { 226 | System.out.println(group.getGroupName() + "," + group.getGroupId()); 227 | } 228 | } 229 | } 230 | //必须!!!向插件回复消息并清空当前对象待发送消息 231 | return httpsdk.toJsonString(); 232 | } 233 | } 234 | ``` 235 | >webSocket 236 | ``` 237 | //与PHP版本类似,传入获取的字符串即可。取决于用什么框架,和上述提交返回使用方法基本相同,这里不再赘述。 238 | ``` 239 | >HTTP推送 240 | ``` 241 | //推送测试代码如下,插件中开启推送,并设置端口为8080 242 | public class HTTPSDKPushDemo { 243 | public static void main(String[] args) { 244 | //首先擦创建对象,支持加密。详情请查看文档 245 | HTTPSDK httpsdkPush = HTTPSDK.httpPush("http://127.0.0.1:8080", null, null); 246 | //引号中为测试QQ号 247 | String qq = "1402549575"; 248 | //发送消息 249 | httpsdkPush.sendPrivateMsg(qq, "Hello World[ksust,at_all:qq=all][ksust,music:name=明天]"); 250 | httpsdkPush.sendGroupMsg("244510218", "hello[ksust,at_all:qq=all][ksust,music:name=明天]"); 251 | //点赞 252 | httpsdkPush.sendLike(qq, 1); 253 | //查看点赞数量 254 | System.out.println(httpsdkPush.getLikeCount(qq)); 255 | //查看机器人当前状态 256 | System.out.println(JSON.toJSONString(httpsdkPush.getQQRobotInfo())); 257 | } 258 | } 259 | ``` 260 | >消息转发 261 | ``` 262 | //保证插件再2.2.2及以上并启动 263 | public class MsgForwardDemo { 264 | public static void main(String[] args) throws IOException { 265 | HTTPSDK forwardPush = HTTPSDK.msgForwardPush("QQ", "code");//输入QQ和授权码 266 | System.out.println(forwardPush.getLoginQQ()); 267 | System.out.println(forwardPush.sendPrivateMsg("QQ", "hello")); 268 | List groupMemberList = forwardPush.getGroupMemberList("群号"); 269 | for (GroupMember groupMember : groupMemberList) { 270 | System.out.println(groupMember.getName() + "," + groupMember.getQq()); 271 | } 272 | } 273 | } 274 | ``` 275 | ### Python Demo 276 | 277 | >安装(Python2/3):pip install http-api-sdk 278 | 279 | >提交返回 280 | ``` 281 | # 独立demo:https://github.com/ksust/http_api_django_demo 282 | ``` 283 | >webSocket 284 | ``` 285 | #原理同提交返回,取决于使用什么外部框架。 286 | ``` 287 | >HTTP推送 288 | ``` 289 | #!/usr/bin/env python 290 | # -*-coding:utf-8-*- 291 | """ 292 | Demo Push 293 | HTTP-API Python SDK(Python2、python3) 294 | * Created by PyCharm. 295 | * User: yugao 296 | * version 2.2.2 297 | * Note: HTTPSDK for Python(适用于版本2.2.2插件):用于解析插件消息、构造返回数据,以及HTTP推送(发起HTTP请求) 298 | * Contact: 开发者邮箱 admin@ksust.com 299 | * 安装:pip install http-api-sdk 300 | """ 301 | 302 | from httpapi.HTTPSDK import * 303 | 304 | if sys.version_info.major == 2: 305 | reload(sys) # python2请配置相应编码 306 | sys.setdefaultencoding('utf8') 307 | sys.setdefaultencoding('gb18030') 308 | 309 | push = HTTPSDK.httpPush("http://127.0.0.1:8080") 310 | print(push.getGroupList()) 311 | print(push.sendPrivdteMsg('QQ', '你好')) 312 | 313 | forward = HTTPSDK.msgForwardPush('QQ', '授权码') 314 | print(forward.getGroupList()) 315 | print(forward.getLoginQQ()) 316 | print(forward.sendPrivdteMsg('QQ', '你好')) 317 | print(forward.getQQRobotInfo()) 318 | 319 | ``` 320 | >消息转发 321 | ``` 322 | #上述推送中包含消息转发(forward) 323 | ``` 324 | 325 | ### NodeJS Demo 326 | >安装依赖:npm install http-api-sdk 327 | >引用包:如 const HTTPSDK = require('http-api-sdk'); 328 | 329 | >提交返回 330 | ``` 331 | /** 332 | * Demo 333 | * User: yugao 334 | * Date: 2019/2/27 335 | * version 2.2.2 336 | * Note: HTTPSDK for NodeJS(适用于版本2.2.2插件):用于解析插件消息、构造返回数据,以及HTTP推送(发起HTTP请求) 337 | * Contact: 开发者邮箱 admin@ksust.com 338 | * 安装SDK:npm install http-api-sdk 339 | */ 340 | const http = require('http'); 341 | const HTTPSDK = require('http-api-sdk'); 342 | const server = http.createServer((req, res) => { 343 | req.on('data', function (data) { 344 | let sdk = HTTPSDK.httpGet(data.toString()); 345 | //console.log(sdk.getMsg());//获取到的消息 346 | sdk.sendPrivateMsg(sdk.getMsg()['QQ'], '你发送了这样的消息:' + sdk.getMsg()['Msg']); 347 | sdk.getLoginQQ(); 348 | //回调演示,提交返回获取群列表、登录QQ等 349 | if (sdk.isCallback() && parseInt(sdk.getMsg()['Type']) === HTTPSDK.TYPE_GET_LOGIN_QQ) { 350 | console.log('Login QQ:' + sdk.getLoginQQ()); 351 | } 352 | res.end(sdk.toJsonString()); 353 | }); 354 | }); 355 | server.on('clientError', (err, socket) => { 356 | socket.end('HTTP/1.1 400 Bad Request\r\n\r\n'); 357 | }); 358 | server.listen(8000); 359 | ``` 360 | >webSocket() 361 | ``` 362 | //与PHP版本类似,传入获取的字符串即可。取决于用什么框架,和上述提交返回使用方法基本相同,这里不再赘述。 363 | ``` 364 | >HTTP推送 365 | ``` 366 | /** 367 | * Demo 368 | * User: yugao 369 | * Date: 2019/2/27 370 | * version 2.2.2 371 | * Note: HTTPSDK for NodeJS(适用于版本2.2.2插件):用于解析插件消息、构造返回数据,以及HTTP推送(发起HTTP请求) 372 | * Contact: 开发者邮箱 admin@ksust.com 373 | * 安装SDK:npm install http-api-sdk 374 | */ 375 | const HTTPSDK = require('http-api-sdk'); 376 | //推送演示,需要配置推送 377 | push = HTTPSDK.httpPush('http://127.0.0.1:8080') 378 | push.getGroupList().data(function (data) { 379 | console.log('push ' + data) 380 | }); 381 | push.getLoginQQ().data(function (data) { 382 | console.log('push ' + data) 383 | }); 384 | push.sendPrivateMsg('QQ', 'Hello').data(function (data) { 385 | console.log('push ' + data) 386 | }); 387 | //消息转发演示,插件在线即可用 388 | let forward = HTTPSDK.msgForwardPush('QQ', '授权码'); 389 | forward.getLoginQQ().data(function (data) { 390 | console.log('forward ' + data); 391 | }); 392 | forward.getGroupList().data(function (data) { 393 | console.log('forward ' + data); 394 | }); 395 | forward.sendPrivateMsg('QQ', 'Hello').data(function (data) { 396 | console.log('forward' + data) 397 | }); 398 | ``` 399 | >消息转发 400 | ``` 401 | //上述推送中包含消息转发(forward) 402 | ``` 403 | 404 | ------ 405 | 406 | ## SDK参考手册 407 | --- 408 | 409 | | 方法 | 说明 | 返回值 | 支持平台 | 参数1(从左到右) | 参数2 | 参数3 | 参数4 | 参数5 | 410 | | ----------- | ----------- | ----------- | ----------- | ----------- |----------- | ----------- | ----------- | ----------- | 411 | | httpGet(String msg) | 提交返回模型,PHP SDK无需传入参数 | HTTPSDK对象 | IR/CQ/QQLight |获取到的原始消息(RequestBody)|-|-|-|-| 412 | | webSocket(String msg) | 提交返回(webSocket)模型,传入获取到的原始消息 | HTTPSDK对象 | IR/CQ/QQLight |获取到的原始消息(RequestBody)|-|-|-|-| 413 | | httpPush(String URL, String key, String secret) | HTTP推送模型 | HTTPSDK对象 | IR/CQ/QQLight |推送地址及端口,如http://127.0.0.1:8888|验证key 为空或null则表示不加密|验证secret 为空或null则表示不加密|-|-| 414 | | msgForwardPush(String qq, String code)| 消息转发推送模型 | HTTPSDK对象 | IR/CQ/QQLight |机器人QQ|该机器人QQ的授权码,统一管理平台:http://work.ksust.com|-|-|-| 415 | | getMsg() | 获取接收到的消息(结构化) | JSON/MessageGet对象 | IR/CQ/QQLight |-|-|-|-|-| 416 | | isCallback() | 当前消息体是否为插件反馈(用于提交返回模型下获取群列表等) | boolean | IR/CQ/QQLight |-|-|-|-|-| 417 | | setCallbackSend(boolean callbackSend)| 是否在插件反馈情况下返回消息(提交返回),默认 | - | IR/CQ/QQLight |true/false|-|-|-|-| 418 | | toJsonString() | 构造返回的JSON String格式并清除当前MessageBackList。同时重置已发送消息(清空),仅针对于提交返回 | String | IR/CQ/QQLight |-|-|-|-|-| 419 | | sendPrivateMsg(String qq, String msg, int structureType, int subType) | 发送私聊消息,默认非卡片形式 | int | IR/CQ/QQLight |目标QQ,好友|消息内容|消息结构类型 0普通消息,1 XML消息,2 JSON消息默认0|XML、JSON消息发送方式下:0为普通(默认),1为匿名(需要群开启),默认0|-| 420 | | sendGroupMsg(String groupId, String msg, int structureType, int subType) | 发送群聊消息,默认非卡片形式 | int | IR/CQ/QQLight |群号|消息内容|消息结构类型 0普通消息,1 XML消息,2 JSON消息默认0|XML、JSON消息发送方式下:0为普通(默认),1为匿名(需要群开启),默认0|-| 421 | | sendDiscussMsg(String discuss, String msg, int structureType, int subType) | 发送讨论组消息,默认非卡片形式 | int | IR/CQ/QQLight |讨论组id|消息内容|消息结构类型 0普通消息,1 XML消息,2 JSON消息默认0|XML、JSON消息发送方式下:0为普通(默认),1为匿名(需要群开启),默认0|-| 422 | | sendLike(String qq, int count) | 点赞 | int | IR/CQ/QQLight |对象QQ|点赞数量,一人最多一天10|-|-|-| 423 | | sendShake(String qq) | 抖动窗口 | int | IR/CQ/QQLight |对象QQ|-|-|-|-| 424 | | setGroupBan(String groupId, String qq, int time) | 群禁言(管理) | int | IR/CQ/QQLight |群号|禁言QQ,为null则禁言全群|禁言时间,单位秒,至少10秒。0为解除禁言|-|-| 425 | | setGroupQuit(String groupId) | 主动退群 | int | IR/CQ/QQLight |群号|-|-|-|-| 426 | | setGroupKick(String groupId, String qq, boolean neverIn) | 踢人(管理) | int | IR/CQ/QQLight |群号|对象QQ|是否不允许再加群|-|-| 427 | | setGroupCard(String groupId, String qq, String card) | 设置群名片 | int | IR/CQ/QQLight |群号|对象QQ|群名片|-|-| 428 | | setGroupAdmin(String groupId, String qq, boolean become) | 设置管理员(群主) | int | IR/CQ/QQLight |群号|对象QQ|True为设置,false为取消|-|-| 429 | | handleGroupIn(String groupId, String qq, boolean agree, int type, String msg) | 处理加群事件,是否同意 | int | IR/CQ/QQLight|群号|对象QQ|是否同意加群|213请求入群 214我被邀请加入某群 215某人被邀请加入群 。为0则不管哪种|消息,当拒绝时发送的消息| 430 | | handleFriendAdd(String qq, boolean agree, String msg) | 是否同意被加好友 | int | IR/CQ/QQLight |对象QQ|是否同意|当拒绝时发送的消息|-|-| 431 | | addGroupNotice(String groupId, String title, String content) | 发群公告(管理) | int | IR |群号|公告标题|内容|-|-| 432 | | addGroupHomework(String groupId, String homewordName, String title, String content) | 发群作业(管理)。注意作业名和标题中不能含有#号 | int | IR |群号|作业名|标题|内容|-| 433 | | joinGroup(String groupId, String reason) | 主动申请加入群 | int | IR |群号|加群理由|-|-|-| 434 | | disGroupCreate(String disName, List qqList) | 创建讨论组 | String | IR |讨论组名。并作为创建后第一条消息发送(激活消息)|需要添加到讨论组的QQ号列表|-|-|-| 435 | | disGroupQuit(String disGroupId) | 退出讨论组 | int | IR/CQ/QQLight |讨论组ID|-|-|-|-| 436 | | disGroupKick(String disGroupId, List qqList) | 踢出讨论组 | int | IR |讨论组ID|踢提出的QQ号列表|-|-|-| 437 | | disGroupInvite(String disGrouId, List qqList) | 添加讨论组成员 | int | IR |讨论组号|欲添加的QQ号列表|-|-|-| 438 | | groupInvite(String groupId, String qq) | 邀请QQ入群(管理+群员) | int | IR |群号|QQ|-|-|-| 439 | | getStrangerInfo(String qq) | 获取陌生人信息 isCallback情况下返回有数据的,否则返回空对象 | Stranger/- | IR/CQ/QQLight |QQ|-|-|-|-| 440 | | getLoginQQ() | 获取当前登陆的QQ isCallback情况下返回有数据的,否则返回空对象 | int/- | IR/CQ/QQLight |-|-|-|-|-| 441 | | getGroupList() | 获取当前QQ群列表,JSON字符串 isCallback情况下返回有数据的,否则返回空对象 | JSON字符串/- | IR/CQ/QQLight |-|-|-|-|-| 442 | | getFriendList() | 获取好友列表 isCallback情况下返回有数据的,否则返回空对象 | 好友列表/- | IR/QQLight |-|-|-|-|-| 443 | | getGroupMemberList(String groupId) | 获取群成员列表 isCallback情况下返回有数据的,否则返回空对象 | 群成员列表/- | IR/CQ/QQLight |群号|-|-|-|-| 444 | | getGroupNotice(String groupId) | 获取群公告 isCallback情况下返回有数据的,否则返回空对象 | Notice/- | IR |群号|-|-|-|-| 445 | | getLikeCount(String qq) | 获取对象QQ赞数量 isCallback情况下返回有数据的,否则返回空对象 | int/- | IR/QQLight |对象QQ|-|-|-|-| 446 | | getDisGroupList() | 获取讨论组列表(IRQQ框架获取为空) isCallback情况下返回有数据的,否则返回空对象 | DisGroup/- | IR |-|-|-|-|-| 447 | | getQQLevel(String qq) | 获取QQ等级 | int | IR |QQ|-|-|-|-| 448 | | getGroupMemberCard(String groupId, String qq) | 获取群成员名片 | 群名片 | IR |群号|QQ|-|-|-| 449 | | getQQIsOline(String qq) | 查询QQ是否在线 | 是否在线 | IR |QQ|-|-|-|-| 450 | | getQQIsFriend(String qq) | 查询QQ是否好友 | 是否好友 | IR |QQ|-|-|-|-| 451 | | getQQRobotInfo() | 获取当前QQ机器人状态信息(如是否在线) | 结构信息 | IR/CQ/QQLight |-|-|-|-|-| 452 | | setInputStatus(String qq) | 置正在输入 状态,发送消息撤销 | int | IR |QQ|-|-|-|-| 453 | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 454 | 455 | 456 | ------ 457 | 458 | ## 事件ID及标签 459 | --- 460 | 461 | ### 事件ID 462 | 其中值>20000的为操作代码,其余的为事件ID。 463 | 464 | | 事件名 | 值 | 说明 | 支持平台 | 备注 | 465 | | ----------- |----------- | ----------- | ----------- | ----------- | 466 | | TYPE_FRIEND_TEMP | 0 | 在线状态临时会话(Pro版可用)| IR | - | 467 | | TYPE_FRIEND | 1 | 好友消息,发送私聊消息| IR/CQ/QQLight | - | 468 | | TYPE_GROUP | 2 | 群消息,发送群消息| IR/CQ/QQLight | - | 469 | | TYPE_DISCUSS | 3 | 讨论组消息,发送讨论组消息| IR/CQ/QQLight | - | 470 | | TYPE_GROUP_TEMP | 4 | 群临时会话| IR | - | 471 | | TYPE_DISCUSS_TEMP | 5 | 讨论组临时会话| IR | - | 472 | | TYPE_ACCOUNT | 6 | 收到财付通转账| IR/QQLight | - | 473 | | TYPE_FRIEND_VERIFY_BACK | 7 | 好友验证回复会话消息(Pro版可用)| IR | - | 474 | | TYPE_HANDLE_AGREE | 10 | 请求处理_同意| IR/CQ/QQLight | - | 475 | | TYPE_HANDLE_REJECT | 20 | 请求处理_拒绝| IR/CQ/QQLight | - | 476 | | TYPE_HANDLE_IGNORE | 30 | 请求处理_忽略| IR | - | 477 | | TYPE_FRIEND_ADDED_SINGLE | 100 | 被单项添加为好友| IR | - | 478 | | TYPE_FRIEND_ADDED | 101 | 某人请求加为好友| IR/CQ/QQLight | - | 479 | | TYPE_FRIEND_ADDED_AGREED | 102 | 被同意加为好友| IR/CQ/QQLight | - | 480 | | TYPE_FRIEND_ADDED_REJECTED | 103 | 被拒绝加为好友| IR | - | 481 | | TYPE_FRIEND_DELETED | 104 | 被删除好友| IR | - | 482 | | TYPE_FRIEND_FILE_OFFLINE | 105 | 收到好友离线文件(Pro版可用)| IR | - | 483 | | TYPE_FRIEND_SIGNATURE_CHANGE | 106 | 好友签名变更| IR | - | 484 | | TYPE_FRIEND_SAY_COMMENT | 107 | 说说被某人评论| IR | - | 485 | | TYPE_GROUP_FILE_RECV | 218 | 收到群文件| IR/CQ | - | 486 | | TYPE_GROUP_IN_WHO_REQUEST | 213 | 某人请求入群| IR/CQ/QQLight | - | 487 | | TYPE_GROUP_IN_ME_INVITED | 214 | 被邀请加入群| IR/CQ/QQLight | - | 488 | | TYPE_GROUP_IN_ME_AGREED | 220 | 被批准入群| IR | - | 489 | | TYPE_GROUP_IN_ME_REJECTED | 221 | 被拒绝入群| IR | - | 490 | | TYPE_GROUP_IN_WHO_INVITED | 215 | 某人被邀请加入群| IR | - | 491 | | TYPE_GROUP_IN_WHO_INVITED_HAS | 219 | 某人已被邀请加入群(群主或管理员邀请成员加群或开启了群成员100以内无需审核或无需审核直接进群,被邀请人同意进群后才会触发)| IR/CQ/QQLight | - | 492 | | TYPE_GROUP_IN_WHO_AGREED | 212 | 某人被批准加入了群| IR/CQ/QQLight | - | 493 | | TYPE_GROUP_QUIT_WHO | 201 | 某人退出群| IR/CQ/QQLight | - | 494 | | TYPE_GROUP_QUITED_WHO | 202 | 某人被管理移除群| IR/CQ/QQLight | - | 495 | | TYPE_GROUP_INVALID | 216 | 某群被解散| IR | - | 496 | | TYPE_GROUP_ADMIN_WHO_BECOME | 210 | 某人成为管理| IR/CQ/QQLight | - | 497 | | TYPE_GROUP_ADMIN_WHO_INVALID | 211 | 某人被取消管理| IR/CQ/QQLight | - | 498 | | TYPE_GROUP_BANED | 203 | 对象被禁言| IR | - | 499 | | TYPE_GROUP_BANED_INVALID | 204 | 对象被解除禁言| IR | - | 500 | | TYPE_GROUP_BANED_ALL | 205 | 开启全群禁言| IR | - | 501 | | TYPE_GROUP_BANED_ALL_INVALID | 206 | 关闭全群禁言| IR | - | 502 | | TYPE_GROUP_ANONYMOUS_OPEN | 207 | 开启匿名聊天| IR | - | 503 | | TYPE_GROUP_ANONYMOUS_CLOSE | 208 | 关闭匿名聊天| IR | - | 504 | | TYPE_GROUP_NOTICE_CHANGE | 209 | 群公告变动| IR | - | 505 | | TYPE_GROUP_CARD_CHANGE | 217 | 群名片变动| IR | - | 506 | | TYPE_SEND_LIKE | 20001 | 点赞| IR/CQ/QQLight | 操作类型 | 507 | | TYPE_SEND_SHAKE | 20002 | 窗口抖动| I/CQ | - | 508 | | TYPE_GROUP_BAN | 20011 | 群禁言(管理)| IR/CQ/QQLight | - | 509 | | TYPE_GROUP_QUIT | 20012 | 主动退群| IR/CQ/QQLight | - | 510 | | TYPE_GROUP_KICK | 20013 | 踢群成员(管理)| IR/CQ/QQLight | - | 511 | | TYPE_GROUP_SET_CARD | 20021 | 设置群名片(管理)| IR/CQ/QQLight | - | 512 | | TYPE_GROUP_SET_ADMIN | 20022 | 设置群管理(群主)| IR/CQ/QQLight | - | 513 | | TYPE_GROUP_HANDLE_GROUP_IN | 20023 | 入群处理(某人请求入群、我被邀请入群、某人被邀请入群)| IR/CQ/QQLight | - | 514 | | TYPE_FRIEND_HANDLE_FRIEND_ADD | 20024 | 加好友处理(是否同意被加好友)| IR/CQ/QQLight | - | 515 | | TYPE_GROUP_ADD_NOTICE | 20031 | 发群公告| IR | - | 516 | | TYPE_GROUP_ADD_HOMEWORK | 20032 | 发群作业| IR | - | 517 | | TYPE_GROUP_JOIN | 20033 | 主动申请加入群| IR | - | 518 | | TYPE_DIS_CREATE | 20041 | 创建讨论组,返回讨论组ID(并且对外部接口支持直接根据好友列表创建讨论组)| IR | - | 519 | | TYPE_DIS_INVITE | 20042 | 邀请加入某讨论组,多个用#隔开| IR | - | 520 | | TYPE_DIS_KICK | 20043 | 踢出讨论组成员| IR | - | 521 | | TYPE_DIS_QUIT | 20044 | 退出讨论组| IR | - | 522 | | TYPE_GROUP_INVITE | 20051 | 邀请QQ入群(管理+普通成员)| IR | - | 523 | | TYPE_GET_LOGIN_QQ | 20101 | 获取当前QQ| IR/CQ/QQLight | - | 524 | | TYPE_GET_STRANGER_INFO | 20102 | 获取陌生人信息,JSON,昵称,性别,年龄,签名| IR/CQ/QQLight | - | 525 | | TYPE_GET_GROUP_LIST | 20103 | 获取当前QQ群列表,JSON| IR/CQ/QQLight | - | 526 | | TYPE_GET_GROUP_MEMBER_LIST | 20104 | 获取指定群成员列表,JSON| IR/CQ/QQLight | - | 527 | | TYPE_GET_FRIEND_LIST | 20105 | 获取好友列表,JSON| IR/QQLight | - | 528 | | TYPE_GET_GROUP_NOTICE | 20106 | 获取群公告列表,JSON| IR | - | 529 | | TYPE_GET_DIS_LIST | 20107 | 获取讨论组列表| IR | - | 530 | | TYPE_GET_QQ_LEVEL | 20111 | 获取QQ等级| IR | - | 531 | | TYPE_GET_GROUP_MEMBER_CARD | 20112 | 获取群成员名片| IR | - | 532 | | TYPE_GET_QQ_ONLINE_STATUS | 20113 | 查询QQ是否在线| IR | - | 533 | | TYPE_GET_QQ_IS_FRIEND | 20114 | 查询QQ是否好友| IR | - | 534 | | TYPE_GET_QQ_ROBOT_INFO | 20115 | 获取机器人状态信息,JSON| IR/CQ/QQLight | - | 535 | | TYPE_LIKE_COUNT_GET | 20201 | 获取目标对象赞数目| IR | - | 536 | | TYPE_SET_INPUT_STATUS | 20301 | 置正在输入状态(发送消息取消)| IR | - | 537 | | TYPE_TIMER_SEND | 30001 | 定时任务提交类型| IR/CQ/QQLight | - | 538 | | SUBTYPE_CALLBACK_SEND | 10001 | 提交返回有反馈时,更改原数据中的subtype和msg(数据),向返回地址发送反馈 539 | | -- | -- | -- | - | - | 540 | 541 | ### 消息标签 542 | **消息标签用于特殊消息发送,例如卡片、@全体成员、音乐标签等**,目前支持的标签如下: 543 | 544 | | 标签 | 说明 | 举例 | 支持平台 | 备注 | 545 | | ----------- |----------- | ----------- | ----------- |----------- | 546 | | [ksust,music:name=歌曲名] | 多选音乐卡片,传入歌名 | [ksust,music:name=明天] | IR | - | 547 | | [ksust,link:url=链接网址,title=标题文字,content=内容文字,pic=图片链接] | 简单图文(卡片)| - | IR/CQ(Pro) | - | 548 | | [ksust,link2:url=链接网址,title=标题文字,content=内容文字,pic=图片链接,bcontent=内容2文字,bpic=大图链接] | 简单图文,加大图和长文本 |- | IR | - | 549 | | [ksust,at:qq=qq] | 统一标签,艾特某人。qq=all 或 qq=QQ号码。可跨平台兼容 | [ksust,at:qq=all] |IR/CQ/QQLight/QY | - | 550 | | [ksust,image:pic=图片地址] | CQ、IRQQ统一网络图片标签,pic为网络图片地址,可跨平台兼容 | - | IR/CQ(Pro)/QQLight/QY | - | 551 | | [ksust,at_all:qq=all] | 逐个@全体成员,避免@全体成员限制 | 固定用法 [ksust,at_all:qq=all] | IR/CQ/QQLight/QY | - | 552 | | [ksust,voice:url=mp3或amr语音文件网络地址] | 发送语音消息 | [ksust,voice:url=http://hao.haolingsheng.com/ring/000/993/d915a1c149bb3076a32dfdab923f8c21.mp3] | QY | - | 553 | | [ksust,qqlight_group_file_forward:src=,dst_group=,guid=] | 转发好友/群文件 | [ksust,qqlight_group_file_forward:src=好友QQ或群号,dst_group=目标群,guid=文件GUID] | QQLight | - | 554 | | [ksust,qy_group_file:group=,group_path=,file_url=,name=] | 上传群文件 | [ksust,qy_group_file:group=目标群号,group_path=群文件路径(根目录为/),file_url=文件绝对链接(http://),name=文件名称(如a.zip)] | QY | - | 555 | ### 数据结构 556 | 简单列出必要的几种数据结构(使用**JSON格式**描述),其余请开发者在开发中查看SDK或者打印。 557 | >提交返回-插件提交-数据结构(接口getMsg()返回值) 558 | ``` 559 | { 560 | Myqq:机器人QQ, 561 | Type:"消息类型,举例:【详看消息类型】 -1 未定义事件 1 好友信息 2,群信息 3,讨论组信息 4,群临时会话 5,讨论组临时会话 6,财付通转账, 562 | SubType:接收财付通转账时 1为好友 2为群临时会话 3为讨论组临时会话 有人请求入群时,不良成员这里为1, 563 | From:此消息的来源,如:群号、讨论组ID、临时会话QQ、好友QQ, 564 | Group:来源群号,若无则为空, 565 | Discuss:来源讨论组,若无则为空, 566 | QQ:主动发送这条消息的QQ,踢人时为踢人管理员QQ, 567 | ObjectQQ:被动触发的QQ,如某人被踢出群,则此参数为被踢出人QQ, 568 | Msg:消息文本内容(当消息为JSON、XML时为相应内容)。消息反馈时为消息反馈文本(如取群列表), 569 | ID:消息id,用于识别消息【如异步处理时】、撤回等,构成:消息序号-消息ID, 570 | Data:{ 571 | //携带数据,如当消息为转账消息时,则有相关属性。以下举例转账消息 572 | "Comments": "接收到转账时留言", 573 | "Money": "接收到转账时金额(数字)", 574 | "Number": "接收到转账时订单号" 575 | } 576 | } 577 | ``` 578 | >提交返回-返回处理-数据结构(WEB返回) 579 | ``` 580 | { 581 | 582 | data:[ 583 | { 584 | ID:唯一标识,UUID, 585 | Type:发送消息类型【具体查看SDK】, 1 好友信息 2,群信息 3,讨论组信息 4,群临时会话 5,讨论组临时会话 ...,20001 点赞,20002 窗口抖动,20011 群禁言(管理),20012 退群,20013 踢群成员(管理),20021 设置群名片(管理),20022 设置群管理(群主),20023 入群处理(某人请求入群、我被邀请入群、某人被邀请入群),20024 加好友处理(是否同意被加好友),20031 发公告,20032 发作业 等 586 | SubType:子类型,0普通,1匿名(需要群开启,默认0), 587 | StructureType:消息结构类型,0为普通文本消息(默认)、1为XML消息、2为JSON消息, 588 | Group:操作或发送的群号或者讨论组号, 589 | QQ:操作或者发送的QQ, 590 | Msg:文本消息【标签等】,当发送类型为JSON、XML时为相应文本,禁言时为分钟数【分钟】, 591 | Send:是否开启同步发送(1为开启同步发送【测试】,0为不开启【默认】), 592 | Data:附加数据,用于特定操作等(文本型) 593 | } , 594 | { 595 | ... 596 | } 597 | ] 598 | } 599 | ``` 600 | >推送(转发)-发送-数据结构 601 | ``` 602 | { 603 | time:验证的时间戳, 604 | verify:验证字符串, 605 | data:[ //暂时仅允许一个成员 606 | { 607 | ID:唯一标识,UUID, 608 | Type:发送消息类型, 1 好友信息 2,群信息 3,讨论组信息 4,群临时会话 5,讨论组临时会话 ...,20001 点赞,20002 窗口抖动,20011 群禁言(管理),20012 退群,20013 踢群成员(管理),20021 设置群名片(管理),20022 设置群管理(群主),20023 入群处理(某人请求入群、我被邀请入群、某人被邀请入群),20024 加好友处理(是否同意被加好友),20031 发公告,20032 发作业 609 | SubType:子类型,0普通,1匿名(需要群开启,默认0), 610 | StructureType:消息结构类型,0为普通文本消息(默认)、1为XML消息、2为JSON消息, 611 | Group:操作或发送的群号或者讨论组号, 612 | QQ:操作或者发送的QQ, 613 | Msg:文本消息【标签等】,当发送类型为JSON、XML时为相应文本,禁言时为分钟数【分钟】, 614 | Send:是否开启同步发送(1为开启同步发送【测试】,0为不开启【默认】), 615 | Data:附加数据,用于特定操作等(文本型) 616 | } 617 | ] 618 | } 619 | ``` 620 | 621 | ------ 622 | 623 | ## 插件界面及使用引导 624 | --- 625 | 626 | ### 用户使用流程引导 627 | 对于使用本插件的用户来说,除了第一次配置插件外,几乎所有操作均在管理平台上进行(包括安装应用、查看机器人状态等)。 628 | 对于新用户,步骤如下: 629 | >1.注册平台账户(用于线上管理、安装) 630 | * 至管理平台注册用户(用户名最好为英文)[http://work.ksust.com](http://work.ksust.com) 631 | * 加入用户QQ群(用于应用审核等):(QQ群,用户加入)537419179 632 | >2.安装并启用插件(QQLight、酷Q、契约) 633 | * 首先你需要至少登录成功一个机器人QQ。 634 | * 直接下载相应插件(本页开始的版本分布表中对应下载)。 635 | * 如果你是新用户,你可以再次直接下载已经安装好HTTP-API的机器人框架。下载地址:[QQLight-HTTP-API](http://)、[CQ-HTTP-API](http://)、[QY-HTTP-API](http://) 636 | >3.重启机器人框架 637 | * 上一步过后,请记得重启机器人,以获取授权码、载入新配置等。 638 | >4.打开插件设置进行配置 639 | * 上一步重启机器人并至少登录成功一个机器人QQ后,打开HTTP-API设置,按下图顺序操作;绑定时输入你在平台注册的**用户名和密码**。 640 | ![开启服务](./resources/setting1.png) 641 | ![绑定账号](./resources/setting2.png) 642 | ![保存配置](./resources/setting3.png) 643 | * 插件配置完成后,登录管理平台,进入授权管理,此时可以看到你绑定的机器人QQ。 644 | ![我的授权](./resources/verifyList.png) 645 | >5.主人QQ绑定 646 | * 在平台右上角选择绑定主人,选择主人QQ,输入你加入用户QQ群的QQ号(机器人不用加群),点击提交。 647 | ![绑定主人](./resources/bindMaster.png) 648 | * 在用户QQ群中发送 验证主人 即可成功绑定。群内发送帮助可获取帮助信息。 649 | >6.安装应用及应用审核 650 | * 进入应用商店,点击一款应用进行在线安装。 651 | ![应用商店](./resources/appList.png) 652 | ![应用安装1](./resources/appInstall1.png) 653 | ![应用安装2](./resources/appInstall2.png) 654 | * 在用户QQ群中发送 应用审核 即可自动审核应用。 655 | ![我的应用](./resources/myAppList.png) 656 | * 等待1分钟或者进入插件设置,点击更新配置后保存,即可看到安装的应用已经成功运行。 657 | ![应用测试](./resources/appTest.png) 658 | >以上流程为新用户完整流程,尽量描述详细,具体执行过程1-2分钟即可完成;对于老用户,则直接绑定平台账号即可。 659 | 660 | ### 开发者相关配置 661 | 对于开发者,主要包含开发、发布两个流程。下面主要介绍开发过程中的相关配置,更多请加入开发群了解,开发群也有免费视频培训。 662 | >开启开发者模式 663 | * 开启开发者模式 664 | >提交返回配置 665 | * 提交返回一般只需填提交URL即可,URL填HTTP协议地址(如[http://127.0.0.1](http://127.0.0.1)),或者填webSocket地址(如ws://127.0.0.1:2346),点击测试即可查看测试结果(测试发起的GET请求)。 666 | >主动推送配置 667 | * 主动提交一般只需开启服务,配置监听端口即可。 668 | >定时任务配置 669 | * 定时任务只需开启服务并添加任务URL(只能是[http://XXX](http://XXX)),填写任务间隔(秒)即可,任务间隔最小为1秒。 670 | >发布应用到平台 671 | * 应用发布是针对已经认证开发者的开发者。可以在平台上发布开发的应用,用户可很方便地通过线上安装运行你的应用,另外开发者也可以通过这种方式获得收入(应用安装收费)。详情请加入开发群。 672 | ------ 673 | 如果你觉得本项目还不错,可以捐助本项目,你的捐赠将会使作者更具开发/更新的信心,同时也能推进本项目的发展(在捐助的时候可以备注您的QQ或微信): 674 | ![捐助方式](./resources/donate.png) 675 | 交流群:(QQ群,用户加入)537419179 676 | 开发群:(QQ群,开发者加入)598629636 677 | **管理平台:http://work.ksust.com** 678 | 679 | 680 | 681 | -------------------------------------------------------------------------------- /SDK/Java/http-api-sdk-2.3.0-jar-with-dependencies.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ksust/HTTP--API/9427015bf8263770c5eb4dd45b7009dc22eb9188/SDK/Java/http-api-sdk-2.3.0-jar-with-dependencies.jar -------------------------------------------------------------------------------- /SDK/Java/http-api-sdk-2.3.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ksust/HTTP--API/9427015bf8263770c5eb4dd45b7009dc22eb9188/SDK/Java/http-api-sdk-2.3.0.jar -------------------------------------------------------------------------------- /SDK/NodeJS/install: -------------------------------------------------------------------------------- 1 | npm install http-api-sdk -------------------------------------------------------------------------------- /SDK/PHP/HTTPSDK.php: -------------------------------------------------------------------------------- 1 | []];//返回给插件的数据 124 | private $returnDataCell = [//返回数据中的data单元 125 | 'ID' => '-1',//消息唯一标识,ID,可使用毫秒时间戳、UUID等 126 | 'Type' => -1,//发送消息类型, 1 好友信息 2,群信息 3,讨论组信息 4,群临时会话 5,讨论组临时会话 ...,20001 群禁言, 127 | 'SubType' => 0,//0普通,1匿名(需要群开启,默认0) 128 | 'StructureType' => 0,//消息结构类型,0为普通文本消息(默认)、1为XML消息、2为JSON消息 129 | 'Group' => '',//操作或发送的群号或者讨论组号 130 | 'QQ' => '',//操作或者发送的QQ 131 | 'Msg' => '',//文本消息【标签等】,当发送类型为JSON、XML时为相应文本,禁言时为分钟数【分钟】 132 | 'Send' => 0,//是否开启同步发送(1为开启同步发送【测试】,0为不开启【默认】) 133 | 'Data' => ''//附加数据,用于特定操作等(文本型 134 | ]; 135 | 136 | /** 137 | * http提交返回的构建方法,一般使用该方法 138 | * @return HTTPSDK 139 | */ 140 | public static function httpGet() 141 | { 142 | $sdk = new HTTPSDK(); 143 | $sdk->SDKType = 0; 144 | return $sdk; 145 | } 146 | 147 | /** 148 | * webSocket服务端模式下用于解析插件消息,传入接收到的消息即可(若有粘包等情况,请先以换行\r\n分开) 149 | * @param string $msg 接收到的消息(若有粘包等情况,请先以换行\r\n分开) 150 | * @return HTTPSDK 151 | */ 152 | public static function webSocket($msg) 153 | { 154 | $sdk = new HTTPSDK($msg); 155 | $sdk->SDKType = 1; 156 | return $sdk; 157 | } 158 | 159 | /** 160 | * HTTP推送,HTTPSDKPush 161 | * @param string $URL 推送地址及端口,如http://127.0.0.1:8888 162 | * @param string $serverKey 验证key,默认123 163 | * @param string $serverSecret 验证secret,默认456 164 | * @param boolean $serverVerify 是否开启验证,默认开启 165 | * @return HTTPSDK 166 | */ 167 | public static function httpPush($URL, $serverKey = null, $serverSecret = null) 168 | { 169 | $sdk = new HTTPSDK(); 170 | $sdk->SDKType = 2; 171 | $sdk->serverURL = $URL; 172 | $sdk->serverKey = $serverKey; 173 | $sdk->serverSecret = $serverSecret; 174 | return $sdk; 175 | } 176 | 177 | /** 178 | * 消息转发推送,消息转发模式(http协议)。需要在到平台免费申请授权码:http://work.ksust.com 179 | * @param string $qq 机器人QQ 180 | * @param string $code 该机器人QQ的授权码,统一管理平台:http://work.ksust.com 181 | * @return HTTPSDK 182 | */ 183 | public static function msgForwardPush($qq, $code) 184 | { 185 | $sdk = new HTTPSDK(); 186 | $sdk->SDKType = 3; 187 | $sdk->myqq = $qq; 188 | $sdk->code = $code; 189 | list($sdk->url, $sdk->token) = self::getMsgForwardPushToken($qq, $code); 190 | return $sdk; 191 | } 192 | 193 | /** 194 | * 获取消息转发请求的token 195 | * @param string $qq 机器人QQ 196 | * @param string $code 该机器人QQ的授权码,统一管理平台:http://work.ksust.com 197 | * @return array url,token 198 | */ 199 | private static function getMsgForwardPushToken($qq, $code) 200 | { 201 | 202 | //初始化,获取token(Redis缓存或本地文件缓存,远程获取) 203 | $token = ''; 204 | $url = 'http://127.0.0.1:2047'; 205 | $tokenKey = 'msgForwardToken-' . $qq; 206 | $urlKey = 'msgForwardURL-' . $qq; 207 | if (class_exists('Redis')) { 208 | //默认使用Redis,否则使用文件缓存 209 | $redis = new Redis(); 210 | $redis->connect('127.0.0.1', 6379); 211 | if ($redis->exists($tokenKey) && $redis->exists($urlKey)) { 212 | $token = $redis->get($tokenKey); 213 | $url = $redis->get($urlKey); 214 | } else { 215 | $verifyData = self::sendMsgForwardPush('http://qq.ksust.com/api/tool.php?func=get_server_dst' 216 | , 3, 'user-' . $qq, 'plugin-' . $qq, $code); 217 | $verifyData = json_decode($verifyData, true); 218 | if ($verifyData['status'] == 1) { 219 | $token = $verifyData['data']['token']; 220 | $url = 'http://' . $verifyData['data']['ip'] . ':' . $verifyData['data']['http-port'] . '/api/user/request'; 221 | $redis->set($tokenKey, $token); 222 | $redis->set($urlKey, $urlKey); 223 | } 224 | } 225 | } else { 226 | //文件缓存,创建./temp目录 227 | $tempDir = self::$TEMP_DIR; 228 | if (!is_dir($tempDir)) { 229 | mkdir($tempDir, 777, true); 230 | } 231 | if (time() - filemtime($tempDir . $tokenKey) <= 60 * 60 * 24 232 | && time() - filemtime($tempDir . $urlKey) <= 60 * 60 * 24 233 | && strlen(file_get_contents($tempDir . $tokenKey)) > 5 234 | ) { 235 | $token = file_get_contents($tempDir . $tokenKey); 236 | $url = file_get_contents($tempDir . $urlKey); 237 | } else { 238 | $verifyData = self::sendMsgForwardPush('http://qq.ksust.com/api/tool.php?func=get_server_dst' 239 | , 3, 'user-' . $qq, 'plugin-' . $qq, $code); 240 | $verifyData = json_decode($verifyData, true); 241 | if ($verifyData['status'] == 1) { 242 | $token = $verifyData['data']['token']; 243 | $url = 'http://' . $verifyData['data']['ip'] . ':' . $verifyData['data']['http-port'] . '/api/user/request'; 244 | file_put_contents($tempDir . $tokenKey, $token); 245 | file_put_contents($tempDir . $urlKey, $url); 246 | } 247 | } 248 | } 249 | return [$url, $token]; 250 | } 251 | 252 | /** 253 | * 消息转发请求协议封装 254 | * @param string $url 255 | * @param string $code 256 | * @param string $src 257 | * @param string $dst 258 | * @param string $token 259 | * @param array $dataIn 260 | * @return string 请求结果 261 | */ 262 | private static function sendMsgForwardPush($url, $code, $src, $dst, $token, $dataIn = array()) 263 | { 264 | $data['id'] = time(); 265 | $data['code'] = $code; 266 | $data['src'] = $src; 267 | $data['dst'] = $dst; 268 | $data['time'] = time(); 269 | $data['token'] = $token; 270 | $data['data'] = json_encode($dataIn); 271 | //请求 272 | $conn = curl_init($url); 273 | curl_setopt($conn, CURLOPT_RETURNTRANSFER, 1);//参数1 不显示 274 | curl_setopt($conn, CURLOPT_POST, 1); 275 | curl_setopt($conn, CURLOPT_POSTFIELDS, json_encode($data)); 276 | curl_setopt($conn, CURLOPT_HTTPHEADER, ["Content-Type: application/json; charset=utf-8"]); 277 | $get = curl_exec($conn); 278 | return $get; 279 | } 280 | 281 | /** 282 | * 解析客户端传来的消息 283 | * HttpApiLocalSDK constructor. 284 | * @param string $msg 解析的消息(JSON),http提交返回使用默认参数,ws等需要解析的消息则传入消息字符串 285 | */ 286 | private function __construct($msg = '') 287 | { 288 | $this->parseMsg($msg); 289 | } 290 | 291 | /** 292 | * 获取并解析客户端传来的消息 293 | * @param string $msg 解析的消息(JSON),为空则从PHP输入流中获取 294 | */ 295 | private function parseMsg($msg) 296 | { 297 | if ($msg == '') 298 | $this->msg = json_decode(urldecode(urldecode((file_get_contents("php://input")))), true); 299 | else 300 | $this->msg = json_decode(urldecode(urldecode($msg)), true); 301 | } 302 | 303 | /** 304 | * 添加功能,原始方法:为了保持一致,此处参数使用大驼峰命名 305 | * @param $Type 306 | * @param int $SubType 307 | * @param int $StructureType 308 | * @param string $Group 309 | * @param string $QQ 310 | * @param string $Msg 311 | * @param string $Data 312 | * @param int $Send 313 | * @return mixed 314 | */ 315 | private function addDataCell($Type, $SubType = 0, $StructureType = 0, $Group = '', $QQ = '', $Msg = '', $Data = '', $Send = 0) 316 | { 317 | $data = $this->returnDataCell; 318 | $data['ID'] = md5(mt_rand(-time(), time()) . time() . $this->toJsonString()); 319 | $data['Type'] = $Type; 320 | $data['SubType'] = $SubType; 321 | $data['StructureType'] = $StructureType; 322 | $data['Group'] = $Group; 323 | $data['QQ'] = $QQ; 324 | $data['Msg'] = $Msg; 325 | $data['Data'] = $Data; 326 | $data['Send'] = $Send; 327 | array_push($this->returnData['data'], $data); 328 | //分类型确定调用方式 329 | if ($this->SDKType == 2) { 330 | $pushReturn = $this->sendPushData(); 331 | $pushReturnJson = json_decode($pushReturn, true); 332 | //若解析失败,则返回原文本;否则返回解析后的array 333 | return $pushReturnJson == null ? $pushReturn : $pushReturnJson; 334 | } else if ($this->SDKType == 3) { 335 | //消息转发 336 | $sendData = $this->returnData['data'][0]; 337 | $this->returnData = ['data' => []];//发送之后清空数据,以免影响下一次发送** 338 | $forwardReturnJson = json_decode(self::sendMsgForwardPush($this->url, 3, 'user-' . $this->myqq, 'plugin-' . $this->myqq 339 | , $this->token, $sendData), true); 340 | if ($forwardReturnJson['code'] == -1) { 341 | //清空缓存 342 | file_put_contents(self::$TEMP_DIR . 'msgForwardToken-' . $this->myqq, ''); 343 | file_put_contents(self::$TEMP_DIR . 'msgForwardURL-' . $this->myqq, ''); 344 | } 345 | return $forwardReturnJson; 346 | 347 | } 348 | //非推送模式下返回null 349 | return null; 350 | } 351 | 352 | /** 353 | * httpPush:发送消息与获得结果 354 | * @return mixed 返回json数据 355 | */ 356 | private function sendPushData() 357 | { 358 | $url = $this->serverURL; 359 | $verify = []; 360 | $verify['time'] = time(); 361 | $verify['verify'] = md5($this->serverKey . $verify['time'] . $this->serverSecret); 362 | $send_arr = $verify + $this->returnData;//加入加密信息。"+",若两个数组存在相同的key,前一会覆盖后一 363 | $this->returnData = ['data' => []];//发送之后清空数据,以免影响下一次发送** 364 | $json_data = json_encode($send_arr); 365 | $result_url = $url; 366 | $conn = curl_init($result_url); 367 | curl_setopt($conn, CURLOPT_RETURNTRANSFER, 1);//参数1 不显示 368 | curl_setopt($conn, CURLOPT_POST, 1); 369 | curl_setopt($conn, CURLOPT_POSTFIELDS, $json_data); 370 | $get = curl_exec($conn); 371 | return $get; 372 | } 373 | 374 | /** 375 | * 返回客户端传来的消息 376 | * @return array 377 | */ 378 | public function getMsg() 379 | { 380 | return $this->msg; 381 | } 382 | 383 | /** 384 | * 当前消息体是否为插件反馈(用于提交返回模型下获取群列表等) 385 | * 若是,则默认不能够返回消息。若需要返回消息,调用 setCallbackSend(true) 386 | * @return boolean 387 | */ 388 | public function isCallback() 389 | { 390 | return $this->getMsg()['SubType'] == self::$SUBTYPE_CALLBACK_SEND; 391 | } 392 | 393 | /** 394 | * 是否在插件反馈情况下返回消息(提交返回),默认否。该方法在PHP下无效 395 | * @param boolean $callbackSend 默认false 396 | */ 397 | public function setCallbackSend($callbackSend = false) 398 | { 399 | $this->callbackSend = $callbackSend; 400 | } 401 | 402 | /** 403 | * 获取返回数据:已格式化,作为最后直接的输出返回.同时重置已发送消息(清空) 404 | * @return string 消息文本(json_encode) 405 | */ 406 | public function toJsonString() 407 | { 408 | $ret = json_encode($this->returnData); 409 | $this->returnData = ['data' => []]; 410 | return $ret; 411 | } 412 | 413 | 414 | /******************************接下来为具体功能,每添加一个功能就增加一条消息。****************************************************/ 415 | /******************消息发送*************************/ 416 | /** 417 | * 通用发送消息方法(为解决某些平台兼容问题) 418 | * @param int $type 消息类型,见TypeEnum(如1为好友消息,2为群消息,3为讨论组消息,4为群临时消息等) 419 | * @param string $group 群号 420 | * @param string $qq QQ 421 | * @param string $msg 消息内容 422 | * @param int $structureType 消息结构类型 0普通消息,1 XML消息,2 JSON消息 423 | * @param int $subType XML、JSON消息发送方式下:0为普通(默认),1为匿名(需要群开启) 424 | * @return mixed 425 | */ 426 | public function sendMsg($type, $group, $qq, $msg, $structureType = 0, $subType = 0) 427 | { 428 | return $this->addDataCell($type, $subType, $structureType, $group, $qq, $msg, '', 0); 429 | } 430 | 431 | /** 432 | * 发送私聊消息 433 | * @param string $qq 434 | * @param string $msg 435 | * @param int $structureType 消息结构类型 0普通消息,1 XML消息,2 JSON消息 436 | * @param int $subType XML、JSON消息发送方式下:0为普通(默认),1为匿名(需要群开启) 437 | * @return mixed 438 | */ 439 | public function sendPrivateMsg($qq, $msg, $structureType = 0, $subType = 0) 440 | { 441 | return $this->addDataCell(HTTPSDK::$TYPE_FRIEND, $subType, $structureType, '', $qq, $msg, '', 0); 442 | } 443 | 444 | /** 445 | * 发送群消息 446 | * @param string $groupId 447 | * @param string $msg 448 | * @param int $structureType 消息结构类型 0普通消息,1 XML消息,2 JSON消息 449 | * @param int $subType XML、JSON消息发送方式下:0为普通(默认),1为匿名(需要群开启) 450 | * @return mixed 451 | */ 452 | public function sendGroupMsg($groupId, $msg, $structureType = 0, $subType = 0) 453 | { 454 | return $this->addDataCell(HTTPSDK::$TYPE_GROUP, $subType, $structureType, $groupId, '', $msg, '', 0); 455 | } 456 | 457 | /** 458 | * 发送讨论组消息 459 | * @param string $discuss 460 | * @param string $msg 461 | * @param int $structureType 消息结构类型 0普通消息,1 XML消息,2 JSON消息 462 | * @param int $subType XML、JSON消息发送方式下:0为普通(默认),1为匿名(需要群开启) 463 | * @return mixed 464 | */ 465 | public function sendDiscussMsg($discuss, $msg, $structureType = 0, $subType = 0) 466 | { 467 | return $this->addDataCell(HTTPSDK::$TYPE_DISCUSS, $subType, $structureType, $discuss, '', $msg, '', 0); 468 | } 469 | 470 | /** 471 | * 向QQ点赞 472 | * @param string $qq 473 | * @param int $count 默认为1,作为消息的 Msg项 474 | * @return mixed 475 | */ 476 | public function sendLike($qq, $count = 1) 477 | { 478 | return $this->addDataCell(HTTPSDK::$TYPE_SEND_LIKE, 0, 0, '', $qq, $count, '', 0); 479 | } 480 | 481 | /** 482 | * 窗口抖动 483 | * @param string $qq 484 | * @return mixed 485 | */ 486 | public function sendShake($qq) 487 | { 488 | return $this->addDataCell(HTTPSDK::$TYPE_SEND_SHAKE, 0, 0, '', $qq, '', '', 0); 489 | } 490 | 491 | /******************群操作、事件处理*************************/ 492 | /** 493 | * 群禁言(管理) 494 | * @param string $groupId 群号 495 | * @param string $qq 禁言QQ,为空则禁言全群 496 | * @param int $time 禁言时间,单位秒,至少10秒。0为解除禁言 497 | * @return mixed 498 | */ 499 | public function setGroupBan($groupId, $qq = '', $time = 10) 500 | { 501 | return $this->addDataCell(HTTPSDK::$TYPE_GROUP_BAN, 0, 0, $groupId, $qq, $time, '', 0); 502 | } 503 | 504 | /** 505 | * 主动退群 506 | * @param string $groupId 507 | * @return mixed 508 | */ 509 | public function setGroupQuit($groupId) 510 | { 511 | return $this->addDataCell(HTTPSDK::$TYPE_GROUP_QUIT, 0, 0, $groupId, '', '', '', 0); 512 | } 513 | 514 | /** 515 | * 踢人(管理) 516 | * @param string $groupId 517 | * @param string $qq 518 | * @param boolean $neverIn 是否不允许再加群 519 | * @return mixed 520 | */ 521 | public function setGroupKick($groupId, $qq, $neverIn = false) 522 | { 523 | return $this->addDataCell(HTTPSDK::$TYPE_GROUP_KICK, 0, 0, $groupId, $qq, $neverIn ? 1 : 0, '', 0); 524 | } 525 | 526 | /** 527 | * 设置群名片 528 | * @param string $groupId 529 | * @param string $qq 530 | * @param string $card 531 | * @return mixed 532 | */ 533 | public function setGroupCard($groupId, $qq, $card = '') 534 | { 535 | return $this->addDataCell(HTTPSDK::$TYPE_GROUP_SET_CARD, 0, 0, $groupId, $qq, $card, '', 0); 536 | } 537 | 538 | /** 539 | * 设置管理员(群主) 540 | * @param string $groupId 541 | * @param string $qq 542 | * @param boolean $become true为设置,false为取消 543 | * @return mixed 544 | */ 545 | public function setGroupAdmin($groupId, $qq, $become = false) 546 | { 547 | return $this->addDataCell(HTTPSDK::$TYPE_GROUP_SET_ADMIN, 0, 0, $groupId, $qq, $become ? 1 : 0, '', 0); 548 | } 549 | 550 | /** 551 | * 处理加群事件,是否同意 552 | * @param string $groupId 553 | * @param string $qq 554 | * @param boolean $agree 是否同意加群 555 | * @param int $type 213请求入群 214我被邀请加入某群 215某人被邀请加入群 。为0则不管哪种 556 | * @param string $msg 消息,当拒绝时发送的消息 557 | * @return mixed 558 | */ 559 | public function handleGroupIn($groupId, $qq, $agree = true, $type = 0, $msg = '') 560 | { 561 | return $this->addDataCell(HTTPSDK::$TYPE_GROUP_HANDLE_GROUP_IN, $type, 0, $groupId, $qq, $agree ? 1 : 0, $msg, 0); 562 | } 563 | 564 | /** 565 | * 是否同意被加好友 566 | * @param string $qq 567 | * @param boolean $agree 是否同意 568 | * @param string $msg 附加消息 569 | * @return mixed 570 | */ 571 | public function handleFriendAdd($qq, $agree = true, $msg = '') 572 | { 573 | return $this->addDataCell(HTTPSDK::$TYPE_FRIEND_HANDLE_FRIEND_ADD, 0, 0, '', $qq, $agree ? 1 : 0, $msg, 0); 574 | } 575 | 576 | /** 577 | * 发群公告(管理) 578 | * @param string $groupId 579 | * @param string $title 内容 580 | * @param string $content 信息 581 | * @return mixed 582 | */ 583 | public function addGroupNotice($groupId, $title, $content) 584 | { 585 | return $this->addDataCell(HTTPSDK::$TYPE_GROUP_ADD_NOTICE, 0, 0, $groupId, '', $title, $content, 0); 586 | } 587 | 588 | /** 589 | * 发群作业(管理)。注意作业名和标题中不能含有#号 590 | * @param string $groupId 591 | * @param string $homeworkName 作业名 592 | * @param string $title 标题 593 | * @param string $content 内容 594 | * @return mixed 595 | */ 596 | public function addGroupHomework($groupId, $homeworkName, $title, $content) 597 | { 598 | return $this->addDataCell(HTTPSDK::$TYPE_GROUP_ADD_HOMEWORK, 0, 0, $groupId, '', $homeworkName . '#' . $title, $content, 0); 599 | } 600 | 601 | /** 602 | * 主动申请加入群 603 | * @param string $groupId 群号 604 | * @param string $reason 加群理由 605 | * @return mixed 606 | */ 607 | public function joinGroup($groupId, $reason = '') 608 | { 609 | return $this->addDataCell(HTTPSDK::$TYPE_GROUP_JOIN, 0, 0, $groupId, '', $reason, 0, 0); 610 | } 611 | 612 | /** 613 | * 创建讨论组 614 | * @param string $disName 讨论组名。并作为创建后第一条消息发送(激活消息) 615 | * @param array $qqList 需要添加到讨论组的QQ号列表 616 | * @return mixed 讨论组ID 617 | */ 618 | public function disGroupCreate($disName, $qqList = []) 619 | { 620 | $qqListStr = ''; 621 | $first = true; 622 | foreach ($qqList as $qq) { 623 | $qqListStr .= $first ? $qq : '#' . $qq; 624 | $first = false; 625 | } 626 | return $this->addDataCell(HTTPSDK::$TYPE_DIS_CREATE, 0, 0, '', '', $disName, $qqListStr, 0); 627 | } 628 | 629 | /** 630 | * 退出讨论组 631 | * @param string $disGroupId 讨论组ID 632 | * @return mixed 633 | */ 634 | public function disGroupQuit($disGroupId) 635 | { 636 | return $this->addDataCell(HTTPSDK::$TYPE_DIS_QUIT, 0, 0, $disGroupId, '', '', 0, 0); 637 | } 638 | 639 | /** 640 | * 踢出讨论组 641 | * @param string $disGroupId 讨论组ID 642 | * @param array $qqList 欲踢出的QQ号列表 643 | * @return mixed 644 | */ 645 | public function disGroupKick($disGroupId, $qqList = []) 646 | { 647 | $qqListStr = ''; 648 | $first = true; 649 | foreach ($qqList as $qq) { 650 | $qqListStr .= $first ? $qq : '#' . $qq; 651 | $first = false; 652 | } 653 | return $this->addDataCell(HTTPSDK::$TYPE_DIS_KICK, 0, 0, $disGroupId, '', $qqListStr, 0, 0); 654 | } 655 | 656 | /** 657 | * 添加讨论组成员 658 | * @param string $disGroupId 讨论组号 659 | * @param array $qqList 欲添加的QQ号列表 660 | * @return mixed 661 | */ 662 | public function disGroupInvite($disGroupId, $qqList = []) 663 | { 664 | $qqListStr = ''; 665 | $first = true; 666 | foreach ($qqList as $qq) { 667 | $qqListStr .= $first ? $qq : '#' . $qq; 668 | $first = false; 669 | } 670 | return $this->addDataCell(HTTPSDK::$TYPE_DIS_INVITE, 0, 0, $disGroupId, '', $qqListStr, 0, 0); 671 | } 672 | 673 | /** 674 | * 邀请QQ入群(管理+群员) 675 | * 676 | * @param string $groupId 群号 677 | * @param string $qq QQ 678 | * @return mixed 状态 679 | */ 680 | public function groupInvite($groupId, $qq) 681 | { 682 | return $this->addDataCell(HTTPSDK::$TYPE_GROUP_INVITE, 0, 0, $groupId, '', $qq, 0, 0); 683 | } 684 | /*********************** 获取信息:注意获取反馈消息,通过ID识别 *******************************************/ 685 | /** 686 | * 获取陌生人信息 687 | * @param string $qq 688 | * @return mixed 689 | */ 690 | public function getStrangerInfo($qq) 691 | { 692 | return $this->addDataCell(HTTPSDK::$TYPE_GET_STRANGER_INFO, 0, 0, '', $qq, '', '', 0); 693 | 694 | } 695 | 696 | /** 697 | * 获取当前登陆的QQ 698 | * @return mixed 699 | */ 700 | public function getLoginQQ() 701 | { 702 | return $this->addDataCell(HTTPSDK::$TYPE_GET_LOGIN_QQ, 0, 0, '', '', '', '', 0); 703 | } 704 | 705 | /** 706 | * 获取当前QQ群列表 707 | * @return mixed 708 | */ 709 | public function getGroupList() 710 | { 711 | return $this->addDataCell(HTTPSDK::$TYPE_GET_GROUP_LIST, 0, 0, '', '', '', '', 0); 712 | } 713 | 714 | /** 715 | * 获取当前登陆QQ好友列表 716 | * @return mixed 717 | */ 718 | public function getFriendList() 719 | { 720 | return $this->addDataCell(HTTPSDK::$TYPE_GET_FRIEND_LIST, 0, 0, '', '', '', '', 0); 721 | } 722 | 723 | /** 724 | * 获取指定群群成员列表 725 | * @param string $groupId 726 | * @return mixed 727 | */ 728 | public function getGroupMemberList($groupId) 729 | { 730 | return $this->addDataCell(HTTPSDK::$TYPE_GET_GROUP_MEMBER_LIST, 0, 0, $groupId, '', '', '', 0); 731 | } 732 | 733 | /** 734 | * 获取群公告 735 | * @param string $groupId 736 | * @return mixed 737 | */ 738 | public function getGroupNotice($groupId) 739 | { 740 | return $this->addDataCell(HTTPSDK::$TYPE_GET_GROUP_NOTICE, 0, 0, $groupId, '', '', '', 0); 741 | } 742 | 743 | /** 744 | * 获取对象QQ赞数量 745 | * @param $qq 746 | * @return mixed 747 | */ 748 | public function getLikeCount($qq) 749 | { 750 | return $this->addDataCell(HTTPSDK::$TYPE_LIKE_COUNT_GET, 0, 0, '', $qq, '', '', 0); 751 | } 752 | 753 | /** 754 | * 获取讨论组列表 755 | * @return mixed 756 | */ 757 | public function getDisGroupList() 758 | { 759 | return $this->addDataCell(HTTPSDK::$TYPE_GET_DIS_LIST, 0, 0, '', '', '', '', 0); 760 | } 761 | 762 | /** 763 | * 获取QQ等级 764 | * 765 | * @param string $qq QQ 766 | * @return mixed 等级 767 | */ 768 | public function getQQLevel($qq) 769 | { 770 | return $this->addDataCell(HTTPSDK::$TYPE_GET_QQ_LEVEL, 0, 0, '', $qq, '', '', 0); 771 | } 772 | 773 | /** 774 | * 获取群成员名片 775 | * 776 | * @param string $groupId 群号 777 | * @param string $qq QQ 778 | * @return mixed 名片 779 | */ 780 | public function getGroupMemberCard($groupId, $qq) 781 | { 782 | return $this->addDataCell(HTTPSDK::$TYPE_GET_QQ_LEVEL, 0, 0, $groupId, $qq, '', '', 0); 783 | } 784 | 785 | /** 786 | * 查询QQ是否在线 787 | * 788 | * @param string $qq QQ 789 | * @return mixed 是否在线 790 | */ 791 | public function getQQIsOline($qq) 792 | { 793 | return $this->addDataCell(HTTPSDK::$TYPE_GET_QQ_ONLINE_STATUS, 0, 0, '', $qq, '', '', 0); 794 | } 795 | 796 | /** 797 | * 查询QQ是否好友 798 | * 799 | * @param string $qq QQ 800 | * @return mixed 是否好友 801 | */ 802 | public function getQQIsFriend($qq) 803 | { 804 | return $this->addDataCell(HTTPSDK::$TYPE_GET_QQ_IS_FRIEND, 0, 0, '', $qq, '', '', 0); 805 | } 806 | 807 | /** 808 | * 获取当前QQ机器人状态信息(如是否在线) 809 | * 810 | * @return mixed 结构信息 811 | */ 812 | public function getQQRobotInfo() 813 | { 814 | return $this->addDataCell(HTTPSDK::$TYPE_GET_QQ_ROBOT_INFO, 0, 0, '', '', '', '', 0); 815 | } 816 | 817 | /** 818 | * 置正在输入 状态,发送消息撤销 819 | * 820 | * @param string $qq QQ 821 | * @return mixed 状态 822 | */ 823 | public function setInputStatus($qq) 824 | { 825 | return $this->addDataCell(HTTPSDK::$TYPE_SET_INPUT_STATUS, 0, 0, '', $qq, '', '', 0); 826 | } 827 | } -------------------------------------------------------------------------------- /SDK/PHP/composer install: -------------------------------------------------------------------------------- 1 | composer require ksust/http-api-sdk -------------------------------------------------------------------------------- /SDK/Python/install: -------------------------------------------------------------------------------- 1 | pip install http-api-sdk -------------------------------------------------------------------------------- /demo/Java/HTTP-API-Java-Demo: -------------------------------------------------------------------------------- 1 | https://github.com/ksust/HTTP-API-Java-Demo -------------------------------------------------------------------------------- /demo/NodeJS/demo-push.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Demo 3 | * User: yugao 4 | * Date: 2019/2/27 5 | * version 2.2.2 6 | * Note: HTTPSDK for NodeJS(适用于版本2.2.2插件):用于解析插件消息、构造返回数据,以及HTTP推送(发起HTTP请求) 7 | * Contact: 开发者邮箱 admin@ksust.com 8 | * 安装SDK:npm install http-api-sdk 9 | */ 10 | 11 | const HTTPSDK = require('http-api-sdk'); 12 | 13 | //推送演示,需要配置推送 14 | push = HTTPSDK.httpPush('http://127.0.0.1:8080') 15 | push.getGroupList().data(function (data) { 16 | console.log('push ' + data) 17 | }); 18 | push.getLoginQQ().data(function (data) { 19 | console.log('push ' + data) 20 | }); 21 | push.sendPrivateMsg('QQ', 'Hello').data(function (data) { 22 | console.log('push ' + data) 23 | }); 24 | 25 | //消息转发演示,插件在线即可用 26 | let forward = HTTPSDK.msgForwardPush('QQ', '授权码'); 27 | forward.getLoginQQ().data(function (data) { 28 | console.log('forward ' + data); 29 | }); 30 | 31 | forward.getGroupList().data(function (data) { 32 | console.log('forward ' + data); 33 | }); 34 | forward.sendPrivateMsg('QQ', 'Hello').data(function (data) { 35 | console.log('forward' + data) 36 | }); -------------------------------------------------------------------------------- /demo/NodeJS/demo-server.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Demo 3 | * User: yugao 4 | * Date: 2019/2/27 5 | * version 2.2.2 6 | * Note: HTTPSDK for NodeJS(适用于版本2.2.2插件):用于解析插件消息、构造返回数据,以及HTTP推送(发起HTTP请求) 7 | * Contact: 开发者邮箱 admin@ksust.com 8 | * 安装SDK:npm install http-api-sdk 9 | */ 10 | const http = require('http'); 11 | const HTTPSDK = require('http-api-sdk'); 12 | 13 | const server = http.createServer((req, res) => { 14 | req.on('data', function (data) { 15 | let sdk = HTTPSDK.httpGet(data.toString()); 16 | //console.log(sdk.getMsg());//获取到的消息 17 | sdk.sendPrivateMsg(sdk.getMsg()['QQ'], '你发送了这样的消息:' + sdk.getMsg()['Msg']); 18 | sdk.getLoginQQ(); 19 | //回调演示,提交返回获取群列表、登录QQ等 20 | if (sdk.isCallback() && parseInt(sdk.getMsg()['Type']) === HTTPSDK.TYPE_GET_LOGIN_QQ) { 21 | console.log('Login QQ:' + sdk.getLoginQQ()); 22 | } 23 | res.end(sdk.toJsonString()); 24 | }); 25 | 26 | }); 27 | server.on('clientError', (err, socket) => { 28 | socket.end('HTTP/1.1 400 Bad Request\r\n\r\n'); 29 | }); 30 | server.listen(8000); -------------------------------------------------------------------------------- /demo/NodeJS/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "http-api-nodejs-demo", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "http-api-sdk": "^2.2.3" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /demo/PHP/.gitignore: -------------------------------------------------------------------------------- 1 | /.idea 2 | temp 3 | vendor 4 | composer.lock -------------------------------------------------------------------------------- /demo/PHP/HTTPSDK.php: -------------------------------------------------------------------------------- 1 | []];//返回给插件的数据 124 | private $returnDataCell = [//返回数据中的data单元 125 | 'ID' => '-1',//消息唯一标识,ID,可使用毫秒时间戳、UUID等 126 | 'Type' => -1,//发送消息类型, 1 好友信息 2,群信息 3,讨论组信息 4,群临时会话 5,讨论组临时会话 ...,20001 群禁言, 127 | 'SubType' => 0,//0普通,1匿名(需要群开启,默认0) 128 | 'StructureType' => 0,//消息结构类型,0为普通文本消息(默认)、1为XML消息、2为JSON消息 129 | 'Group' => '',//操作或发送的群号或者讨论组号 130 | 'QQ' => '',//操作或者发送的QQ 131 | 'Msg' => '',//文本消息【标签等】,当发送类型为JSON、XML时为相应文本,禁言时为分钟数【分钟】 132 | 'Send' => 0,//是否开启同步发送(1为开启同步发送【测试】,0为不开启【默认】) 133 | 'Data' => ''//附加数据,用于特定操作等(文本型 134 | ]; 135 | 136 | /** 137 | * http提交返回的构建方法,一般使用该方法 138 | * @return HTTPSDK 139 | */ 140 | public static function httpGet() 141 | { 142 | $sdk = new HTTPSDK(); 143 | $sdk->SDKType = 0; 144 | return $sdk; 145 | } 146 | 147 | /** 148 | * webSocket服务端模式下用于解析插件消息,传入接收到的消息即可(若有粘包等情况,请先以换行\r\n分开) 149 | * @param string $msg 接收到的消息(若有粘包等情况,请先以换行\r\n分开) 150 | * @return HTTPSDK 151 | */ 152 | public static function webSocket($msg) 153 | { 154 | $sdk = new HTTPSDK($msg); 155 | $sdk->SDKType = 1; 156 | return $sdk; 157 | } 158 | 159 | /** 160 | * HTTP推送,HTTPSDKPush 161 | * @param string $URL 推送地址及端口,如http://127.0.0.1:8888 162 | * @param string $serverKey 验证key,默认123 163 | * @param string $serverSecret 验证secret,默认456 164 | * @param boolean $serverVerify 是否开启验证,默认开启 165 | * @return HTTPSDK 166 | */ 167 | public static function httpPush($URL, $serverKey = null, $serverSecret = null) 168 | { 169 | $sdk = new HTTPSDK(); 170 | $sdk->SDKType = 2; 171 | $sdk->serverURL = $URL; 172 | $sdk->serverKey = $serverKey; 173 | $sdk->serverSecret = $serverSecret; 174 | return $sdk; 175 | } 176 | 177 | /** 178 | * 消息转发推送,消息转发模式(http协议)。需要在到平台免费申请授权码:http://work.ksust.com 179 | * @param string $qq 机器人QQ 180 | * @param string $code 该机器人QQ的授权码,统一管理平台:http://work.ksust.com 181 | * @return HTTPSDK 182 | */ 183 | public static function msgForwardPush($qq, $code) 184 | { 185 | $sdk = new HTTPSDK(); 186 | $sdk->SDKType = 3; 187 | $sdk->myqq = $qq; 188 | $sdk->code = $code; 189 | list($sdk->url, $sdk->token) = self::getMsgForwardPushToken($qq, $code); 190 | return $sdk; 191 | } 192 | 193 | /** 194 | * 获取消息转发请求的token 195 | * @param string $qq 机器人QQ 196 | * @param string $code 该机器人QQ的授权码,统一管理平台:http://work.ksust.com 197 | * @return array url,token 198 | */ 199 | private static function getMsgForwardPushToken($qq, $code) 200 | { 201 | 202 | //初始化,获取token(Redis缓存或本地文件缓存,远程获取) 203 | $token = ''; 204 | $url = 'http://127.0.0.1:2047'; 205 | $tokenKey = 'msgForwardToken-' . $qq; 206 | $urlKey = 'msgForwardURL-' . $qq; 207 | if (class_exists('Redis')) { 208 | //默认使用Redis,否则使用文件缓存 209 | $redis = new Redis(); 210 | $redis->connect('127.0.0.1', 6379); 211 | if ($redis->exists($tokenKey) && $redis->exists($urlKey)) { 212 | $token = $redis->get($tokenKey); 213 | $url = $redis->get($urlKey); 214 | } else { 215 | $verifyData = self::sendMsgForwardPush('http://qq.ksust.com/api/tool.php?func=get_server_dst' 216 | , 3, 'user-' . $qq, 'plugin-' . $qq, $code); 217 | $verifyData = json_decode($verifyData, true); 218 | if ($verifyData['status'] == 1) { 219 | $token = $verifyData['data']['token']; 220 | $url = 'http://' . $verifyData['data']['ip'] . ':' . $verifyData['data']['http-port'] . '/api/user/request'; 221 | $redis->set($tokenKey, $token); 222 | $redis->set($urlKey, $urlKey); 223 | } 224 | } 225 | } else { 226 | //文件缓存,创建./temp目录 227 | $tempDir = self::$TEMP_DIR; 228 | if (!is_dir($tempDir)) { 229 | mkdir($tempDir, 777, true); 230 | } 231 | if (time() - filemtime($tempDir . $tokenKey) <= 60 * 60 * 24 232 | && time() - filemtime($tempDir . $urlKey) <= 60 * 60 * 24 233 | && strlen(file_get_contents($tempDir . $tokenKey)) > 5 234 | ) { 235 | $token = file_get_contents($tempDir . $tokenKey); 236 | $url = file_get_contents($tempDir . $urlKey); 237 | } else { 238 | $verifyData = self::sendMsgForwardPush('http://qq.ksust.com/api/tool.php?func=get_server_dst' 239 | , 3, 'user-' . $qq, 'plugin-' . $qq, $code); 240 | $verifyData = json_decode($verifyData, true); 241 | if ($verifyData['status'] == 1) { 242 | $token = $verifyData['data']['token']; 243 | $url = 'http://' . $verifyData['data']['ip'] . ':' . $verifyData['data']['http-port'] . '/api/user/request'; 244 | file_put_contents($tempDir . $tokenKey, $token); 245 | file_put_contents($tempDir . $urlKey, $url); 246 | } 247 | } 248 | } 249 | return [$url, $token]; 250 | } 251 | 252 | /** 253 | * 消息转发请求协议封装 254 | * @param string $url 255 | * @param string $code 256 | * @param string $src 257 | * @param string $dst 258 | * @param string $token 259 | * @param array $dataIn 260 | * @return string 请求结果 261 | */ 262 | private static function sendMsgForwardPush($url, $code, $src, $dst, $token, $dataIn = array()) 263 | { 264 | $data['id'] = time(); 265 | $data['code'] = $code; 266 | $data['src'] = $src; 267 | $data['dst'] = $dst; 268 | $data['time'] = time(); 269 | $data['token'] = $token; 270 | $data['data'] = json_encode($dataIn); 271 | //请求 272 | $conn = curl_init($url); 273 | curl_setopt($conn, CURLOPT_RETURNTRANSFER, 1);//参数1 不显示 274 | curl_setopt($conn, CURLOPT_POST, 1); 275 | curl_setopt($conn, CURLOPT_POSTFIELDS, json_encode($data)); 276 | curl_setopt($conn, CURLOPT_HTTPHEADER, ["Content-Type: application/json; charset=utf-8"]); 277 | $get = curl_exec($conn); 278 | return $get; 279 | } 280 | 281 | /** 282 | * 解析客户端传来的消息 283 | * HttpApiLocalSDK constructor. 284 | * @param string $msg 解析的消息(JSON),http提交返回使用默认参数,ws等需要解析的消息则传入消息字符串 285 | */ 286 | private function __construct($msg = '') 287 | { 288 | $this->parseMsg($msg); 289 | } 290 | 291 | /** 292 | * 获取并解析客户端传来的消息 293 | * @param string $msg 解析的消息(JSON),为空则从PHP输入流中获取 294 | */ 295 | private function parseMsg($msg) 296 | { 297 | if ($msg == '') 298 | $this->msg = json_decode(urldecode(urldecode((file_get_contents("php://input")))), true); 299 | else 300 | $this->msg = json_decode(urldecode(urldecode($msg)), true); 301 | } 302 | 303 | /** 304 | * 添加功能,原始方法:为了保持一致,此处参数使用大驼峰命名 305 | * @param $Type 306 | * @param int $SubType 307 | * @param int $StructureType 308 | * @param string $Group 309 | * @param string $QQ 310 | * @param string $Msg 311 | * @param string $Data 312 | * @param int $Send 313 | * @return mixed 314 | */ 315 | private function addDataCell($Type, $SubType = 0, $StructureType = 0, $Group = '', $QQ = '', $Msg = '', $Data = '', $Send = 0) 316 | { 317 | $data = $this->returnDataCell; 318 | $data['ID'] = md5(mt_rand(-time(), time()) . time() . $this->toJsonString()); 319 | $data['Type'] = $Type; 320 | $data['SubType'] = $SubType; 321 | $data['StructureType'] = $StructureType; 322 | $data['Group'] = $Group; 323 | $data['QQ'] = $QQ; 324 | $data['Msg'] = $Msg; 325 | $data['Data'] = $Data; 326 | $data['Send'] = $Send; 327 | array_push($this->returnData['data'], $data); 328 | //分类型确定调用方式 329 | if ($this->SDKType == 2) { 330 | $pushReturn = $this->sendPushData(); 331 | $pushReturnJson = json_decode($pushReturn, true); 332 | //若解析失败,则返回原文本;否则返回解析后的array 333 | return $pushReturnJson == null ? $pushReturn : $pushReturnJson; 334 | } else if ($this->SDKType == 3) { 335 | //消息转发 336 | $sendData = $this->returnData['data'][0]; 337 | $this->returnData = ['data' => []];//发送之后清空数据,以免影响下一次发送** 338 | $forwardReturnJson = json_decode(self::sendMsgForwardPush($this->url, 3, 'user-' . $this->myqq, 'plugin-' . $this->myqq 339 | , $this->token, $sendData), true); 340 | if ($forwardReturnJson['code'] == -1) { 341 | //清空缓存 342 | file_put_contents(self::$TEMP_DIR . 'msgForwardToken-' . $this->myqq, ''); 343 | file_put_contents(self::$TEMP_DIR . 'msgForwardURL-' . $this->myqq, ''); 344 | } 345 | return $forwardReturnJson; 346 | 347 | } 348 | //非推送模式下返回null 349 | return null; 350 | } 351 | 352 | /** 353 | * httpPush:发送消息与获得结果 354 | * @return mixed 返回json数据 355 | */ 356 | private function sendPushData() 357 | { 358 | $url = $this->serverURL; 359 | $verify = []; 360 | $verify['time'] = time(); 361 | $verify['verify'] = md5($this->serverKey . $verify['time'] . $this->serverSecret); 362 | $send_arr = $verify + $this->returnData;//加入加密信息。"+",若两个数组存在相同的key,前一会覆盖后一 363 | $this->returnData = ['data' => []];//发送之后清空数据,以免影响下一次发送** 364 | $json_data = json_encode($send_arr); 365 | $result_url = $url; 366 | $conn = curl_init($result_url); 367 | curl_setopt($conn, CURLOPT_RETURNTRANSFER, 1);//参数1 不显示 368 | curl_setopt($conn, CURLOPT_POST, 1); 369 | curl_setopt($conn, CURLOPT_POSTFIELDS, $json_data); 370 | $get = curl_exec($conn); 371 | return $get; 372 | } 373 | 374 | /** 375 | * 返回客户端传来的消息 376 | * @return array 377 | */ 378 | public function getMsg() 379 | { 380 | return $this->msg; 381 | } 382 | 383 | /** 384 | * 当前消息体是否为插件反馈(用于提交返回模型下获取群列表等) 385 | * 若是,则默认不能够返回消息。若需要返回消息,调用 setCallbackSend(true) 386 | * @return boolean 387 | */ 388 | public function isCallback() 389 | { 390 | return $this->getMsg()['SubType'] == self::$SUBTYPE_CALLBACK_SEND; 391 | } 392 | 393 | /** 394 | * 是否在插件反馈情况下返回消息(提交返回),默认否。该方法在PHP下无效 395 | * @param boolean $callbackSend 默认false 396 | */ 397 | public function setCallbackSend($callbackSend = false) 398 | { 399 | $this->callbackSend = $callbackSend; 400 | } 401 | 402 | /** 403 | * 获取返回数据:已格式化,作为最后直接的输出返回.同时重置已发送消息(清空) 404 | * @return string 消息文本(json_encode) 405 | */ 406 | public function toJsonString() 407 | { 408 | $ret = json_encode($this->returnData); 409 | $this->returnData = ['data' => []]; 410 | return $ret; 411 | } 412 | 413 | 414 | /******************************接下来为具体功能,每添加一个功能就增加一条消息。****************************************************/ 415 | /******************消息发送*************************/ 416 | /** 417 | * 通用发送消息方法(为解决某些平台兼容问题) 418 | * @param int $type 消息类型,见TypeEnum(如1为好友消息,2为群消息,3为讨论组消息,4为群临时消息等) 419 | * @param string $group 群号 420 | * @param string $qq QQ 421 | * @param string $msg 消息内容 422 | * @param int $structureType 消息结构类型 0普通消息,1 XML消息,2 JSON消息 423 | * @param int $subType XML、JSON消息发送方式下:0为普通(默认),1为匿名(需要群开启) 424 | * @return mixed 425 | */ 426 | public function sendMsg($type, $group, $qq, $msg, $structureType = 0, $subType = 0) 427 | { 428 | return $this->addDataCell($type, $subType, $structureType, $group, $qq, $msg, '', 0); 429 | } 430 | 431 | /** 432 | * 发送私聊消息 433 | * @param string $qq 434 | * @param string $msg 435 | * @param int $structureType 消息结构类型 0普通消息,1 XML消息,2 JSON消息 436 | * @param int $subType XML、JSON消息发送方式下:0为普通(默认),1为匿名(需要群开启) 437 | * @return mixed 438 | */ 439 | public function sendPrivateMsg($qq, $msg, $structureType = 0, $subType = 0) 440 | { 441 | return $this->addDataCell(HTTPSDK::$TYPE_FRIEND, $subType, $structureType, '', $qq, $msg, '', 0); 442 | } 443 | 444 | /** 445 | * 发送群消息 446 | * @param string $groupId 447 | * @param string $msg 448 | * @param int $structureType 消息结构类型 0普通消息,1 XML消息,2 JSON消息 449 | * @param int $subType XML、JSON消息发送方式下:0为普通(默认),1为匿名(需要群开启) 450 | * @return mixed 451 | */ 452 | public function sendGroupMsg($groupId, $msg, $structureType = 0, $subType = 0) 453 | { 454 | return $this->addDataCell(HTTPSDK::$TYPE_GROUP, $subType, $structureType, $groupId, '', $msg, '', 0); 455 | } 456 | 457 | /** 458 | * 发送讨论组消息 459 | * @param string $discuss 460 | * @param string $msg 461 | * @param int $structureType 消息结构类型 0普通消息,1 XML消息,2 JSON消息 462 | * @param int $subType XML、JSON消息发送方式下:0为普通(默认),1为匿名(需要群开启) 463 | * @return mixed 464 | */ 465 | public function sendDiscussMsg($discuss, $msg, $structureType = 0, $subType = 0) 466 | { 467 | return $this->addDataCell(HTTPSDK::$TYPE_DISCUSS, $subType, $structureType, $discuss, '', $msg, '', 0); 468 | } 469 | 470 | /** 471 | * 向QQ点赞 472 | * @param string $qq 473 | * @param int $count 默认为1,作为消息的 Msg项 474 | * @return mixed 475 | */ 476 | public function sendLike($qq, $count = 1) 477 | { 478 | return $this->addDataCell(HTTPSDK::$TYPE_SEND_LIKE, 0, 0, '', $qq, $count, '', 0); 479 | } 480 | 481 | /** 482 | * 窗口抖动 483 | * @param string $qq 484 | * @return mixed 485 | */ 486 | public function sendShake($qq) 487 | { 488 | return $this->addDataCell(HTTPSDK::$TYPE_SEND_SHAKE, 0, 0, '', $qq, '', '', 0); 489 | } 490 | 491 | /******************群操作、事件处理*************************/ 492 | /** 493 | * 群禁言(管理) 494 | * @param string $groupId 群号 495 | * @param string $qq 禁言QQ,为空则禁言全群 496 | * @param int $time 禁言时间,单位秒,至少10秒。0为解除禁言 497 | * @return mixed 498 | */ 499 | public function setGroupBan($groupId, $qq = '', $time = 10) 500 | { 501 | return $this->addDataCell(HTTPSDK::$TYPE_GROUP_BAN, 0, 0, $groupId, $qq, $time, '', 0); 502 | } 503 | 504 | /** 505 | * 主动退群 506 | * @param string $groupId 507 | * @return mixed 508 | */ 509 | public function setGroupQuit($groupId) 510 | { 511 | return $this->addDataCell(HTTPSDK::$TYPE_GROUP_QUIT, 0, 0, $groupId, '', '', '', 0); 512 | } 513 | 514 | /** 515 | * 踢人(管理) 516 | * @param string $groupId 517 | * @param string $qq 518 | * @param boolean $neverIn 是否不允许再加群 519 | * @return mixed 520 | */ 521 | public function setGroupKick($groupId, $qq, $neverIn = false) 522 | { 523 | return $this->addDataCell(HTTPSDK::$TYPE_GROUP_KICK, 0, 0, $groupId, $qq, $neverIn ? 1 : 0, '', 0); 524 | } 525 | 526 | /** 527 | * 设置群名片 528 | * @param string $groupId 529 | * @param string $qq 530 | * @param string $card 531 | * @return mixed 532 | */ 533 | public function setGroupCard($groupId, $qq, $card = '') 534 | { 535 | return $this->addDataCell(HTTPSDK::$TYPE_GROUP_SET_CARD, 0, 0, $groupId, $qq, $card, '', 0); 536 | } 537 | 538 | /** 539 | * 设置管理员(群主) 540 | * @param string $groupId 541 | * @param string $qq 542 | * @param boolean $become true为设置,false为取消 543 | * @return mixed 544 | */ 545 | public function setGroupAdmin($groupId, $qq, $become = false) 546 | { 547 | return $this->addDataCell(HTTPSDK::$TYPE_GROUP_SET_ADMIN, 0, 0, $groupId, $qq, $become ? 1 : 0, '', 0); 548 | } 549 | 550 | /** 551 | * 处理加群事件,是否同意 552 | * @param string $groupId 553 | * @param string $qq 554 | * @param boolean $agree 是否同意加群 555 | * @param int $type 213请求入群 214我被邀请加入某群 215某人被邀请加入群 。为0则不管哪种 556 | * @param string $msg 消息,当拒绝时发送的消息 557 | * @return mixed 558 | */ 559 | public function handleGroupIn($groupId, $qq, $agree = true, $type = 0, $msg = '') 560 | { 561 | return $this->addDataCell(HTTPSDK::$TYPE_GROUP_HANDLE_GROUP_IN, $type, 0, $groupId, $qq, $agree ? 1 : 0, $msg, 0); 562 | } 563 | 564 | /** 565 | * 是否同意被加好友 566 | * @param string $qq 567 | * @param boolean $agree 是否同意 568 | * @param string $msg 附加消息 569 | * @return mixed 570 | */ 571 | public function handleFriendAdd($qq, $agree = true, $msg = '') 572 | { 573 | return $this->addDataCell(HTTPSDK::$TYPE_FRIEND_HANDLE_FRIEND_ADD, 0, 0, '', $qq, $agree ? 1 : 0, $msg, 0); 574 | } 575 | 576 | /** 577 | * 发群公告(管理) 578 | * @param string $groupId 579 | * @param string $title 内容 580 | * @param string $content 信息 581 | * @return mixed 582 | */ 583 | public function addGroupNotice($groupId, $title, $content) 584 | { 585 | return $this->addDataCell(HTTPSDK::$TYPE_GROUP_ADD_NOTICE, 0, 0, $groupId, '', $title, $content, 0); 586 | } 587 | 588 | /** 589 | * 发群作业(管理)。注意作业名和标题中不能含有#号 590 | * @param string $groupId 591 | * @param string $homeworkName 作业名 592 | * @param string $title 标题 593 | * @param string $content 内容 594 | * @return mixed 595 | */ 596 | public function addGroupHomework($groupId, $homeworkName, $title, $content) 597 | { 598 | return $this->addDataCell(HTTPSDK::$TYPE_GROUP_ADD_HOMEWORK, 0, 0, $groupId, '', $homeworkName . '#' . $title, $content, 0); 599 | } 600 | 601 | /** 602 | * 主动申请加入群 603 | * @param string $groupId 群号 604 | * @param string $reason 加群理由 605 | * @return mixed 606 | */ 607 | public function joinGroup($groupId, $reason = '') 608 | { 609 | return $this->addDataCell(HTTPSDK::$TYPE_GROUP_JOIN, 0, 0, $groupId, '', $reason, 0, 0); 610 | } 611 | 612 | /** 613 | * 创建讨论组 614 | * @param string $disName 讨论组名。并作为创建后第一条消息发送(激活消息) 615 | * @param array $qqList 需要添加到讨论组的QQ号列表 616 | * @return mixed 讨论组ID 617 | */ 618 | public function disGroupCreate($disName, $qqList = []) 619 | { 620 | $qqListStr = ''; 621 | $first = true; 622 | foreach ($qqList as $qq) { 623 | $qqListStr .= $first ? $qq : '#' . $qq; 624 | $first = false; 625 | } 626 | return $this->addDataCell(HTTPSDK::$TYPE_DIS_CREATE, 0, 0, '', '', $disName, $qqListStr, 0); 627 | } 628 | 629 | /** 630 | * 退出讨论组 631 | * @param string $disGroupId 讨论组ID 632 | * @return mixed 633 | */ 634 | public function disGroupQuit($disGroupId) 635 | { 636 | return $this->addDataCell(HTTPSDK::$TYPE_DIS_QUIT, 0, 0, $disGroupId, '', '', 0, 0); 637 | } 638 | 639 | /** 640 | * 踢出讨论组 641 | * @param string $disGroupId 讨论组ID 642 | * @param array $qqList 欲踢出的QQ号列表 643 | * @return mixed 644 | */ 645 | public function disGroupKick($disGroupId, $qqList = []) 646 | { 647 | $qqListStr = ''; 648 | $first = true; 649 | foreach ($qqList as $qq) { 650 | $qqListStr .= $first ? $qq : '#' . $qq; 651 | $first = false; 652 | } 653 | return $this->addDataCell(HTTPSDK::$TYPE_DIS_KICK, 0, 0, $disGroupId, '', $qqListStr, 0, 0); 654 | } 655 | 656 | /** 657 | * 添加讨论组成员 658 | * @param string $disGroupId 讨论组号 659 | * @param array $qqList 欲添加的QQ号列表 660 | * @return mixed 661 | */ 662 | public function disGroupInvite($disGroupId, $qqList = []) 663 | { 664 | $qqListStr = ''; 665 | $first = true; 666 | foreach ($qqList as $qq) { 667 | $qqListStr .= $first ? $qq : '#' . $qq; 668 | $first = false; 669 | } 670 | return $this->addDataCell(HTTPSDK::$TYPE_DIS_INVITE, 0, 0, $disGroupId, '', $qqListStr, 0, 0); 671 | } 672 | 673 | /** 674 | * 邀请QQ入群(管理+群员) 675 | * 676 | * @param string $groupId 群号 677 | * @param string $qq QQ 678 | * @return mixed 状态 679 | */ 680 | public function groupInvite($groupId, $qq) 681 | { 682 | return $this->addDataCell(HTTPSDK::$TYPE_GROUP_INVITE, 0, 0, $groupId, '', $qq, 0, 0); 683 | } 684 | /*********************** 获取信息:注意获取反馈消息,通过ID识别 *******************************************/ 685 | /** 686 | * 获取陌生人信息 687 | * @param string $qq 688 | * @return mixed 689 | */ 690 | public function getStrangerInfo($qq) 691 | { 692 | return $this->addDataCell(HTTPSDK::$TYPE_GET_STRANGER_INFO, 0, 0, '', $qq, '', '', 0); 693 | 694 | } 695 | 696 | /** 697 | * 获取当前登陆的QQ 698 | * @return mixed 699 | */ 700 | public function getLoginQQ() 701 | { 702 | return $this->addDataCell(HTTPSDK::$TYPE_GET_LOGIN_QQ, 0, 0, '', '', '', '', 0); 703 | } 704 | 705 | /** 706 | * 获取当前QQ群列表 707 | * @return mixed 708 | */ 709 | public function getGroupList() 710 | { 711 | return $this->addDataCell(HTTPSDK::$TYPE_GET_GROUP_LIST, 0, 0, '', '', '', '', 0); 712 | } 713 | 714 | /** 715 | * 获取当前登陆QQ好友列表 716 | * @return mixed 717 | */ 718 | public function getFriendList() 719 | { 720 | return $this->addDataCell(HTTPSDK::$TYPE_GET_FRIEND_LIST, 0, 0, '', '', '', '', 0); 721 | } 722 | 723 | /** 724 | * 获取指定群群成员列表 725 | * @param string $groupId 726 | * @return mixed 727 | */ 728 | public function getGroupMemberList($groupId) 729 | { 730 | return $this->addDataCell(HTTPSDK::$TYPE_GET_GROUP_MEMBER_LIST, 0, 0, $groupId, '', '', '', 0); 731 | } 732 | 733 | /** 734 | * 获取群公告 735 | * @param string $groupId 736 | * @return mixed 737 | */ 738 | public function getGroupNotice($groupId) 739 | { 740 | return $this->addDataCell(HTTPSDK::$TYPE_GET_GROUP_NOTICE, 0, 0, $groupId, '', '', '', 0); 741 | } 742 | 743 | /** 744 | * 获取对象QQ赞数量 745 | * @param $qq 746 | * @return mixed 747 | */ 748 | public function getLikeCount($qq) 749 | { 750 | return $this->addDataCell(HTTPSDK::$TYPE_LIKE_COUNT_GET, 0, 0, '', $qq, '', '', 0); 751 | } 752 | 753 | /** 754 | * 获取讨论组列表 755 | * @return mixed 756 | */ 757 | public function getDisGroupList() 758 | { 759 | return $this->addDataCell(HTTPSDK::$TYPE_GET_DIS_LIST, 0, 0, '', '', '', '', 0); 760 | } 761 | 762 | /** 763 | * 获取QQ等级 764 | * 765 | * @param string $qq QQ 766 | * @return mixed 等级 767 | */ 768 | public function getQQLevel($qq) 769 | { 770 | return $this->addDataCell(HTTPSDK::$TYPE_GET_QQ_LEVEL, 0, 0, '', $qq, '', '', 0); 771 | } 772 | 773 | /** 774 | * 获取群成员名片 775 | * 776 | * @param string $groupId 群号 777 | * @param string $qq QQ 778 | * @return mixed 名片 779 | */ 780 | public function getGroupMemberCard($groupId, $qq) 781 | { 782 | return $this->addDataCell(HTTPSDK::$TYPE_GET_QQ_LEVEL, 0, 0, $groupId, $qq, '', '', 0); 783 | } 784 | 785 | /** 786 | * 查询QQ是否在线 787 | * 788 | * @param string $qq QQ 789 | * @return mixed 是否在线 790 | */ 791 | public function getQQIsOline($qq) 792 | { 793 | return $this->addDataCell(HTTPSDK::$TYPE_GET_QQ_ONLINE_STATUS, 0, 0, '', $qq, '', '', 0); 794 | } 795 | 796 | /** 797 | * 查询QQ是否好友 798 | * 799 | * @param string $qq QQ 800 | * @return mixed 是否好友 801 | */ 802 | public function getQQIsFriend($qq) 803 | { 804 | return $this->addDataCell(HTTPSDK::$TYPE_GET_QQ_IS_FRIEND, 0, 0, '', $qq, '', '', 0); 805 | } 806 | 807 | /** 808 | * 获取当前QQ机器人状态信息(如是否在线) 809 | * 810 | * @return mixed 结构信息 811 | */ 812 | public function getQQRobotInfo() 813 | { 814 | return $this->addDataCell(HTTPSDK::$TYPE_GET_QQ_ROBOT_INFO, 0, 0, '', '', '', '', 0); 815 | } 816 | 817 | /** 818 | * 置正在输入 状态,发送消息撤销 819 | * 820 | * @param string $qq QQ 821 | * @return mixed 状态 822 | */ 823 | public function setInputStatus($qq) 824 | { 825 | return $this->addDataCell(HTTPSDK::$TYPE_SET_INPUT_STATUS, 0, 0, '', $qq, '', '', 0); 826 | } 827 | } -------------------------------------------------------------------------------- /demo/PHP/LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /demo/PHP/README.md: -------------------------------------------------------------------------------- 1 | # HTTP-API-SDK 2 | **包含PHP/Java/Python/NodeJS四种编程语言SDK。** 3 | **composer安装:composer require ksust/http-api-sdk** 4 | 5 | | 名称 | 编程语言 | 最新版本 | 适配插件版本 | 备注 | 6 | | ------ | ------ | ------| ------ | ------ | 7 | | HTTP-API-SDK For PHP | PHP |2.3.0|2.3.0|-| 8 | | HTTP-API-SDK For Java | Java8 |2.3.0|2.3.0|-| 9 | | HTTP-API-SDK For Python | Python2/3 |2.3.0|2.3.0|-| 10 | | HTTP-API-SDK For NodeJS | NodeJS8 |2.3.0|2.3.0|-| 11 | -------------------------------------------------------------------------------- /demo/PHP/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ksust/http-api-sdk", 3 | "description": "HTTP-API-PHP-SDK", 4 | "type": "library", 5 | "license": "Apache-2.0", 6 | "authors": [ 7 | { 8 | "name": "ksust", 9 | "email": "admin@ksust.com" 10 | } 11 | ], 12 | "minimum-stability":"stable", 13 | "require": { 14 | "workerman/workerman": "^3.5" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /demo/PHP/demo/demo-forwardPush.php: -------------------------------------------------------------------------------- 1 | getLoginQQ());//获取登录的QQ 11 | var_dump($forward->sendPrivateMsg('QQ', 'hello~'));//向QQ发送消息 12 | var_dump($forward->getFriendList());//获取好友列表 13 | -------------------------------------------------------------------------------- /demo/PHP/demo/demo-push.php: -------------------------------------------------------------------------------- 1 | getLoginQQ());//获取登录的QQ 10 | var_dump($push->sendPrivateMsg('QQ', 'hello~'));//向QQ发送消息 11 | var_dump($push->getFriendList());//获取好友列表 12 | -------------------------------------------------------------------------------- /demo/PHP/demo/demo-ws.php: -------------------------------------------------------------------------------- 1 | count = 4; 17 | // Emitted when new connection come 18 | $ws_worker->onConnect = function ($connection) { 19 | echo "New connection\n"; 20 | }; 21 | // Emitted when data received 22 | $ws_worker->onMessage = function ($connection, $data) { 23 | $json = json_decode(urldecode(urldecode($data)), true); 24 | if (isset($json['type']) && $json['type'] == 'init') { 25 | $connection->send('{"type":"success"}'); 26 | } else { 27 | //消息操作 28 | $sdk = HTTPSDK::webSocket($data); 29 | $msg = $sdk->getMsg(); 30 | if ($msg['Msg'] == 'demo') { 31 | $sdk->sendPrivateMsg($msg['QQ'], '你发送了这样的消息:' . $msg['Msg']);//逻辑代码,向发送者回消息 32 | } 33 | //echo $sdk->returnJsonString(); 34 | $connection->send($sdk->toJsonString()); 35 | } 36 | 37 | }; 38 | // Emitted when connection closed 39 | $ws_worker->onClose = function ($connection) { 40 | echo "Connection closed\n"; 41 | }; 42 | // Run worker 43 | Worker::runAll(); -------------------------------------------------------------------------------- /demo/PHP/demo/demo.php: -------------------------------------------------------------------------------- 1 | getMsg();//插件发送过来的消息 11 | $sdk->sendPrivateMsg($msg['QQ'], '你发送了这样的消息:' . $msg['Msg']);//逻辑代码,向发送者回消息 12 | echo $sdk->toJsonString();//命令返回 13 | 14 | ?> 15 | 16 | -------------------------------------------------------------------------------- /demo/Python/demo-flask.py: -------------------------------------------------------------------------------- 1 | # author:Shimada666 2 | 3 | from flask import Flask, request, make_response 4 | from httpapi.HTTPSDK import * 5 | 6 | # 配置路由,在插件提交返回中配置地址(如本例 http://127.0.0.1:5000) 7 | # Create your views here. 8 | 9 | app = Flask(__name__) 10 | 11 | 12 | @app.route('/', methods=['GET', 'POST']) 13 | def index(): 14 | req = request.get_data() 15 | sdk = HTTPSDK.httpGet(req) 16 | print(sdk.getMsg()) 17 | 18 | sdk.sendPrivdteMsg(sdk.getMsg().QQ, '你发送了这样的消息:' + sdk.getMsg().Msg) 19 | sdk.getLoginQQ() 20 | 21 | # 回调演示,提交返回获取群列表、登录QQ等 22 | if sdk.isCallback() and sdk.getMsg().Type == HTTPSDK.TYPE_GET_LOGIN_QQ: 23 | print('Login QQ:' + str(sdk.getLoginQQ())) 24 | 25 | return make_response(sdk.toJsonString()) 26 | 27 | 28 | if __name__ == '__main__': 29 | app.run() 30 | -------------------------------------------------------------------------------- /demo/Python/demo-push.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*-coding:utf-8-*- 3 | """ 4 | Demo Push 5 | HTTP-API Python SDK(Python2、python3) 6 | * Created by PyCharm. 7 | * User: yugao 8 | * version 2.2.2 9 | * Note: HTTPSDK for Python(适用于版本2.2.2插件):用于解析插件消息、构造返回数据,以及HTTP推送(发起HTTP请求) 10 | * Contact: 开发者邮箱 admin@ksust.com 11 | * 安装:pip install http-api-sdk 12 | """ 13 | 14 | from httpapi.HTTPSDK import * 15 | 16 | if sys.version_info.major == 2: 17 | reload(sys) # python2请配置相应编码 18 | sys.setdefaultencoding('utf8') 19 | sys.setdefaultencoding('gb18030') 20 | 21 | push = HTTPSDK.httpPush("http://127.0.0.1:8080") 22 | print(push.getGroupList()) 23 | print(push.sendPrivdteMsg('QQ', '你好')) 24 | 25 | forward = HTTPSDK.msgForwardPush('QQ', '授权码') 26 | print(forward.getGroupList()) 27 | print(forward.getLoginQQ()) 28 | print(forward.sendPrivdteMsg('QQ', '你好')) 29 | print(forward.getQQRobotInfo()) 30 | -------------------------------------------------------------------------------- /demo/Python/demo-server.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*-coding:utf-8-*- 3 | """ 4 | Demo Server 5 | HTTP-API Python SDK(Python2、python3) 6 | * Created by PyCharm. 7 | * User: yugao 8 | * version 2.2.2 9 | * Note: HTTPSDK for Python(适用于版本2.2.2插件):用于解析插件消息、构造返回数据,以及HTTP推送(发起HTTP请求) 10 | * Contact: 开发者邮箱 admin@ksust.com 11 | """ 12 | 13 | # 独立demo:https://github.com/ksust/http_api_django_demo 14 | -------------------------------------------------------------------------------- /plugin/HTTP-API.IR.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ksust/HTTP--API/9427015bf8263770c5eb4dd45b7009dc22eb9188/plugin/HTTP-API.IR.dll -------------------------------------------------------------------------------- /plugin/com.ksust.qq.http-api.cpk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ksust/HTTP--API/9427015bf8263770c5eb4dd45b7009dc22eb9188/plugin/com.ksust.qq.http-api.cpk -------------------------------------------------------------------------------- /plugin/com.ksust.qq.http-api.ql.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ksust/HTTP--API/9427015bf8263770c5eb4dd45b7009dc22eb9188/plugin/com.ksust.qq.http-api.ql.dll -------------------------------------------------------------------------------- /plugin/com.ksust.qq.http-api.qyk.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ksust/HTTP--API/9427015bf8263770c5eb4dd45b7009dc22eb9188/plugin/com.ksust.qq.http-api.qyk.dll -------------------------------------------------------------------------------- /resources/appInstall1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ksust/HTTP--API/9427015bf8263770c5eb4dd45b7009dc22eb9188/resources/appInstall1.png -------------------------------------------------------------------------------- /resources/appInstall2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ksust/HTTP--API/9427015bf8263770c5eb4dd45b7009dc22eb9188/resources/appInstall2.png -------------------------------------------------------------------------------- /resources/appList.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ksust/HTTP--API/9427015bf8263770c5eb4dd45b7009dc22eb9188/resources/appList.png -------------------------------------------------------------------------------- /resources/appTest.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ksust/HTTP--API/9427015bf8263770c5eb4dd45b7009dc22eb9188/resources/appTest.png -------------------------------------------------------------------------------- /resources/bindMaster.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ksust/HTTP--API/9427015bf8263770c5eb4dd45b7009dc22eb9188/resources/bindMaster.png -------------------------------------------------------------------------------- /resources/donate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ksust/HTTP--API/9427015bf8263770c5eb4dd45b7009dc22eb9188/resources/donate.png -------------------------------------------------------------------------------- /resources/myAppList.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ksust/HTTP--API/9427015bf8263770c5eb4dd45b7009dc22eb9188/resources/myAppList.png -------------------------------------------------------------------------------- /resources/setting1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ksust/HTTP--API/9427015bf8263770c5eb4dd45b7009dc22eb9188/resources/setting1.png -------------------------------------------------------------------------------- /resources/setting2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ksust/HTTP--API/9427015bf8263770c5eb4dd45b7009dc22eb9188/resources/setting2.png -------------------------------------------------------------------------------- /resources/setting3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ksust/HTTP--API/9427015bf8263770c5eb4dd45b7009dc22eb9188/resources/setting3.png -------------------------------------------------------------------------------- /resources/verifyList.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ksust/HTTP--API/9427015bf8263770c5eb4dd45b7009dc22eb9188/resources/verifyList.png --------------------------------------------------------------------------------