Compare commits

...

9 Commits
1.5 ... 1.5.2

Author SHA1 Message Date
whale
c0ea068d04 update to 1.5.2 version
add ZM_VERSION const
2020-06-08 23:52:55 +08:00
whale
9ba58ff90f remove ModBase to default Module 2020-06-05 19:54:20 +08:00
whale
1a1cf0ad30 update to 1.5.1 version 2020-06-05 19:31:43 +08:00
whale
1de93b9dc1 update to 1.5.1 version
fix a warning bug
2020-06-05 19:31:18 +08:00
Whale
99e44eea3d Merge pull request #12 from 854854321/patch-1
Update ZMRequest.php
2020-06-05 19:25:20 +08:00
Whale
e67958a8d1 Update ZMRequest.php 2020-06-05 19:24:56 +08:00
Whale
23b3dc34e2 Merge pull request #11 from 854854321/master
Update README.md
2020-06-05 18:51:52 +08:00
775672d515 Update ZMRequest.php
增加了http请求 传输 数据体
2020-06-05 18:31:55 +08:00
40e17fab62 Update README.md 2020-06-05 16:02:13 +08:00
8 changed files with 46 additions and 11 deletions

View File

@@ -84,6 +84,6 @@ Pages托管[https://framework.zhamao.xin/](https://framework.zhamao.xin/)
欢迎随时在 HTTP-API 插件群里提问,当然更好的话可以加作者 QQ627577391或提交 Issue 进行疑难解答。
本项目在更内容时,请及时关注 GitHub 动态,更新前请将自己的模块代码做好备份。
本项目在更内容时,请及时关注 GitHub 动态,更新前请将自己的模块代码做好备份。
项目框架采用 Apache-2.0 协议开源,在分发或重写修改等操作时需遵守协议。项目模块部分(`Module` 文件夹) 在非借鉴框架内代码时可不遵守 Apache-2.0 协议进行分发和修改(声明版权)。

View File

@@ -1,9 +1,9 @@
{
"name": "zhamao/framework",
"description": "high-performance intelligent assistant",
"description": "High performance QQ robot and web server development framework",
"minimum-stability": "stable",
"license": "Apache-2.0",
"version": "1.5",
"version": "1.5.2",
"authors": [
{
"name": "whale",

View File

@@ -100,7 +100,7 @@ class FrameworkLoader
"host: " . self::$settings->get("host") .
", port: " . self::$settings->get("port") .
", log_level: " . ZMBuf::$atomics["info_level"]->get() .
", version: " . json_decode(file_get_contents(WORKING_DIR . "/composer.json"), true)["version"] .
", version: " . ZM_VERSION .
"\nworking_dir: " . DataProvider::getWorkingDir()
);
global $motd;
@@ -130,6 +130,7 @@ class FrameworkLoader
private function defineProperties() {
define("ZM_START_TIME", microtime(true));
define("ZM_DATA", self::$settings->get("zm_data"));
define("ZM_VERSION", json_decode(file_get_contents(__DIR__."/../../composer.json"), true)["version"] ?? "unknown");
define("CONFIG_DIR", self::$settings->get("config_dir"));
define("CRASH_DIR", self::$settings->get("crash_dir"));
@mkdir(ZM_DATA);

View File

@@ -222,3 +222,5 @@ function zm_timer_tick($ms, callable $callable) {
}

View File

@@ -10,7 +10,6 @@ use ZM\Annotation\Http\Middleware;
use ZM\Annotation\Http\RequestMapping;
use ZM\Annotation\Swoole\SwooleEventAt;
use ZM\Connection\CQConnection;
use ZM\ModBase;
use ZM\Utils\ZMUtil;
/**
@@ -18,7 +17,7 @@ use ZM\Utils\ZMUtil;
* @package Module\Example
* @since 1.0
*/
class Hello extends ModBase
class Hello
{
/**
* 在机器人连接后向终端输出信息

View File

@@ -38,7 +38,7 @@ class MessageEvent
* @throws AnnotationException
*/
public function onBefore() {
$obj_list = ZMBuf::$events[CQBefore::class]["message"];
$obj_list = ZMBuf::$events[CQBefore::class]["message"] ?? [];
foreach ($obj_list as $v) {
if($v->level < 200) break;
EventHandler::callWithMiddleware(

View File

@@ -27,6 +27,7 @@ class ZMRequest
Console::warning("ZMRequest: url must contains scheme such as \"http(s)\"");
return false;
}
if(!isset($parse["path"])) $parse["path"] = "/";
$port = $parse["port"] ?? (($parse["scheme"] ?? "http") == "https" ? 443 : 80);
$cli = new Client($parse["host"], $port, (($parse["scheme"] ?? "http") == "https" ? true : false));
$cli->setHeaders($headers);
@@ -60,6 +61,7 @@ class ZMRequest
Console::warning("ZMRequest: url must contains scheme such as \"http(s)://\"");
return false;
}
if(!isset($parse["path"])) $parse["path"] = "/";
$port = $parse["port"] ?? (($parse["scheme"] ?? "http") == "https" ? 443 : 80);
$cli = new Client($parse["host"], $port, (($parse["scheme"] ?? "http") == "https" ? true : false));
$cli->set($set == [] ? ['timeout' => 15.0] : $set);
@@ -94,4 +96,34 @@ class ZMRequest
public static function session($option) {
return Saber::session($option);
}
public static function request($url, $attribute = [], $return_body = true) {
$parse = parse_url($url);
if (!isset($parse["host"])) {
Console::warning("ZMRequest: url must contains scheme such as \"http(s)://\"");
return false;
}
if(!isset($parse["path"])) $parse["path"] = "/";
$port = $parse["port"] ?? (($parse["scheme"] ?? "http") == "https" ? 443 : 80);
$cli = new Client($parse["host"], $port, (($parse["scheme"] ?? "http") == "https" ? true : false));
$cli->set($attribute["set"] ?? ["timeout" => 15.0]);
$cli->setMethod($attribute["method"] ?? "GET");
$cli->setHeaders($attribute["headers"] ?? []);
if(isset($attribute["data"])) $cli->setData($attribute["data"]);
if(isset($attribute["file"])) {
foreach($attribute["file"] as $k => $v) {
$cli->addFile($v["path"], $v["name"], $v["mime_type"] ?? null, $v["filename"] ?? null, $v["offset"] ?? 0, $v["length"] ?? 0);
}
}
$cli->execute($parse["path"] . (isset($parse["query"]) ? "?" . $parse["query"] : ""));
if ($return_body) {
if ($cli->errCode != 0 || $cli->statusCode != 200) return false;
$a = $cli->body;
$cli->close();
return $a;
} else {
$cli->close();
return $cli;
}
}
}

View File

@@ -29,6 +29,7 @@ class ZMWebSocket
Console::warning("ZMRequest: url must contains scheme such as \"ws(s)://\"");
return;
}
if (!isset($this->parse["path"])) $this->parse["path"] = "/";
$port = $this->parse["port"] ?? (($this->parse["scheme"] ?? "ws") == "wss" ? 443 : 80);
$this->client = new Client($this->parse["host"], $port, (($this->parse["scheme"] ?? "ws") == "wss" ? true : false));
$this->client->set($set);
@@ -85,18 +86,18 @@ class ZMWebSocket
}
}
if(!debug_backtrace()) {
if (!debug_backtrace()) {
go(function () {
require_once __DIR__ . "/../../Framework/Console.php";
$cli = new ZMWebSocket("ws://127.0.0.1:20001/");
if (!$cli->is_available) die("Error!\n");
$cli->onMessage(function ($frame){
$cli->onMessage(function (Frame $frame) {
var_dump($frame);
});
$cli->onClose(function($client){
$cli->onClose(function () {
echo "Connection closed.\n";
});
if($cli->upgrade()){
if ($cli->upgrade()) {
echo "成功连接!\n";
} else {
echo "连接失败!\n";