Compare commits

..

25 Commits
v0.1 ... main

Author SHA1 Message Date
xAmast
80bb352dea feat: remove repositories 2024-06-12 20:54:44 +08:00
董巍
d588a7d108 Merge branch 'feature/notify_file' into 'master'
发送文件消息

See merge request composer/php-alert-client!5
2019-07-15 10:41:21 +08:00
侯登峰
c02656e435 发送文件消息 2019-07-12 18:20:27 +08:00
董巍
4133ce2995 Merge branch 'feature/rpc_alert' into 'master'
alert 请求实体机器

See merge request composer/php-alert-client!4
2019-07-11 15:34:03 +08:00
lisida
eb92fe8e8b alert 请求实体机器 2019-07-11 15:33:19 +08:00
董巍
3d7d02f353 Merge branch 'feature/rpc_alert' into 'master'
Feature/rpc alert

See merge request composer/php-alert-client!3
2019-07-10 18:55:56 +08:00
lisida
f6ed2277fa Merge branch 'master' into feature/rpc_alert 2019-07-10 18:55:19 +08:00
lisida
1534831332 alert 2019-07-10 18:55:07 +08:00
董巍
029c02969b Merge branch 'feature/rpc_alert' into 'master'
地址

See merge request composer/php-alert-client!2
2019-07-10 18:37:54 +08:00
lisida
74f2959272 地址 2019-07-10 18:37:13 +08:00
dongwei
80655ac74d remove log 2019-07-03 14:28:47 +08:00
dongwei
b494903dfd log exception and return null 2019-07-03 14:10:37 +08:00
候学杰
c9b502ac38 no message 2019-07-02 16:41:17 +08:00
候学杰
9791b6dcfd add test 2019-07-02 16:37:27 +08:00
候学杰
d6d53ec544 new function 2019-07-02 16:33:40 +08:00
候学杰
3b8ec334de Merge branch 'feature/rpc' into 'master'
composer update

See merge request composer/php-alert-client!1
2019-02-26 13:16:30 +08:00
lisida
ff69dacdb2 composer update 2019-02-26 13:11:55 +08:00
候学杰
9731b0c374 Merge branch 'feature/rpc_alert' of git.int.haowumc.com:composer/php-alert-client 2019-02-26 13:04:25 +08:00
lisida
338e38825b alert 2019-02-25 11:27:28 +08:00
董巍
b4e3b70d70 Update README.md 2019-02-25 11:25:19 +08:00
董巍
0c1b5deba0 Update composer.json 2019-02-25 11:25:00 +08:00
董巍
a155f52333 Update README.md 2019-02-25 11:24:06 +08:00
候学杰
cf9591a0b5 card message 2019-01-02 15:17:32 +08:00
候学杰
1107190667 Merge branch 'master' of git.int.haowumc.com:arch/php-alert-client
# Conflicts:
#	src/functions.php
2018-12-21 18:34:43 +08:00
候学杰
df257386c7 更改api 地址 2018-12-21 18:28:50 +08:00
9 changed files with 327 additions and 1250 deletions

View File

@ -4,8 +4,8 @@
执行
```bash
composer config repositories.php-alert vcs git@git.int.haowumc.com:arch/php-alert-client.git
composer require arch/alert
composer config repositories.php-alert vcs git@git.int.haowumc.com:composer/php-alert-client.git
composer require paidian/work-wx-alert
```

View File

@ -1,5 +1,5 @@
{
"name": "arch/alert",
"name": "paidian/work-wx-alert",
"authors": [
{
"name": "候学杰",
@ -12,12 +12,6 @@
]
},
"require": {
"arch/php-internal-api-client": "^0.6.1"
},
"repositories": {
"php-internal-api-client": {
"type": "vcs",
"url": "git@git.int.haowumc.com:arch/php-internal-api-client.git"
}
"paidian/json-rpc": "~1.1"
}
}

1214
composer.lock generated

File diff suppressed because it is too large Load Diff

BIN
docs/robot-image.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

BIN
docs/robot-markdown.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 140 KiB

BIN
docs/robot-news.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 181 KiB

BIN
docs/robot-text.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

View File

@ -1,29 +1,37 @@
<?php
define('CRM_API_CONFIG', [
'base_uri' => 'http://crm.in.haowumc.com/api/wechat/',
'appid' => 'notification',
'secret' => '123456',
define('RPC_CONFIG', [
'app' => env('APP_NAME'),
'client' => [
'auth' => [
'base_uri' => 'http://auth.in.haowumc.com',
],
],
]);
/**
* 对企业微信群发送报警信息(需先创建
*
* @param $chat
* @param $text
*
* @return mixed|null
*/
function chat_text_alert($chat, $text){
$client = new \PdInternalApi\Client('crm', CRM_API_CONFIG);
function chat_text_alert ($chat, $text)
{
if (env('APP_ENV') == 'local') {
return true;
}
$base_client = new \JsonRpc\Client(RPC_CONFIG);
$client = $base_client->endpoint('auth');
try {
$resp = $client->call('work/text', [
'chat_id' => $chat,
'text' => $text,
$resp = $client->call('notify.text', [
['chat' => $chat],
$text,
]);
} catch (Exception $ex) {
var_dump($ex->getMessage());
return null;
}
@ -32,22 +40,302 @@ function chat_text_alert($chat, $text){
/**
* 对单个或多个用户发送报警或通知信息多个用户id使用 | 隔开
* @param $username
*
* @param $text
*
* @return mixed|null
*/
function user_text_alert($username, $text){
$client = new \PdInternalApi\Client('crm', CRM_API_CONFIG);
function user_text_alert ($username, $text)
{
if (env('APP_ENV') == 'local') {
return true;
}
$base_client = new \JsonRpc\Client(RPC_CONFIG);
$client = $base_client->endpoint('auth');
$username = explode('|', $username);
try {
$resp = $client->call('work/text', [
'username' => $username,
'text' => $text,
$res = $client->call('notify.text', [
['user' => $username],
$text,
]);
} catch (Exception $ex) {
return null;
}
return $res;
}
/**
* 对微信群发送文本卡片
*
* @param $chat
* @param $title
* @param $desc
* @param $button
* @param $url
*
* @return mixed|null
*/
function chat_card_alert ($chat, $title, $desc, $button, $url)
{
if (env('APP_ENV') == 'local') {
return true;
}
$base_client = new \JsonRpc\Client(RPC_CONFIG);
$client = $base_client->endpoint('auth');
try {
$resp = $client->call('notify.card', [
['chat' => $chat],
$title,
$desc,
$button,
$url,
]);
} catch (Exception $ex) {
var_dump($ex->getMessage());
return null;
}
return $resp;
}
/**
* 对单个或多个用户发送文本卡片多个用户id使用 | 隔开
*
* @param $username
* @param $title
* @param $desc
* @param $button
* @param $url
*
* @return mixed|null
*/
function user_card_alert ($username, $title, $desc, $button, $url)
{
if (env('APP_ENV') == 'local') {
return true;
}
$base_client = new \JsonRpc\Client(RPC_CONFIG);
$client = $base_client->endpoint('auth');
$username = explode('|', $username);
try {
$resp = $client->call('notify.card', [
['user' => $username],
$title,
$desc,
$button,
$url,
]);
} catch (Exception $ex) {
return null;
}
return $resp;
}
/**
* 对单个或多个用户发送文本卡片多个用户id使用 | 隔开
*
* @param $username
* @param $appid //小程序的appid
* @param $title //标题
* @param $page //小程序页面路径
* @param $desc //描述
* @param $items //消息内容键值对最多允许10个item
* @param $emphasisFirstItem //是否放大第一个content_item
*
* @return mixed|null
*/
function user_mp_alert ($username, $appid, $title, $page = null, $desc = null, $items = null, $emphasisFirstItem = null)
{
if (env('APP_ENV') == 'local') {
return true;
}
$base_client = new \JsonRpc\Client(RPC_CONFIG);
$client = $base_client->endpoint('auth');
$username = explode('|', $username);
try {
$resp = $client->call('notify.mp', [
['user' => $username],
$appid,
$title,
$page,
$desc,
$items,
$emphasisFirstItem
]);
} catch (Exception $ex) {
return null;
}
return $resp;
}
/**
* 对单个或多个用户发送文本卡片多个用户id使用 | 隔开
*
* @param $username
* @param $appid //小程序的appid
* @param $title //标题
* @param $page //小程序页面路径
* @param $desc //描述
* @param $items //消息内容键值对最多允许10个item
* @param $emphasisFirstItem //是否放大第一个content_item
*
* @return mixed|null
*/
function tag_mp_alert ($tag, $appid, $title, $page = null, $desc = null, $items = null, $emphasisFirstItem = null)
{
if (env('APP_ENV') == 'local') {
return true;
}
$base_client = new \JsonRpc\Client(RPC_CONFIG);
$client = $base_client->endpoint('auth');
try {
$resp = $client->call('notify.mp', [
['tag' => $tag],
$appid,
$title,
$page,
$desc,
$items,
$emphasisFirstItem
]);
} catch (Exception $ex) {
return null;
}
return $resp;
}
/**
* 机器人通知
*
* $content = [
* 'msgtype' => 'text',
* 'text' => [
* 'content' => '!',
* ]
* ];
*
* @param $name
* @param $content
* @return array|mixed
* @throws Exception
*/
function bot_notify($name, $content)
{
switch ($name) {
case 'inventory':
$uri = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=20a40b87-7bb9-4bcf-bd38-6612377d0970';
break;
case 'test':
$uri = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=757bcb2d-913c-4ab6-9395-bfa45f488f68';
break;
default:
throw new Exception('bot name not found!');
}
$client = new \GuzzleHttp\Client();
$option['json'] = $content;
$resp = $client->request('POST', $uri, $option);
if ($resp->getStatusCode() == 200) {
return json_decode($resp->getBody(), true);
} else {
return [];
}
}
/**
* 对单个或多个用户发送报警或通知图片多个用户id使用 | 隔开
*
* @param $media_id
*
* @return mixed|null
*/
function user_image_alert ($username, $media_id)
{
if (env('APP_ENV') == 'local') {
return true;
}
$base_client = new \JsonRpc\Client(RPC_CONFIG);
$client = $base_client->endpoint('auth');
$username = explode('|', $username);
try {
$res = $client->call('notify.image', [
['user' => $username],
$media_id,
]);
} catch (Exception $ex) {
return null;
}
return $res;
}
/**
* 对企业微信群发送报警图片(需先创建
*
* @param $chat
* @param $media_id
*
* @return mixed|null
*/
function chat_image_alert ($chat, $media_id)
{
if (env('APP_ENV') == 'local') {
return true;
}
$base_client = new \JsonRpc\Client(RPC_CONFIG);
$client = $base_client->endpoint('auth');
try {
$resp = $client->call('notify.image', [
['chat' => $chat],
$media_id,
]);
} catch (Exception $ex) {
return null;
}
return $resp;
}
/**
* 对企业微信群发送报警文件(需先创建
*
* @param $chat
* @param $media_id
*
* @return mixed|null
*/
function chat_file_alert ($chat, $media_id)
{
if (env('APP_ENV') == 'local') {
return true;
}
$base_client = new \JsonRpc\Client(RPC_CONFIG);
$client = $base_client->endpoint('auth');
try {
$resp = $client->call('notify.file', [
['chat' => $chat],
$media_id,
]);
} catch (Exception $ex) {
return null;
}
return $resp;
}

View File

@ -5,11 +5,20 @@ ini_set('display_errors', 'stderr');
require_once dirname(__DIR__).'/vendor/autoload.php';
$ret = user_text_alert('xieshi','dfdfdf');
var_dump($ret);
if( $ret['err_code'] == '0' ){
echo "发送成功\n";
}else{
echo "发送失败,原因{$ret['err_msg']}\n";
}
//$ret = chat_card_alert('szjesh','dfdfdf');
//var_dump($ret);
//if( $ret['err_code'] == '0' ){
// echo "发送成功\n";
//}else{
// echo "发送失败,原因{$ret['err_msg']}\n";
//}
$content = [
'msgtype' => 'text',
'text' => [
'content' => '!',
]
];
bot_notify('inventory',$content);