Compare commits
25 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
80bb352dea | ||
![]() |
d588a7d108 | ||
![]() |
c02656e435 | ||
![]() |
4133ce2995 | ||
![]() |
eb92fe8e8b | ||
![]() |
3d7d02f353 | ||
![]() |
f6ed2277fa | ||
![]() |
1534831332 | ||
![]() |
029c02969b | ||
![]() |
74f2959272 | ||
![]() |
80655ac74d | ||
![]() |
b494903dfd | ||
![]() |
c9b502ac38 | ||
![]() |
9791b6dcfd | ||
![]() |
d6d53ec544 | ||
![]() |
3b8ec334de | ||
![]() |
ff69dacdb2 | ||
![]() |
9731b0c374 | ||
![]() |
338e38825b | ||
![]() |
b4e3b70d70 | ||
![]() |
0c1b5deba0 | ||
![]() |
a155f52333 | ||
![]() |
cf9591a0b5 | ||
![]() |
1107190667 | ||
![]() |
df257386c7 |
|
@ -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
|
||||
```
|
||||
|
||||
|
||||
|
|
|
@ -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
1214
composer.lock
generated
File diff suppressed because it is too large
Load Diff
BIN
docs/robot-image.jpg
Normal file
BIN
docs/robot-image.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 59 KiB |
BIN
docs/robot-markdown.jpg
Normal file
BIN
docs/robot-markdown.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 140 KiB |
BIN
docs/robot-news.jpg
Normal file
BIN
docs/robot-news.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 181 KiB |
BIN
docs/robot-text.jpg
Normal file
BIN
docs/robot-text.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 88 KiB |
|
@ -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,20 +40,300 @@ 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) {
|
||||
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) {
|
||||
var_dump($ex->getMessage());
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
Loading…
Reference in New Issue
Block a user