-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
jiangbj
committed
Apr 17, 2020
0 parents
commit fa0334f
Showing
9 changed files
with
291 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# 本文件是代码风格配置文件 | ||
# 最顶层的 EditorConfig 文件 | ||
root = true | ||
# 使用大括号扩展符号匹配多个文件 | ||
[*] | ||
# Unix样式的换行符,换行符以每个文件结尾 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
# 设置默认字符集 | ||
charset = utf-8 | ||
|
||
# 制表符缩进(4空格) | ||
indent_style = space | ||
indent_size = 4 | ||
#表示在行尾是否允许空格 | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# 本文件是git脚本 | ||
# 文件的行尾自动转换。如果是文本文件,则在文件入Git库时,行尾自动转换为LF。如果已经在入Git库中的文件的行尾是GRLF,则文件在入Git库时,不再转换为LF。 | ||
* text=auto | ||
|
||
# Visual Studio自定义 | ||
*.cs diff=csharp | ||
|
||
# MSysgit标准 | ||
*.doc diff=astextplain | ||
*.DOC diff=astextplain | ||
*.docx diff=astextplain | ||
*.DOCX diff=astextplain | ||
*.dot diff=astextplain | ||
*.DOT diff=astextplain | ||
*.pdf diff=astextplain | ||
*.PDF diff=astextplain | ||
*.rtf diff=astextplain | ||
*.RTF diff=astextplain | ||
|
||
# composer 忽略无关文件 (export-ignore 意思是git压缩包 不加入这行内容) | ||
/.github export-ignore | ||
/.travis.yml export-ignore | ||
/.gitattributes export-ignore | ||
/.gitignore export-ignore | ||
/.scrutinizer.yml export-ignore | ||
/.travis.yml export-ignore | ||
/.editorconfig export-ignore | ||
/Demo export-ignore | ||
/demo export-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# 本文件是防止上传git配置文件 | ||
# Windows映像文件缓存 | ||
Thumbs.db | ||
ehthumbs.db | ||
|
||
# 文件夹配置文件 | ||
Desktop.ini | ||
|
||
# 用于文件共享的回收站 | ||
$RECYCLE.BIN/ | ||
|
||
# Windows 安装 文件 | ||
*.cab | ||
*.msi | ||
*.msm | ||
*.msp | ||
|
||
# Windows 快捷方式 | ||
*.lnk | ||
|
||
# ========================= | ||
# 操作系统文件 | ||
# ========================= | ||
|
||
# OSX | ||
# ========================= | ||
|
||
.DS_Store | ||
.AppleDouble | ||
.LSOverride | ||
|
||
# 缩略图 | ||
._* | ||
|
||
#可能出现在卷根目录中的文件 | ||
.DocumentRevisions-V100 | ||
.fseventsd | ||
.Spotlight-V100 | ||
.TemporaryItems | ||
.Trashes | ||
.VolumeIcon.icns | ||
|
||
# 可能在远程AFP共享上创建的目录 | ||
.AppleDB | ||
.AppleDesktop | ||
Network Trash Folder | ||
Temporary Items | ||
.apdisk | ||
|
||
# IDE | ||
/nbproject/ | ||
.idea/ | ||
|
||
# 环境文件 | ||
.uini | ||
ErrorFiles | ||
u.php | ||
logs | ||
# 缓存文件夹 | ||
update/ | ||
application/logs/ | ||
|
||
# 作曲家文件 | ||
/vendor/ | ||
/composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# RobotWebHook | ||
- EN:This is a robot message push, supporting pin and enterprise wechat's robot web hook interface. | ||
- ZH:这是一个机器人消息推送,支持钉钉和企业微信的机器人 web hook 接口。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "carlo/robot-web-hook", | ||
"description": "EN:This is a robot message push, supporting pin and enterprise wechat's robot web hook interface.ZH:这是一个机器人消息推送,支持钉钉和企业微信的机器人 web hook 接口。", | ||
"type": "library", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "carlo", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"keywords": [ | ||
"robot web hook", | ||
"robot-web-hook", | ||
"机器人消息推送", | ||
"钉钉消息推送", | ||
"企业微信消息推送", | ||
"钉钉机器人", | ||
"企业微信机器人" | ||
], | ||
"minimum-stability": "stable", | ||
"require": { | ||
"php": ">=5.4" | ||
}, | ||
"require-dev": { | ||
"php": ">=5.3.7" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"RobotWebHook\\": "src/" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
require_once '../vendor/autoload.php'; | ||
|
||
use \RobotWebHook\Client; | ||
|
||
$a = new Client(); | ||
print_r($a->getConfig()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
<?php | ||
|
||
namespace App\Jobs; | ||
|
||
use Exception; | ||
use GuzzleHttp\Client; | ||
use Illuminate\Support\Facades\Log; | ||
|
||
class BugJob extends Job | ||
{ | ||
protected $exception; | ||
|
||
protected $data = array(); | ||
|
||
protected $company_wechat = array( | ||
'develop' => 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=1f292d89-da72-4821-a12b-efbbadba2750', | ||
'production' => 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=7afa69ff-9dd5-4140-9624-c5260eb3e6f2', | ||
); | ||
|
||
public function __construct(array $exception, array $data = array()) | ||
{ | ||
$this->exception = array_to_object($exception); | ||
$this->exception->code = $this->exception->code ?? '没有code'; | ||
$this->exception->message = $this->exception->message ?? '没有message'; | ||
$this->exception->file = $this->exception->file ?? '没有file'; | ||
$this->exception->line = $this->exception->line ?? '没有line'; | ||
$this->data['env'] = $data['env'] ?? 'develop'; | ||
$this->data['msg_type'] = $data['msg_type'] ?? 'markdown'; | ||
$this->data['app_name'] = '小程序'; | ||
$this->data["mentioned_list"] = $data["mentioned_list"] ?? []; | ||
$this->data["mentioned_mobile_list"] = $data["mentioned_mobile_list"] ?? []; | ||
|
||
} | ||
|
||
/** | ||
* Execute the job. | ||
* | ||
* @return void | ||
*/ | ||
public function handle() | ||
{ | ||
|
||
try { | ||
call_user_func_array(array(__CLASS__, $this->data['msg_type']), []); | ||
} catch (Exception $e) { | ||
Log::info('bug消息推送异常:', array( | ||
'message' => $e->getMessage(), | ||
'code' => $e->getCode(), | ||
'file' => $e->getFile(), | ||
'line' => $e->getLine() | ||
)); | ||
} | ||
} | ||
|
||
function text() | ||
{ | ||
$data = array( | ||
"content" => "异常警告:\n" . print_r(array( | ||
'app_name' => $this->data['app_name'], | ||
'env' => $this->data['env'], | ||
'code' => $this->exception->code, | ||
'message' => $this->exception->message, | ||
'file' => $this->exception->file, | ||
'line' => $this->exception->line, | ||
), true) | ||
); | ||
$this->data["mentioned_list"] && $data["mentioned_list"] = $this->data["mentioned_list"]; | ||
$this->data["mentioned_mobile_list"] && $data["mentioned_mobile_list"] = $this->data["mentioned_mobile_list"]; | ||
$this->push(array( | ||
"msgtype" => "text", | ||
"text" => $data | ||
)); | ||
} | ||
|
||
function markdown() | ||
{ | ||
$this->push(array( | ||
'msgtype' => 'markdown', | ||
'markdown' => array( | ||
'content' => " | ||
### app_name:<font color='warning'>{$this->data['app_name']}</font>\n | ||
>env:<font color='comment'>{$this->data['env']}</font> | ||
>file:<font color='comment'>" . get_good_str($this->exception->file) . "</font> | ||
>line:<font color='comment'>{$this->exception->line}</font> | ||
>code:<font color='comment'>{$this->exception->code}</font> | ||
>message:<font color='comment'>" . get_good_str($this->exception->message) . "</font>" | ||
) | ||
)); | ||
} | ||
|
||
function push($data) | ||
{ | ||
|
||
if (isset($this->data['env']) && $this->data['env'] === 'production') { | ||
$uri = $this->company_wechat[$this->data['env']]; | ||
} else { | ||
$uri = $this->company_wechat['develop']; | ||
} | ||
|
||
$client = new Client(array('timeout' => 30)); | ||
$client->request( | ||
'POST', | ||
$uri, | ||
array( | ||
'json' => $data, | ||
'headers' => array( | ||
'Accept' => '*/*', | ||
'Content-Type' => 'application/json' | ||
), | ||
) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
|
||
namespace RobotWebHook; | ||
|
||
|
||
class Client | ||
{ | ||
private $config = array(); | ||
|
||
public function __construct($config=array()) | ||
{ | ||
$default_config = include_once(__DIR__ . '/config/config.php'); | ||
$this->config = array_merge($config,$default_config); | ||
} | ||
|
||
public function getConfig(){ | ||
return $this->config; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?php | ||
return array( | ||
'uri' => 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=1f292d89-da72-4821-a12b-efbbadba2750' | ||
); |