PHP code example of yyq / minimum_alarm
1. Go to this page and download the library: Download yyq/minimum_alarm library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
yyq / minimum_alarm example snippets php
mum_alarm\YACenter;
use minimum_alarm\YAlertor;
// 声明 消息中心 对象
$a_center = new YACenter;
// 生成 email 报警器(已测试通过)
// config 必须包含:$config['mail_host'], $config['mail_username'], $config['mail_password']
// config 可以包含:$config['mail_host_port'], $config['use_ssl']
$a_center->generateAlertor( YACenter::ALERTOR_TYPE_EMAIL,
array( 'mail_host' => 'XXXXXXX', 'mail_username' => 'XXXXXX', 'mail_password' => 'XXXXXX',
'to_emails' => array('[email protected] ', '[email protected] '), 'use_ssl' => 'tls' )
);
// 生成 微信服务号 报警器
// 参数说明:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1481187827_i0l21
// config 必须包含:$config['wx_appid'], $config['wx_appsecret'], $config['to_wx_uids']
$a_center->generateAlertor( YACenter::ALERTOR_TYPE_WX_PUBLIC,
array('wx_appid' => 'XXXXXXX', 'wx_appsecret' => 'XXXXXX',
'to_wx_uids' => array('XXXXXXXXX', 'XXXXXXXX') )
);
// 生成 微信企业 报警器(已测试通过)
// 参数说明:http://qydev.weixin.qq.com/wiki/index.php?title=消息类型及数据格式
// config 必须包含:$config['wx_corpid'], $config['wx_corpsecret'], $config['to_wx_euids']
// config 可以包含:$config['wx_agentid']
$a_center->generateAlertor( YACenter::ALERTOR_TYPE_WX_ENTERPRISE,
array('wx_corpid' => 'XXXXXXX', 'wx_corpsecret' => 'XXXXXX',
'to_wx_euids' => array('XXXXXXXXX', 'XXXXXXXX') ),
YAlertor::ALARM_LEVEL_MIDDLE
);
// 生成 钉钉企业 报警器(已测试通过)
// 参数说明:https://open-doc.dingtalk.com/docs/doc.htm?spm=a219a.7629140.0.0.5pJaYW&treeId=385&articleId=107549&docType=1
/*
* 方式一 使用机器人报警
* 参数说明:https://open-doc.dingtalk.com/docs/doc.htm?spm=a219a.7629140.0.0.hOYIU2&treeId=257&articleId=105735&docType=1#s0
* config 必须包含:$config['dd_robot_token'], 如果有此参数配置,那么优先使用此方式报警;否则会采用方式二
*
* 方式二 使用指定(消息群) chatid 报警
* 参数说明:https://open-doc.dingtalk.com/docs/doc.htm?spm=a219a.7629140.0.0.xTrowb&treeId=374&articleId=104977&docType=1#s4
* config 必须包含:$config['dd_corpid'], $config['dd_corpsecret'], $config['dd_chatid']
*/
$a_center->generateAlertor( YACenter::ALERTOR_TYPE_DINGDING,
array('dd_corpid' => 'XXXXXXX', 'dd_corpsecret' => 'XXXXXX',
'dd_chatid' => 'chatXXXXXXXXXXXXXXXX' ),
YAlertor::ALARM_LEVEL_MIDDLE
);
// 生成 阿里短信平台 报警器
// 参数说明:https://yq.aliyun.com/articles/59928
// config 必须包含:$config['ali_sign_name'], $config['ali_template_code'], $config['ali_param_name'], $config['ali_appkey'], $config['ali_appsecret'], $config['to_mobiles']
$a_center->generateAlertor( YACenter::ALERTOR_TYPE_ALI_SMS,
array('ali_sign_name' => 'XXXXXXX', 'ali_template_code' => 'XXXXXX', 'ali_param_name' => 'XXXXXXX',
'ali_appkey' => 'XXXXXX', 'ali_appsecret' => 'XXXXXXX',
'to_mobiles' => array('12345678901', '12345678902') ),
YAlertor::ALARM_LEVEL_HIGH
);
// 发送消息
$err_msgs = $a_center->sendAlarm(YAlertor::ALARM_LEVEL_HIGH, '测试消息,请忽略');
if( 1 > count($err_msgs) )
{
echo '发送成功';
}
else
{
print_r( $err_msgs );
}