Compare commits
No commits in common. "main" and "v0.3" have entirely different histories.
|
@ -13,5 +13,11 @@
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"paidian/json-rpc": "~1.1"
|
"paidian/json-rpc": "~1.1"
|
||||||
|
},
|
||||||
|
"repositories": {
|
||||||
|
"php-json-rpc": {
|
||||||
|
"type": "vcs",
|
||||||
|
"url": "git@git.int.haowumc.com:composer/php-json-rpc.git"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
1580
composer.lock
generated
Normal file
1580
composer.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Before Width: | Height: | Size: 59 KiB |
Binary file not shown.
Before Width: | Height: | Size: 140 KiB |
Binary file not shown.
Before Width: | Height: | Size: 181 KiB |
Binary file not shown.
Before Width: | Height: | Size: 88 KiB |
|
@ -32,6 +32,7 @@ function chat_text_alert ($chat, $text)
|
||||||
$text,
|
$text,
|
||||||
]);
|
]);
|
||||||
} catch (Exception $ex) {
|
} catch (Exception $ex) {
|
||||||
|
var_dump($ex->getMessage());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,6 +61,7 @@ function user_text_alert ($username, $text)
|
||||||
$text,
|
$text,
|
||||||
]);
|
]);
|
||||||
} catch (Exception $ex) {
|
} catch (Exception $ex) {
|
||||||
|
var_dump($ex->getMessage());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,6 +97,7 @@ function chat_card_alert ($chat, $title, $desc, $button, $url)
|
||||||
$url,
|
$url,
|
||||||
]);
|
]);
|
||||||
} catch (Exception $ex) {
|
} catch (Exception $ex) {
|
||||||
|
var_dump($ex->getMessage());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,6 +134,7 @@ function user_card_alert ($username, $title, $desc, $button, $url)
|
||||||
$url,
|
$url,
|
||||||
]);
|
]);
|
||||||
} catch (Exception $ex) {
|
} catch (Exception $ex) {
|
||||||
|
var_dump($ex->getMessage());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,6 +175,7 @@ function user_mp_alert ($username, $appid, $title, $page = null, $desc = null, $
|
||||||
$emphasisFirstItem
|
$emphasisFirstItem
|
||||||
]);
|
]);
|
||||||
} catch (Exception $ex) {
|
} catch (Exception $ex) {
|
||||||
|
var_dump($ex->getMessage());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,130 +215,7 @@ function tag_mp_alert ($tag, $appid, $title, $page = null, $desc = null, $items
|
||||||
$emphasisFirstItem
|
$emphasisFirstItem
|
||||||
]);
|
]);
|
||||||
} catch (Exception $ex) {
|
} catch (Exception $ex) {
|
||||||
return null;
|
var_dump($ex->getMessage());
|
||||||
}
|
|
||||||
|
|
||||||
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 null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,20 +5,11 @@ ini_set('display_errors', 'stderr');
|
||||||
|
|
||||||
require_once dirname(__DIR__).'/vendor/autoload.php';
|
require_once dirname(__DIR__).'/vendor/autoload.php';
|
||||||
|
|
||||||
//$ret = chat_card_alert('szjesh','dfdfdf');
|
$ret = chat_card_alert('szjesh','dfdfdf');
|
||||||
//var_dump($ret);
|
var_dump($ret);
|
||||||
//if( $ret['err_code'] == '0' ){
|
if( $ret['err_code'] == '0' ){
|
||||||
// echo "发送成功\n";
|
echo "发送成功\n";
|
||||||
//}else{
|
}else{
|
||||||
// echo "发送失败,原因{$ret['err_msg']}\n";
|
echo "发送失败,原因{$ret['err_msg']}\n";
|
||||||
//}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$content = [
|
|
||||||
'msgtype' => 'text',
|
|
||||||
'text' => [
|
|
||||||
'content' => '!',
|
|
||||||
]
|
|
||||||
];
|
|
||||||
bot_notify('inventory',$content);
|
|
Loading…
Reference in New Issue
Block a user