新增转发到Telegram机器人(自备梯子)

This commit is contained in:
pppscn 2021-03-12 18:12:41 +08:00
parent a34e9da924
commit fff7302bc2
27 changed files with 380 additions and 14 deletions

View File

@ -47,6 +47,8 @@ Android手机监听短信并根据指定规则转发到其他手机钉钉机
- [x] 转发到webhook支持单个web页面[向设置的url发送POST请求](doc/POST_WEB.md)
- [x] 转发到企业微信群机器人
- [x] 转发到企业微信应用消息
- [x] 转发到ServerChan(Server酱·Turbo版)
- [x] 转发到Telegram机器人
- [x] 在线检测新版本、升级
- [x] 清理缓存
- [x] 兼容6.xx、7.xx、8.xx、9.xx、10.xx
@ -89,12 +91,14 @@ Android手机监听短信并根据指定规则转发到其他手机钉钉机
| ![添加/编辑发送方邮箱](pic/sendersetemail.jpg "添加/编辑发送方邮箱") | ![添加/编辑发送方Bark](pic/sendersetbark.jpg "添加/编辑发送方Bark") |
| 添加/编辑发送方网页通知 | 添加/编辑发送方企业微信群机器人 |
| ![添加/编辑发送方网页通知](pic/sendersetwebnotify.jpg "添加/编辑发送方网页通知") | ![添加/编辑发送方企业微信群机器人](pic/sendersetqywechat.jpg "添加/编辑发送方企业微信群机器人") |
| 添加/编辑发送方Telegram机器人 | 添加/编辑发送方Server酱·Turbo版 |
| ![添加/编辑发送方Telegram机器人](pic/sendertelegram.jpg "添加/编辑发送方Telegram机器人") | ![添加/编辑发送方Server酱·Turbo版](pic/senderserverchan.jpg "添加/编辑发送方Server酱·Turbo版") |
| 添加/编辑发送方企业微信应用 | 应用设置 |
| ![添加/编辑发送方企业微信应用](pic/sendersetqywxapp.jpg "添加/编辑发送方企业微信应用") | ![应用设置](pic/setting.jpg "应用设置") |
| 关于/在线升级 | 支持正则匹配规则 & 支持卡槽匹配规则 |
| ![在线升级](pic/update.jpg "在线升级") | ![支持正则匹配规则 & 支持卡槽匹配规则](pic/regex.jpg "支持正则匹配规则 & 支持卡槽匹配规则") |
| 转发短信模板增加卡槽标识 | 添加/编辑发送方Server酱·Turbo版 |
| ![转发短信模板增加卡槽标识](pic/siminfo.jpg "转发短信模板增加卡槽标识") | ![添加/编辑发送方Server酱·Turbo版](pic/sendersetbark.jpg "添加/编辑发送方Server酱·Turbo版") |
| 转发短信模板增加卡槽标识 | |
| ![转发短信模板增加卡槽标识](pic/siminfo.jpg "转发短信模板增加卡槽标识") | |
--------
@ -117,6 +121,7 @@ Android手机监听短信并根据指定规则转发到其他手机钉钉机
+ [v1.5.2](app/release/SmsForwarder_release_20210311_1.5.2.apk) 支持标注卡槽号码(优先使用)、设备信息;自定义转发信息模版
+ [v1.6.0](app/release/SmsForwarder_release_20210312_1.6.0.apk) 优化获取SIM信息兼容高版本Android & 自动填写设备备注 & 自动填充卡槽信息到SIM1备注/SIM2备注 & 支持卡槽匹配规则 & 支持正则匹配规则
+ [v1.6.1](app/release/SmsForwarder_release_20210312_1.6.1.apk) 新增转发到Server酱·Turbo版
+ [v1.6.2](app/release/SmsForwarder_release_20210312_1.6.2.apk) 新增转发到Telegram机器人
--------

Binary file not shown.

View File

@ -10,9 +10,9 @@
{
"type": "SINGLE",
"filters": [],
"versionCode": 17,
"versionName": "1.6.1",
"outputFile": "SmsForwarder_release_20210312_1.6.1.apk"
"versionCode": 18,
"versionName": "1.6.2",
"outputFile": "SmsForwarder_release_20210312_1.6.2.apk"
}
]
}

View File

@ -30,7 +30,7 @@ public class FrontService extends Service {
if (romType == OSUtils.ROM_TYPE.MIUI_ROM) {
builder.setContentTitle("短信转发器");
}
builder.setContentText("根据规则转发到钉钉/微信/邮箱/bark/Server酱/webhook等");
builder.setContentText("根据规则转发到钉钉/微信/邮箱/bark/Server酱/Telegram/webhook等");
Intent intent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity
(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

View File

@ -28,6 +28,7 @@ import com.idormy.sms.forwarder.model.vo.EmailSettingVo;
import com.idormy.sms.forwarder.model.vo.QYWXAppSettingVo;
import com.idormy.sms.forwarder.model.vo.QYWXGroupRobotSettingVo;
import com.idormy.sms.forwarder.model.vo.ServerChanSettingVo;
import com.idormy.sms.forwarder.model.vo.TelegramSettingVo;
import com.idormy.sms.forwarder.model.vo.WebNotifySettingVo;
import com.idormy.sms.forwarder.sender.SenderBarkMsg;
import com.idormy.sms.forwarder.sender.SenderDingdingMsg;
@ -35,6 +36,7 @@ import com.idormy.sms.forwarder.sender.SenderMailMsg;
import com.idormy.sms.forwarder.sender.SenderQyWxAppMsg;
import com.idormy.sms.forwarder.sender.SenderQyWxGroupRobotMsg;
import com.idormy.sms.forwarder.sender.SenderServerChanMsg;
import com.idormy.sms.forwarder.sender.SenderTelegramMsg;
import com.idormy.sms.forwarder.sender.SenderUtil;
import com.idormy.sms.forwarder.sender.SenderWebNotifyMsg;
import com.umeng.analytics.MobclickAgent;
@ -51,6 +53,7 @@ import static com.idormy.sms.forwarder.model.SenderModel.TYPE_EMAIL;
import static com.idormy.sms.forwarder.model.SenderModel.TYPE_QYWX_APP;
import static com.idormy.sms.forwarder.model.SenderModel.TYPE_QYWX_GROUP_ROBOT;
import static com.idormy.sms.forwarder.model.SenderModel.TYPE_SERVER_CHAN;
import static com.idormy.sms.forwarder.model.SenderModel.TYPE_TELEGRAM;
import static com.idormy.sms.forwarder.model.SenderModel.TYPE_WEB_NOTIFY;
public class SenderActivity extends AppCompatActivity {
@ -127,6 +130,9 @@ public class SenderActivity extends AppCompatActivity {
case TYPE_SERVER_CHAN:
setServerChan(senderModel);
break;
case TYPE_TELEGRAM:
setTelegram(senderModel);
break;
default:
Toast.makeText(SenderActivity.this, "异常的发送方类型,自动删除!", Toast.LENGTH_LONG).show();
if (senderModel != null) {
@ -208,6 +214,9 @@ public class SenderActivity extends AppCompatActivity {
case TYPE_SERVER_CHAN:
setServerChan(null);
break;
case TYPE_TELEGRAM:
setTelegram(null);
break;
default:
Toast.makeText(SenderActivity.this, "暂不支持这种转发!", Toast.LENGTH_LONG).show();
break;
@ -947,6 +956,104 @@ public class SenderActivity extends AppCompatActivity {
});
}
//Telegram机器人
private void setTelegram(final SenderModel senderModel) {
TelegramSettingVo telegramSettingVo = null;
//try phrase json setting
if (senderModel != null) {
String jsonSettingStr = senderModel.getJsonSetting();
if (jsonSettingStr != null) {
telegramSettingVo = JSON.parseObject(jsonSettingStr, TelegramSettingVo.class);
}
}
final AlertDialog.Builder alertDialog71 = new AlertDialog.Builder(SenderActivity.this);
View view1 = View.inflate(SenderActivity.this, R.layout.alert_dialog_setview_telegram, null);
final EditText editTextTelegramName = view1.findViewById(R.id.editTextTelegramName);
if (senderModel != null) editTextTelegramName.setText(senderModel.getName());
final EditText editTextTelegramApiToken = view1.findViewById(R.id.editTextTelegramApiToken);
if (telegramSettingVo != null)
editTextTelegramApiToken.setText(telegramSettingVo.getApiToken());
final EditText editTextTelegramChatId = view1.findViewById(R.id.editTextTelegramChatId);
if (telegramSettingVo != null)
editTextTelegramChatId.setText(telegramSettingVo.getChatId());
Button buttonTelegramOk = view1.findViewById(R.id.buttonTelegramOk);
Button buttonTelegramDel = view1.findViewById(R.id.buttonTelegramDel);
Button buttonTelegramTest = view1.findViewById(R.id.buttonTelegramTest);
alertDialog71
.setTitle(R.string.settelegramtitle)
.setIcon(R.mipmap.telegram)
.setView(view1)
.create();
final AlertDialog show = alertDialog71.show();
buttonTelegramOk.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (senderModel == null) {
SenderModel newSenderModel = new SenderModel();
newSenderModel.setName(editTextTelegramName.getText().toString());
newSenderModel.setType(TYPE_TELEGRAM);
newSenderModel.setStatus(STATUS_ON);
TelegramSettingVo telegramSettingVoNew = new TelegramSettingVo(
editTextTelegramApiToken.getText().toString(),
editTextTelegramChatId.getText().toString()
);
newSenderModel.setJsonSetting(JSON.toJSONString(telegramSettingVoNew));
SenderUtil.addSender(newSenderModel);
initSenders();
adapter.add(senderModels);
} else {
senderModel.setName(editTextTelegramName.getText().toString());
senderModel.setType(TYPE_TELEGRAM);
senderModel.setStatus(STATUS_ON);
TelegramSettingVo telegramSettingVoNew = new TelegramSettingVo(
editTextTelegramApiToken.getText().toString(),
editTextTelegramChatId.getText().toString()
);
senderModel.setJsonSetting(JSON.toJSONString(telegramSettingVoNew));
SenderUtil.updateSender(senderModel);
initSenders();
adapter.update(senderModels);
}
show.dismiss();
}
});
buttonTelegramDel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (senderModel != null) {
SenderUtil.delSender(senderModel.getId());
initSenders();
adapter.del(senderModels);
}
show.dismiss();
}
});
buttonTelegramTest.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String apiToken = editTextTelegramApiToken.getText().toString();
String chatId = editTextTelegramChatId.getText().toString();
if (!apiToken.isEmpty() && !chatId.isEmpty()) {
try {
SenderTelegramMsg.sendMsg(handler, apiToken, chatId, "19999999999", "【京东】验证码为387481切勿将验证码告知他人请在页面中输入完成验证如有问题请点击 ihelp.jd.com 联系京东客服");
} catch (Exception e) {
Toast.makeText(SenderActivity.this, "发送失败:" + e.getMessage(), Toast.LENGTH_LONG).show();
e.printStackTrace();
}
} else {
Toast.makeText(SenderActivity.this, "机器人的ApiToken 和 被通知人的ChatId 都不能为空", Toast.LENGTH_LONG).show();
}
}
});
}
@Override
protected void onDestroy() {
Log.d(TAG, "onDestroy");

View File

@ -13,6 +13,7 @@ public class SenderModel {
public static final int TYPE_QYWX_GROUP_ROBOT = 4;
public static final int TYPE_QYWX_APP = 5;
public static final int TYPE_SERVER_CHAN = 6;
public static final int TYPE_TELEGRAM = 7;
private Long id;
private String name;
private int status;
@ -48,6 +49,8 @@ public class SenderModel {
return R.mipmap.qywxapp;
case (TYPE_SERVER_CHAN):
return R.mipmap.serverchan;
case (TYPE_TELEGRAM):
return R.mipmap.telegram;
default:
return R.mipmap.sms;
}
@ -109,6 +112,8 @@ public class SenderModel {
return R.mipmap.qywxapp;
case (TYPE_SERVER_CHAN):
return R.mipmap.serverchan;
case (TYPE_TELEGRAM):
return R.mipmap.telegram;
default:
return R.mipmap.sms;

View File

@ -3,20 +3,20 @@ package com.idormy.sms.forwarder.model.vo;
import java.io.Serializable;
public class ServerChanSettingVo implements Serializable {
private String send_key;
private String sendKey;
public ServerChanSettingVo() {
}
public ServerChanSettingVo(String send_key) {
this.send_key = send_key;
public ServerChanSettingVo(String sendKey) {
this.sendKey = sendKey;
}
public String getSendKey() {
return send_key;
return sendKey;
}
public void setSendKey(String send_key) {
this.send_key = send_key;
public void setSendKey(String sendKey) {
this.sendKey = sendKey;
}
}

View File

@ -0,0 +1,32 @@
package com.idormy.sms.forwarder.model.vo;
import java.io.Serializable;
public class TelegramSettingVo implements Serializable {
private String apiToken;
private String chatId;
public TelegramSettingVo() {
}
public TelegramSettingVo(String apiToken, String chatId) {
this.apiToken = apiToken;
this.chatId = chatId;
}
public String getApiToken() {
return apiToken;
}
public void setApiToken(String apiToken) {
this.apiToken = apiToken;
}
public String getChatId() {
return chatId;
}
public void setChatId(String chatId) {
this.chatId = chatId;
}
}

View File

@ -15,6 +15,7 @@ import com.idormy.sms.forwarder.model.vo.QYWXAppSettingVo;
import com.idormy.sms.forwarder.model.vo.QYWXGroupRobotSettingVo;
import com.idormy.sms.forwarder.model.vo.ServerChanSettingVo;
import com.idormy.sms.forwarder.model.vo.SmsVo;
import com.idormy.sms.forwarder.model.vo.TelegramSettingVo;
import com.idormy.sms.forwarder.model.vo.WebNotifySettingVo;
import com.idormy.sms.forwarder.utils.LogUtil;
import com.idormy.sms.forwarder.utils.RuleUtil;
@ -27,6 +28,7 @@ import static com.idormy.sms.forwarder.model.SenderModel.TYPE_EMAIL;
import static com.idormy.sms.forwarder.model.SenderModel.TYPE_QYWX_APP;
import static com.idormy.sms.forwarder.model.SenderModel.TYPE_QYWX_GROUP_ROBOT;
import static com.idormy.sms.forwarder.model.SenderModel.TYPE_SERVER_CHAN;
import static com.idormy.sms.forwarder.model.SenderModel.TYPE_TELEGRAM;
import static com.idormy.sms.forwarder.model.SenderModel.TYPE_WEB_NOTIFY;
public class SendUtil {
@ -200,6 +202,20 @@ public class SendUtil {
}
break;
case TYPE_TELEGRAM:
//try phrase json setting
if (senderModel.getJsonSetting() != null) {
TelegramSettingVo telegramSettingVo = JSON.parseObject(senderModel.getJsonSetting(), TelegramSettingVo.class);
if (telegramSettingVo != null) {
try {
SenderTelegramMsg.sendMsg(handError, telegramSettingVo.getApiToken(), telegramSettingVo.getChatId(), smsVo.getMobile(), smsVo.getSmsVoForSend());
} catch (Exception e) {
Log.e(TAG, "senderSendMsg: SenderTelegramMsg error " + e.getMessage());
}
}
}
break;
default:
break;
}

View File

@ -0,0 +1,92 @@
package com.idormy.sms.forwarder.sender;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import com.alibaba.fastjson.JSON;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import static com.idormy.sms.forwarder.SenderActivity.NOTIFY;
public class SenderTelegramMsg {
static String TAG = "SenderTelegramMsg";
public static void sendMsg(final Handler handError, String apiToken, String chatId, String from, String text) throws Exception {
Log.i(TAG, "sendMsg apiToken:" + apiToken + " chatId:" + chatId + " text:" + text);
if (apiToken == null || apiToken.isEmpty()) {
return;
}
//特殊处理避免标题重复
text = text.replaceFirst("^" + from + "(.*)", "").trim();
String sendUrl = "https://api.telegram.org/bot" + apiToken + "/sendMessage";
Log.d(TAG, "sendUrl" + sendUrl);
Map bodyMap = new HashMap();
bodyMap.put("chat_id", chatId);
bodyMap.put("text", text.trim());
bodyMap.put("parse_mode", "HTML");
String bodyMsg = JSON.toJSONString(bodyMap);
Log.d(TAG, "body" + bodyMsg);
OkHttpClient client = new OkHttpClient();
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json;charset=utf-8"), bodyMsg);
final Request request = new Request.Builder()
.url(sendUrl)
.addHeader("Content-Type", "application/json; charset=utf-8")
.post(requestBody)
.build();
Call call = client.newCall(request);
call.enqueue(new Callback() {
@Override
public void onFailure(Call call, final IOException e) {
Log.d(TAG, "onFailure" + e.getMessage());
if (handError != null) {
Message msg = new Message();
msg.what = NOTIFY;
Bundle bundle = new Bundle();
bundle.putString("DATA", "发送失败:" + e.getMessage());
msg.setData(bundle);
handError.sendMessage(msg);
}
}
@Override
public void onResponse(Call call, Response response) throws IOException {
final String responseStr = response.body().string();
Log.d(TAG, "Code" + response.code() + responseStr);
if (handError != null) {
Message msg = new Message();
msg.what = NOTIFY;
Bundle bundle = new Bundle();
bundle.putString("DATA", "发送状态:" + responseStr);
msg.setData(bundle);
handError.sendMessage(msg);
Log.d(TAG, "Response" + response.code() + responseStr);
}
}
});
}
}

View File

@ -0,0 +1,107 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="设置名称" />
<EditText
android:id="@+id/editTextTelegramName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:ems="11"
android:inputType=""
android:text="" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="设置Telegram机器人的ApiToken" />
<EditText
android:id="@+id/editTextTelegramApiToken"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="14"
android:inputType=""
android:text="" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="设置被通知人的ChatId" />
<EditText
android:id="@+id/editTextTelegramChatId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="14"
android:inputType=""
android:text="" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:orientation="horizontal">
<Button
android:id="@+id/buttonTelegramOk"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/ok" />
<Button
android:id="@+id/buttonTelegramDel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:text="@string/del" />
<Button
android:id="@+id/buttonTelegramTest"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:text="@string/test" />
</LinearLayout>
</LinearLayout>
</ScrollView>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.2 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

View File

@ -8,5 +8,6 @@
<item>转发到企业微信群机器人</item>
<item>转发到企业微信应用消息</item>
<item>转发到Server酱·Turbo版</item>
<item>转发到Telegram机器人</item>
</string-array>
</resources>

View File

@ -13,6 +13,7 @@
<string name="setqywxapptitle">设置企业微信应用</string>
<string name="setbarktitle">设置Bark</string>
<string name="setserverchantitle">设置Server酱·Turbo版</string>
<string name="settelegramtitle">设置Telegram机器人</string>
<string name="check_new_version">检查更新</string>
<string name="to_setting">设置</string>
<string name="to_about">关于</string>

View File

@ -1,4 +1,4 @@
ext {
appVersionCode = 17
appVersionName = "1.6.1"
appVersionCode = 18
appVersionName = "1.6.2"
}

BIN
pic/senderserverchan.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 198 KiB

BIN
pic/sendertelegram.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 204 KiB

Binary file not shown.