Compare commits
No commits in common. "main" and "v0.1" have entirely different histories.
|
@ -4,8 +4,8 @@
|
||||||
|
|
||||||
执行
|
执行
|
||||||
```bash
|
```bash
|
||||||
composer config repositories.php-alert vcs git@git.int.haowumc.com:composer/php-alert-client.git
|
composer config repositories.php-alert vcs git@git.int.haowumc.com:arch/php-alert-client.git
|
||||||
composer require paidian/work-wx-alert
|
composer require arch/alert
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"name": "paidian/work-wx-alert",
|
"name": "arch/alert",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "候学杰",
|
"name": "候学杰",
|
||||||
|
@ -12,6 +12,12 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"paidian/json-rpc": "~1.1"
|
"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"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
1214
composer.lock
generated
Normal file
1214
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 |
|
@ -1,37 +1,29 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
define('RPC_CONFIG', [
|
define('CRM_API_CONFIG', [
|
||||||
'app' => env('APP_NAME'),
|
'base_uri' => 'http://crm.in.haowumc.com/api/wechat/',
|
||||||
'client' => [
|
'appid' => 'notification',
|
||||||
'auth' => [
|
'secret' => '123456',
|
||||||
'base_uri' => 'http://auth.in.haowumc.com',
|
|
||||||
],
|
|
||||||
],
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 对企业微信群发送报警信息(需先创建
|
* 对企业微信群发送报警信息(需先创建
|
||||||
*
|
|
||||||
* @param $chat
|
* @param $chat
|
||||||
* @param $text
|
* @param $text
|
||||||
*
|
|
||||||
* @return mixed|null
|
* @return mixed|null
|
||||||
*/
|
*/
|
||||||
|
function chat_text_alert($chat, $text){
|
||||||
function chat_text_alert ($chat, $text)
|
$client = new \PdInternalApi\Client('crm', CRM_API_CONFIG);
|
||||||
{
|
|
||||||
if (env('APP_ENV') == 'local') {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
$base_client = new \JsonRpc\Client(RPC_CONFIG);
|
|
||||||
$client = $base_client->endpoint('auth');
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$resp = $client->call('notify.text', [
|
$resp = $client->call('work/text', [
|
||||||
['chat' => $chat],
|
'chat_id' => $chat,
|
||||||
$text,
|
'text' => $text,
|
||||||
]);
|
]);
|
||||||
} catch (Exception $ex) {
|
} catch (Exception $ex) {
|
||||||
|
var_dump($ex->getMessage());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,300 +32,20 @@ function chat_text_alert ($chat, $text)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 对单个或多个用户发送报警或通知信息,多个用户id使用 | 隔开
|
* 对单个或多个用户发送报警或通知信息,多个用户id使用 | 隔开
|
||||||
*
|
* @param $username
|
||||||
* @param $text
|
* @param $text
|
||||||
*
|
|
||||||
* @return mixed|null
|
* @return mixed|null
|
||||||
*/
|
*/
|
||||||
function user_text_alert ($username, $text)
|
function user_text_alert($username, $text){
|
||||||
{
|
$client = new \PdInternalApi\Client('crm', CRM_API_CONFIG);
|
||||||
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.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 {
|
try {
|
||||||
$resp = $client->call('notify.card', [
|
$resp = $client->call('work/text', [
|
||||||
['chat' => $chat],
|
'username' => $username,
|
||||||
$title,
|
'text' => $text,
|
||||||
$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) {
|
} catch (Exception $ex) {
|
||||||
|
var_dump($ex->getMessage());
|
||||||
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 = user_text_alert('xieshi','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