Skip to content

Commit

Permalink
修复转发长短信获取短信内容为空的问题,添加转发至TGBot功能
Browse files Browse the repository at this point in the history
  • Loading branch information
yu lkiu committed May 20, 2023
1 parent bd8d9b1 commit 4e670e1
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 31 deletions.
3 changes: 3 additions & 0 deletions DbusTest/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@
<add key="WeChatQYID" value="" />
<add key="WeChatQYApplicationID" value="" />
<add key="WeChatQYApplicationSecret" value="" />
<add key="TGBotToken" value="" />
<add key="TGBotChatID" value="" />

</appSettings>
</configuration>
11 changes: 8 additions & 3 deletions DbusTest/ProcessUserChoise/ProcessChoise.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ public static string sendMethodGuide(string chooseOption)
{
if(string.IsNullOrEmpty(chooseOption))
{
Console.WriteLine("请选择转发渠道:1.邮箱转发,2.pushplus转发,3.企业微信转发");
Console.WriteLine("请选择转发渠道:1.邮箱转发,2.pushplus转发,3.企业微信转发,4.TG机器人转发");
chooseOption = Console.ReadLine();
}
if (chooseOption == "1" || chooseOption == "2" || chooseOption == "3")
if (chooseOption == "1" || chooseOption == "2" || chooseOption == "3" || chooseOption == "4")
{
if (chooseOption == "1")
{
Expand All @@ -47,14 +47,19 @@ public static string sendMethodGuide(string chooseOption)
SendByWeComApplication.SetupWeComInfo();
return "3";
}
else if (chooseOption == "4")
{
SendByTelegramBot.SetupTGBotInfo();
return "4";
}
else
{
return "";
}
}
else
{
Console.WriteLine("请输入1或2或3");
Console.WriteLine("请输入1或2或3或4");
return sendMethodGuide("");
}
}
Expand Down
39 changes: 39 additions & 0 deletions DbusTest/ProcessUserSend/ProcessSend.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using DbusSmsForward.SendMethod;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DbusSmsForward.ProcessUserSend
{
public class ProcessSend
{
public static void sendSms(string sendMethodGuideResult,string tel,string body)
{
try
{
if (sendMethodGuideResult == "1")
{
SendByEmail.SendSms(tel, body);
}
if (sendMethodGuideResult == "2")
{
SendByPushPlus.SendSms(tel, body);
}
if (sendMethodGuideResult == "3")
{
SendByWeComApplication.SendSms(tel, body);
}
if (sendMethodGuideResult == "4")
{
SendByTelegramBot.SendSms(tel, body);
}
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}
28 changes: 13 additions & 15 deletions DbusTest/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Tmds.DBus;
using DbusSmsForward.SendMethod;
using DbusSmsForward.ProcessUserChoise;

using DbusSmsForward.ProcessUserSend;

string startGuideChoiseNum = "";
string sendMethodGuideChoiseNum = "";
Expand All @@ -24,6 +24,11 @@
startGuideChoiseNum = "1";
sendMethodGuideChoiseNum = "3";
}
else if (s1 == "-fT")
{
startGuideChoiseNum = "1";
sendMethodGuideChoiseNum = "4";
}
else if (s1 == "-sS")
{
startGuideChoiseNum = "2";
Expand Down Expand Up @@ -53,22 +58,15 @@ await imsg.WatchAddedAsync(
var isms = connection.CreateProxy<ISms>("org.freedesktop.ModemManager1", change.path);
string tel = await isms.GetNumberAsync();
string stime = (await isms.GetTimestampAsync()).Replace("T", " ").Replace("+08:00", " ");
string smscontent = await isms.GetTextAsync();
string smscontent = "";
do
{
smscontent = "";
smscontent = await isms.GetTextAsync();
} while (string.IsNullOrEmpty(smscontent));
string body = "发信电话:" + tel + "\n" + "时间:" + stime + "\n" + "短信内容:" + smscontent;
Console.WriteLine(body);
if (sendMethodGuideResult == "1")
{
SendByEmail.SendSms(tel, body);
}
if (sendMethodGuideResult == "2")
{
SendByPushPlus.SendSms(tel, body);
}
if(sendMethodGuideResult == "3")
{
SendByWeComApplication.SendSms(tel, body);
}
ProcessSend.sendSms(sendMethodGuideResult, tel, body);
}
}
);
Expand Down
56 changes: 56 additions & 0 deletions DbusTest/SendMethod/SendByTelegramBot.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using DbusSmsForward.Helper;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DbusSmsForward.SendMethod
{
public static class SendByTelegramBot
{
public static void SetupTGBotInfo()
{
string TGBotToken = ConfigurationManager.AppSettings["TGBotToken"];
string TGBotChatID = ConfigurationManager.AppSettings["TGBotChatID"];

if (string.IsNullOrEmpty(TGBotToken) && string.IsNullOrEmpty(TGBotChatID))
{
Configuration cfa = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
Console.WriteLine("首次运行请输入TG机器人Token:");
TGBotToken = Console.ReadLine().Trim();
cfa.AppSettings.Settings["TGBotToken"].Value = TGBotToken;
Console.WriteLine("首次运行请输入机器人要转发到的ChatId");
TGBotChatID = Console.ReadLine().Trim();
cfa.AppSettings.Settings["TGBotChatID"].Value = TGBotChatID;
cfa.Save();
}
}

public static void SendSms(string number, string body)
{
ConfigurationManager.RefreshSection("appSettings");
string TGBotToken = ConfigurationManager.AppSettings["TGBotToken"];
string TGBotChatID = ConfigurationManager.AppSettings["TGBotChatID"];
string url = "https://api.telegram.org/bot" + TGBotToken + "/sendMessage?chat_id=" + TGBotChatID + "&text=";
url += System.Web.HttpUtility.UrlEncode(body);
string msgresult = HttpHelper.HttpGet(url);
JObject jsonObjresult = JObject.Parse(msgresult);
string status = jsonObjresult["ok"].ToString();
if (status == "True")
{
Console.WriteLine("TGBot转发成功");
}
else
{
Console.WriteLine(jsonObjresult["error_code"].ToString());
Console.WriteLine(jsonObjresult["description"].ToString());
}

}


}
}
2 changes: 0 additions & 2 deletions DbusTest/SendMethod/SendByWeComApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ public static void SetupWeComInfo()
appsecret = Console.ReadLine().Trim();
cfa.AppSettings.Settings["WeChatQYApplicationSecret"].Value = appsecret;



cfa.Save();
}
}
Expand Down
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,31 @@ sudo chmod -R 777 DbusSmsForward
配置程序可执行权限

4.输入
./DbusSmsForward
sudo ./DbusSmsForward
运行程序

5.根据提示配置相关邮箱信息

6.带参数运行跳过程序初始的运行模式选择以达到快速运行程序

输入
./DbusSmsForward -fE
sudo ./DbusSmsForward -fE
跳过运行模式选择直接进入邮箱转发模式

输入
./DbusSmsForward -fP
sudo ./DbusSmsForward -fP
跳过运行模式选择直接进入PushPlus转发模式

输入
./DbusSmsForward -fW
sudo ./DbusSmsForward -fW
跳过运行模式选择直接进入企业微信转发模式

输入
./DbusSmsForward -sS
sudo ./DbusSmsForward -fT
跳过运行模式选择直接进入TGBot转发模式

输入
sudo ./DbusSmsForward -sS
跳过运行模式选择直接进入短信发送界面

# 参考
Expand Down
Binary file modified 发布/DbusSmsForward
Binary file not shown.
3 changes: 3 additions & 0 deletions 发布/DbusSmsForward.dll.config
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@
<add key="WeChatQYID" value="" />
<add key="WeChatQYApplicationID" value="" />
<add key="WeChatQYApplicationSecret" value="" />
<add key="TGBotToken" value="" />
<add key="TGBotChatID" value="" />

</appSettings>
</configuration>
16 changes: 10 additions & 6 deletions 发布/使用教程.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,33 @@ sudo apt install libicu67
2.解压程序至home文件夹下

3.输入
sudo chmod -R 777 DbusSmsFoward
sudo chmod -R 777 DbusSmsForward
配置程序可执行权限

4.输入
./DbusSmsFoward
sudo ./DbusSmsForward
运行程序

5.根据体术配置相关邮箱信息

6.带参数运行跳过程序初始的运行模式选择以达到快速运行程序

输入
./DbusSmsForward -fE
sudo ./DbusSmsForward -fE
跳过运行模式选择直接进入邮箱转发模式

输入
./DbusSmsForward -fP
sudo ./DbusSmsForward -fP
跳过运行模式选择直接进入PushPlus转发模式

输入
./DbusSmsForward -fW
sudo ./DbusSmsForward -fW
跳过运行模式选择直接进入企业微信转发模式

输入
./DbusSmsForward -sS
sudo ./DbusSmsForward -fT
跳过运行模式选择直接进入TGBot转发模式

输入
sudo ./DbusSmsForward -sS
跳过运行模式选择直接进入短信发送界面

0 comments on commit 4e670e1

Please sign in to comment.