From c5ac6e20b6fdd7abf80849cfaea2eba32d4ae9b3 Mon Sep 17 00:00:00 2001 From: HKL-Kevin <1747871302@qq.com> Date: Tue, 7 Jan 2025 18:53:17 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=94=AF=E6=8C=81dark=E6=8E=A8=E9=80=81?= =?UTF-8?q?=E9=80=9A=E9=81=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.conf | 9 +++++++++ mf.sh | 26 ++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/config.conf b/config.conf index 524c157..a43c640 100644 --- a/config.conf +++ b/config.conf @@ -67,5 +67,14 @@ dd_Webhook= #如果你要多个设备使用,可以在同一个团队内创建多个不同名称的部门群用于不同的设备,或是在同一个部门群内添加多个不同名称的自定义机器人用于不同的设备,以便钉钉收到消息可以区分设备。 +# bark推送总开关,当前只简单适配Push接口 +bark_switch=1 + +# bark服务器地址(默认地址,自建服务器可配置) +bark_url=https://api.day.app/push + +# bark推送deviceKey(根据自己设备的实际情况填写) +device_key= + #------------------------------ diff --git a/mf.sh b/mf.sh index 2d6e52d..c7f8b4d 100644 --- a/mf.sh +++ b/mf.sh @@ -99,8 +99,25 @@ if type curl > /dev/null 2>&1; then echo "$(date +%F_%T) 【钉钉通道 消息转发失败】:运营商网络问题,访问接口失败,请变更外网IP后再尝试。或是请检查配置参数[dd_Webhook]是否填写正确,返回提示:$dd_push。【消息】:$wx_text" >> "$MODDIR/log.log" fi } + bark_push() { + bark_url="$(echo "$config_conf" | egrep '^bark_url=' | sed -n 's/bark_url=//g;$p')" + device_key="$(echo "$config_conf" | egrep '^device_key=' | sed -n 's/device_key=//g;$p')" + bark_post="{\"title\": \"$MF_app\",\"body\": \"$wx_text\",\"level\": \"critical\",\"volume\": 5,\"badge\": 1,\"device_key\": \"$device_key\"}" + bark_push="$(curl -s --connect-timeout 12 -m 15 -H 'Content-Type: application/json' -d "$bark_post" "$bark_url")" + if [ -n "$bark_push" ]; then + bark_push_errcode="$(echo "$bark_push" | egrep '\"code\"' | sed -n 's/ //g;s/.*\"code\"://g;s/\".*//g;s/,.*//g;$p')" + if [ "$dd_push_errcode" = "200" ]; then + echo "$(date +%F_%T) 【Bark通道 消息转发成功】:$wx_text" >> "$MODDIR/log.log" + else + echo "$(date +%F_%T) 【Bark通道 消息转发失败】:请检查配置参数[bark_url,device_key]是否填写正确,返回提示:$bark_push。【消息】:$wx_text" >> "$MODDIR/log.log" + fi + else + echo "$(date +%F_%T) 【钉钉通道 消息转发失败】:运营商网络问题,访问接口失败,请变更外网IP后再尝试。或是请检查配置参数[dd_Webhook]是否填写正确,返回提示:$bark_push。【消息】:$wx_text" >> "$MODDIR/log.log" + fi + } wx_switch="$(echo "$config_conf" | egrep '^wx_switch=' | sed -n 's/wx_switch=//g;$p')" dd_switch="$(echo "$config_conf" | egrep '^dd_switch=' | sed -n 's/dd_switch=//g;$p')" + bark_switch="$(echo "$config_conf" | egrep '^bark_switch=' | sed -n 's/bark_switch=//g;$p')" battery_level="$(dumpsys battery | egrep 'level:' | sed -n 's/.*level: //g;$p')" Low_battery="$(echo "$config_conf" | egrep '^Low_battery=' | sed -n 's/Low_battery=//g;$p')" if [ -n "$battery_level" -a "$battery_level" -le "$Low_battery" ]; then @@ -149,6 +166,7 @@ if type curl > /dev/null 2>&1; then Message_p="$(echo "$Message_list" | sed -n "${Message_n}p")" Message_id="$(echo "$Message_p" | cut -d ' ' -f '1-2' | sed -n 's/NotificationRecord(//g;$p')" MF_app="$(echo "$Message_id" | sed -n 's/.* pkg=//g;s/ .*//g;$p')" + notify_date=$(date +"%d/%b/%Y %H:%M") if [ -n "$(echo "$app_list" | egrep "$MF_app")" -a ! -n "$(echo "$MF_pushed" | egrep "$Message_id")" ]; then Message_app="$(echo "$config_conf" | egrep "^$MF_app=" | sed -n 's/.*=//g;$p')" if [ -n "$Message_app" ]; then @@ -175,6 +193,10 @@ if type curl > /dev/null 2>&1; then if [ "$dd_switch" = "1" ]; then dingtalk_push fi + if [ "$bark_switch" = "1" ]; then + wx_text="$ticker_Text" + bark_push + fi fi else android_text="$(echo "$Message_p" | egrep 'android\.text=' | sed -n 's/.*android\.text=//g;s/) android\..*//g;s/.*String (//g;s/\"/\\\"/g;$p')" @@ -199,6 +221,10 @@ if type curl > /dev/null 2>&1; then if [ "$dd_switch" = "1" ]; then dingtalk_push fi + if [ "$bark_switch" = "1" ]; then + wx_text="$ticker_Text" + bark_push + fi fi fi fi From 1a54bd53f46c911fd2f2bc8869ebc281af724b80 Mon Sep 17 00:00:00 2001 From: HKL-Kevin <1747871302@qq.com> Date: Tue, 7 Jan 2025 20:23:15 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9Bark=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E4=B8=BA=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.conf | 2 +- mf.sh | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/config.conf b/config.conf index a43c640..ce2812d 100644 --- a/config.conf +++ b/config.conf @@ -68,7 +68,7 @@ dd_Webhook= #如果你要多个设备使用,可以在同一个团队内创建多个不同名称的部门群用于不同的设备,或是在同一个部门群内添加多个不同名称的自定义机器人用于不同的设备,以便钉钉收到消息可以区分设备。 # bark推送总开关,当前只简单适配Push接口 -bark_switch=1 +bark_switch=0 # bark服务器地址(默认地址,自建服务器可配置) bark_url=https://api.day.app/push diff --git a/mf.sh b/mf.sh index c7f8b4d..a61520a 100644 --- a/mf.sh +++ b/mf.sh @@ -112,7 +112,7 @@ if type curl > /dev/null 2>&1; then echo "$(date +%F_%T) 【Bark通道 消息转发失败】:请检查配置参数[bark_url,device_key]是否填写正确,返回提示:$bark_push。【消息】:$wx_text" >> "$MODDIR/log.log" fi else - echo "$(date +%F_%T) 【钉钉通道 消息转发失败】:运营商网络问题,访问接口失败,请变更外网IP后再尝试。或是请检查配置参数[dd_Webhook]是否填写正确,返回提示:$bark_push。【消息】:$wx_text" >> "$MODDIR/log.log" + echo "$(date +%F_%T) 【Bark通道 消息转发失败】:运营商网络问题,访问接口失败,请变更外网IP后再尝试。或是请检查配置参数[bark_url,device_key]是否填写正确,返回提示:$bark_push。【消息】:$wx_text" >> "$MODDIR/log.log" fi } wx_switch="$(echo "$config_conf" | egrep '^wx_switch=' | sed -n 's/wx_switch=//g;$p')" @@ -194,9 +194,9 @@ if type curl > /dev/null 2>&1; then dingtalk_push fi if [ "$bark_switch" = "1" ]; then - wx_text="$ticker_Text" - bark_push - fi + wx_text=$(echo "$ticker_Text" | tr '\r' '\\r' | sed 's/\\ //g') + bark_push + fi fi else android_text="$(echo "$Message_p" | egrep 'android\.text=' | sed -n 's/.*android\.text=//g;s/) android\..*//g;s/.*String (//g;s/\"/\\\"/g;$p')" @@ -222,9 +222,9 @@ if type curl > /dev/null 2>&1; then dingtalk_push fi if [ "$bark_switch" = "1" ]; then - wx_text="$ticker_Text" - bark_push - fi + wx_text=$(echo "$ticker_Text" | tr '\r' '\\r' | sed 's/\\ //g') + bark_push + fi fi fi fi