Files
zhamao-framework/src/cqbot/connection/NullConnection.php
2018-11-28 13:26:18 +08:00

37 lines
1.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* Created by PhpStorm.
* User: jerry
* Date: 2018/11/18
* Time: 11:11 AM
*/
class NullConnection extends WSConnection
{
private $qq = 0;
public function __construct(swoole_websocket_server $server, $fd, $remote, $qq = 0) {
parent::__construct($server, $fd, $remote);
$this->qq = $qq;
}
public function push($data, $push_error_record = true) {
$data = unicodeDecode($data);
CQUtil::errorlog("API推送失败未发送的消息: \n" . $data, "API ERROR", false);
if ($push_error_record) Cache::append("bug_msg_list", json_decode($data, true));
return false;
}
public function sendAPI($api, $params = [], $echo = []){
$data["action"] = $api;
if($params != []) $data["params"] = $params;
$echo_result["self_id"] = $this->qq;
if($echo != []){
if(count($echo) >= 1) $echo_result['type'] = array_shift($echo);
if(!empty($echo)) $echo_result["params"] = $echo;
}
$data["echo"] = $echo_result;
Console::debug("将要发送的API包" . json_encode($data, 128 | 256));
return $this->push(json_encode($data));
}
}