no message

SPY×FAMILY
鹿和sa0ChunLuyu 4 years ago
parent 01ceafe255
commit 267b65fbbb

3
.gitignore vendored

@ -0,0 +1,3 @@
.idea
.DS_Store
config.ini

@ -0,0 +1,9 @@
MIT License
Copyright (c) <year> <copyright holders>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

@ -0,0 +1,3 @@
# 鹿和开发套件 PHP 机器人
LuCodePhpBot

@ -0,0 +1,20 @@
<?php
namespace Workerman\Lib;
use Workerman\Worker;
$bot_loop = new Worker();
$bot_loop->count = 1;
$bot_loop->name = "LuCodePhpBot";
function BotFunc()
{
$db = Db::get();
$info = $db->getRow('select * from admin where id = 1');
var_dump($info);
}
$bot_loop->onWorkerStart = function () {
Timer::add(2, function () {
BotFunc();
});
};

@ -1,22 +0,0 @@
<?php
use Workerman\Worker;
use \Workerman\Lib\Timer;
use \Workerman\Lib\Tool;
$bot_loop = new Worker();
$bot_loop->count = 1;
$bot_loop->name = "2秒后自动触发";
function BotFunc()
{
$res = Tool::post('http://code.dev.sa0.online:88/api/yo', []);
var_dump($res);
}
$bot_loop->onWorkerStart = function () {
BotFunc();
Timer::add(2, function () {
BotFunc();
});
};

@ -0,0 +1,6 @@
AppName = 鹿和开发套件
MainDbName = example
MainDbUser = example
MainDbPassword = example
MainDbHost = example.com:3306

@ -1,26 +0,0 @@
<?php
use Workerman\Worker;
use \Workerman\Lib\Timer;
use \Workerman\Lib\Tool;
$bot_loop = new Worker();
$bot_loop->count = 1;
$bot_loop->name = "每10秒自动触发";
$loop = 10;
$time = time() - $loop;
function BotFunc($loop, &$time)
{
if (time() - $time >= $loop) {
$res = Tool::post('http://code.dev.sa0.online:88/api/yo', []);
var_dump($res);
$time = $time + $loop;
}
}
$bot_loop->onWorkerStart = function () use ($loop, &$time) {
BotFunc($loop, $time);
Timer::add(2, function () use ($loop, &$time) {
BotFunc($loop, $time);
});
};

@ -1,22 +0,0 @@
<?php
use Workerman\Worker;
use \Workerman\Lib\Timer;
use \Workerman\Lib\Tool;
$bot_loop = new Worker();
$bot_loop->count = 1;
$bot_loop->name = "2秒后自动触发";
function BotFunc()
{
$res = Tool::post('http://code.dev.sa0.online:88/api/yo', []);
var_dump($res);
}
$bot_loop->onWorkerStart = function () {
BotFunc();
Timer::add(2, function () {
BotFunc();
});
};

@ -1,26 +0,0 @@
<?php
use Workerman\Worker;
use \Workerman\Lib\Timer;
use \Workerman\Lib\Tool;
$bot_loop = new Worker();
$bot_loop->count = 1;
$bot_loop->name = "到达规定时间自动触发";
$loop = 10;
$time = strtotime(date('Y-m-d') . ' 20:21:00');
function BotFunc($loop, &$time)
{
if (time() - $time >= 0) {
$res = Tool::post('http://code.dev.sa0.online:88/api/yo', []);
var_dump($res);
$time = $time + $loop;
}
}
$bot_loop->onWorkerStart = function () use ($loop, &$time) {
BotFunc($loop, $time);
Timer::add(2, function () use ($loop, &$time) {
BotFunc($loop, $time);
});
};

File diff suppressed because it is too large Load Diff

@ -10,8 +10,9 @@ use Workerman\Worker;
date_default_timezone_set('Asia/Shanghai');
require_once "workerman/Autoloader.php";
\Workerman\Autoloader::setRootPath(__DIR__);
if (!extension_loaded('pcntl')) exit("Please install pcntl extension. See http://doc3.workerman.net/install/install.html\n");
if (!extension_loaded('posix')) exit("Please install posix extension. See http://doc3.workerman.net/install/install.html\n");
//if (!extension_loaded('pcntl')) exit("Please install pcntl extension. See http://doc3.workerman.net/install/install.html\n");
//if (!extension_loaded('posix')) exit("Please install posix extension. See http://doc3.workerman.net/install/install.html\n");
$config = [];
$config['workerman']['pidFile'] = __DIR__ . '/logs/workerman.pid';
$config['workerman']['logFile'] = __DIR__ . '/logs/workerman.log';

@ -0,0 +1,140 @@
<?php
namespace Workerman\Lib;
class Db
{
public $db;
private static $instance = array();
public function __construct($data)
{
$dsn = "mysql:dbname=" . $data['dbname'] . ";host=" . $data['dbhost'];
$this->db = new \PDO($dsn, $data['dbuser'], $data['dbpassword']);
$this->db->query('set character set utf8mb4;');
$this->db->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
}
public static function get($key = 'Main'): Db
{
$database['dbname'] = Tool::ini($key . 'DbName');
$database['dbuser'] = Tool::ini($key . 'DbUser');
$database['dbpassword'] = Tool::ini($key . 'DbPassword');
$database['dbhost'] = Tool::ini($key . 'DbHost');
if (!isset(self::$instance[$database['dbname']]) || !self::$instance[$database['dbname']] instanceof self) {
self::$instance[$database['dbname']] = new Db($database);
} else {
try {
//断线重连
self::$instance[$database['dbname']]->db->getAttribute(\PDO::ATTR_SERVER_INFO);
} catch (\PDOException $e) {
if (strpos($e->getMessage(), 'MySQL server has gone away') !== false) {
self::$instance[$database['dbname']] = new Db($database);
}
}
}
return self::$instance[$database['dbname']];
}
/*********PDO**********/
public function count($sql, $parameters = null): int
{
return $this->exeupdate($sql, $parameters);
}
public function querysql($sql, $parameters = null)
{
return $this->exeupdate($sql, $parameters);
}
public function querysqlinsertid($sql, $parameters = null)
{
if ($this->exeupdate($sql, $parameters)) {
return $this->db->lastInsertId();
} else {
return 0;
}
}
public function getRow($sql, $parameters = null)
{
$res = $this->exequery($sql, $parameters);
if (count($res) > 0) {
return $res[0];
} else {
return array();
}
}
public function getAll($sql, $parameters = null)
{
$res = $this->exequery($sql, $parameters);
if (count($res) > 0) {
return $res;
} else {
return array();
}
}
public function beginTransaction()
{
$this->db->beginTransaction();
}
public function rollback()
{
$this->db->rollback();
}
public function commit()
{
$this->db->commit();
}
public function exequery($sql, $parameters = null)
{
$conn = $this->db;
$stmt = $conn->prepare($sql);
$stmt->execute($parameters);
$rs = $stmt->fetchall(\PDO::FETCH_ASSOC);
$stmt = null;
$conn = null;
return $rs;
}
public function exeupdate($sql, $parameters = null)
{
$stmt = $this->db->prepare($sql);
$stmt->execute($parameters);
$affectedrows = $stmt->rowcount();
$stmt = null;
$conn = null;
return $affectedrows;
}
public function checklink()
{
$res = $this->db->getAttribute(\PDO::ATTR_SERVER_INFO);
if (strpos($res, 'server has gone away') !== false) {
$this->db = null;
return false;
} else {
return true;
}
}
public function getinsertid()
{
return $this->db->lastInsertId();
}
public function close()
{
return $this->db = null;
}
}

@ -0,0 +1,43 @@
<?php
namespace Workerman\Lib;
class Db2
{
public static function i($db, $table, $array)
{
$insertArr = array();
$sql = "insert into `{$table}`(";
$sql1 = 'values(';
foreach ($array as $key => $value) {
$sql .= "`{$key}`,";
$sql1 .= "?,";
$insertArr[] = $value;
}
$sql = trim($sql, ',');
$sql1 = trim($sql1, ',');
$sql .= ")" . $sql1 . ")";
$db->querysql($sql, $insertArr);
return $db->getinsertid();
}
public static function u($db, $table, $array, $where, $where_a = [])
{
$updateArr = array();
$sql = "update `{$table}` set ";
foreach ($array as $key => $value) {
$sql .= "`{$key}`=?,";
$updateArr[] = $value;
}
$sql = trim($sql, ',');
$where = ' ' . $where;
$sql .= $where;
$updateArr = array_merge($updateArr, $where_a);
return $db->querysql($sql, $updateArr);
}
public static function d($db, $table, $where, $where_a = [])
{
$sql = "delete from `{$table}` " . $where;
$db->querysql($sql, $where_a);
}
}

@ -1,24 +1,25 @@
<?php
namespace Workerman\Lib;
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2019/6/13
* Time: 17:14
* ***************
* 备注
* ***************
* Come on
*/
class Tool
{
// region 获取 UUID
public static function uuid($break = '-'): string
{
$chars = md5(uniqid(mt_rand(), true));
$chars_arr = [
substr($chars, 0, 8),
substr($chars, 8, 4),
substr($chars, 12, 4),
substr($chars, 16, 4),
substr($chars, 20, 12),
];
return implode($break, $chars_arr);
}
// endregion
/*
* http CURL POST
*
*/
public static function post($url, $data, $type = 'json')
// region 发送POST请求
public static function post($url, $data = [], $decode = true, $type = 'json')
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
@ -39,6 +40,44 @@ class Tool
}
$r = curl_exec($curl);
curl_close($curl);
return $r;
if ($decode) {
return json_decode($r, true);
} else {
return $r;
}
}
// endregion
// region 读取 Config ini
public static function ini($key, $default = false)
{
if (!$key) return $default;
$config_file_path = dirname(__DIR__, 2) . '/config.ini';
$config_info = parse_ini_file($config_file_path);
return (isset($config_info[$key])) ? $config_info[$key] : $default;
}
// endregion
// region 10位时间戳 格式化
public static function date($time = false, $format = "Y-m-d H:i:s")
{
if (!$time) $time = time();
return date($format, $time);
}
// endregion
// region 去除空格
public static function ge($str)
{
return preg_replace("/\s+/", ' ', $str);
}
// endregion
// region 毫秒时间戳
public static function time()
{
return floor(microtime(true) * 1000);
}
// endregion
}
Loading…
Cancel
Save