Compare commits

..

No commits in common. "main" and "v0.1" have entirely different histories.
main ... v0.1

9 changed files with 1250 additions and 327 deletions

View File

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

View File

@ -1,5 +1,5 @@
{
"name": "paidian/work-wx-alert",
"name": "arch/alert",
"authors": [
{
"name": "候学杰",
@ -12,6 +12,12 @@
]
},
"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

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

View File

@ -1,37 +1,29 @@
<?php
define('RPC_CONFIG', [
'app' => env('APP_NAME'),
'client' => [
'auth' => [
'base_uri' => 'http://auth.in.haowumc.com',
],
],
define('CRM_API_CONFIG', [
'base_uri' => 'http://crm.in.haowumc.com/api/wechat/',
'appid' => 'notification',
'secret' => '123456',
]);
/**
* 对企业微信群发送报警信息(需先创建
*
* @param $chat
* @param $text
*
* @return mixed|null
*/
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');
function chat_text_alert($chat, $text){
$client = new \PdInternalApi\Client('crm', CRM_API_CONFIG);
try {
$resp = $client->call('notify.text', [
['chat' => $chat],
$text,
$resp = $client->call('work/text', [
'chat_id' => $chat,
'text' => $text,
]);
} catch (Exception $ex) {
var_dump($ex->getMessage());
return null;
}
@ -40,302 +32,22 @@ function chat_text_alert ($chat, $text)
/**
* 对单个或多个用户发送报警或通知信息多个用户id使用 | 隔开
*
* @param $username
* @param $text
*
* @return mixed|null
*/
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 {
$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');
function user_text_alert($username, $text){
$client = new \PdInternalApi\Client('crm', CRM_API_CONFIG);
try {
$resp = $client->call('notify.card', [
['chat' => $chat],
$title,
$desc,
$button,
$url,
$resp = $client->call('work/text', [
'username' => $username,
'text' => $text,
]);
} 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,20 +5,11 @@ ini_set('display_errors', 'stderr');
require_once dirname(__DIR__).'/vendor/autoload.php';
//$ret = chat_card_alert('szjesh','dfdfdf');
//var_dump($ret);
//if( $ret['err_code'] == '0' ){
// echo "发送成功\n";
//}else{
// echo "发送失败,原因{$ret['err_msg']}\n";
//}
$ret = user_text_alert('xieshi','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);