转发到webhook支持GET方式(节点改变,原配置要重新编辑)

This commit is contained in:
pppscn 2021-03-13 14:36:53 +08:00
parent 45f51d8756
commit 7db28afe71
13 changed files with 130 additions and 87 deletions

View File

@ -44,7 +44,7 @@
- [x] 转发到钉钉机器人(支持:单个钉钉群,@某人 - [x] 转发到钉钉机器人(支持:单个钉钉群,@某人
- [x] 转发到邮箱支持SMTP - [x] 转发到邮箱支持SMTP
- [x] 转发到Bark支持验证码/动态密码自动复制) - [x] 转发到Bark支持验证码/动态密码自动复制)
- [x] 转发到webhook支持单个web页面[向设置的url发送POST请求](doc/POST_WEB.md) - [x] 转发到webhook支持单个web页面[向设置的url发送POST/GET请求](doc/POST_WEB.md)
- [x] 转发到企业微信群机器人 - [x] 转发到企业微信群机器人
- [x] 转发到企业微信应用消息 - [x] 转发到企业微信应用消息
- [x] 转发到ServerChan(Server酱·Turbo版) - [x] 转发到ServerChan(Server酱·Turbo版)
@ -124,6 +124,7 @@
+ [v1.6.0](app/release/SmsForwarder_release_20210312_1.6.0.apk) 优化获取SIM信息兼容高版本Android & 自动填写设备备注 & 自动填充卡槽信息到SIM1备注/SIM2备注 & 支持卡槽匹配规则 & 支持正则匹配规则 + [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.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机器人 + [v1.6.2](app/release/SmsForwarder_release_20210312_1.6.2.apk) 新增转发到Telegram机器人
+ [v1.6.3](app/release/SmsForwarder_release_20210313_1.6.3.apk) 转发到webhook支持GET方式节点改变原配置要重新编辑兼容Android5.0待验证仅minSdkVersion改为21修复钉钉机器人没启用加签时url拼接错误问题
-------- --------

Binary file not shown.

View File

@ -10,9 +10,9 @@
{ {
"type": "SINGLE", "type": "SINGLE",
"filters": [], "filters": [],
"versionCode": 18, "versionCode": 19,
"versionName": "1.6.2", "versionName": "1.6.3",
"outputFile": "SmsForwarder_release_20210312_1.6.2.apk" "outputFile": "SmsForwarder_release_20210313_1.6.3.apk"
} }
] ]
} }

View File

@ -12,6 +12,7 @@ import android.widget.CompoundButton;
import android.widget.EditText; import android.widget.EditText;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.ListView; import android.widget.ListView;
import android.widget.RadioGroup;
import android.widget.Switch; import android.widget.Switch;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
@ -652,12 +653,12 @@ public class SenderActivity extends AppCompatActivity {
final EditText editTextWebNotifyName = view1.findViewById(R.id.editTextWebNotifyName); final EditText editTextWebNotifyName = view1.findViewById(R.id.editTextWebNotifyName);
if (senderModel != null) editTextWebNotifyName.setText(senderModel.getName()); if (senderModel != null) editTextWebNotifyName.setText(senderModel.getName());
final EditText editTextWebNotifyToken = view1.findViewById(R.id.editTextWebNotifyToken); final EditText editTextWebNotifyWebServer = view1.findViewById(R.id.editTextWebNotifyWebServer);
if (webNotifySettingVo != null) if (webNotifySettingVo != null) editTextWebNotifyWebServer.setText(webNotifySettingVo.getWebServer());
editTextWebNotifyToken.setText(webNotifySettingVo.getToken());
final EditText editTextWebNotifySecret = view1.findViewById(R.id.editTextWebNotifySecret); final EditText editTextWebNotifySecret = view1.findViewById(R.id.editTextWebNotifySecret);
if (webNotifySettingVo != null) if (webNotifySettingVo != null) editTextWebNotifySecret.setText(webNotifySettingVo.getSecret());
editTextWebNotifySecret.setText(webNotifySettingVo.getSecret()); final RadioGroup radioGroupWebNotifyMethod = (RadioGroup) view1.findViewById(R.id.radioGroupWebNotifyMethod);
if (webNotifySettingVo != null) radioGroupWebNotifyMethod.check(webNotifySettingVo.getWebNotifyMethodCheckId());
Button buttonbebnotifyok = view1.findViewById(R.id.buttonbebnotifyok); Button buttonbebnotifyok = view1.findViewById(R.id.buttonbebnotifyok);
Button buttonbebnotifydel = view1.findViewById(R.id.buttonbebnotifydel); Button buttonbebnotifydel = view1.findViewById(R.id.buttonbebnotifydel);
@ -679,8 +680,9 @@ public class SenderActivity extends AppCompatActivity {
newSenderModel.setType(TYPE_WEB_NOTIFY); newSenderModel.setType(TYPE_WEB_NOTIFY);
newSenderModel.setStatus(STATUS_ON); newSenderModel.setStatus(STATUS_ON);
WebNotifySettingVo webNotifySettingVoNew = new WebNotifySettingVo( WebNotifySettingVo webNotifySettingVoNew = new WebNotifySettingVo(
editTextWebNotifyToken.getText().toString(), editTextWebNotifyWebServer.getText().toString(),
editTextWebNotifySecret.getText().toString() editTextWebNotifySecret.getText().toString(),
(radioGroupWebNotifyMethod.getCheckedRadioButtonId() == R.id.radioWebNotifyMethodGet ? "GET" : "POST")
); );
newSenderModel.setJsonSetting(JSON.toJSONString(webNotifySettingVoNew)); newSenderModel.setJsonSetting(JSON.toJSONString(webNotifySettingVoNew));
SenderUtil.addSender(newSenderModel); SenderUtil.addSender(newSenderModel);
@ -691,8 +693,9 @@ public class SenderActivity extends AppCompatActivity {
senderModel.setType(TYPE_WEB_NOTIFY); senderModel.setType(TYPE_WEB_NOTIFY);
senderModel.setStatus(STATUS_ON); senderModel.setStatus(STATUS_ON);
WebNotifySettingVo webNotifySettingVoNew = new WebNotifySettingVo( WebNotifySettingVo webNotifySettingVoNew = new WebNotifySettingVo(
editTextWebNotifyToken.getText().toString(), editTextWebNotifyWebServer.getText().toString(),
editTextWebNotifySecret.getText().toString() editTextWebNotifySecret.getText().toString(),
(radioGroupWebNotifyMethod.getCheckedRadioButtonId() == R.id.radioWebNotifyMethodGet ? "GET" : "POST")
); );
senderModel.setJsonSetting(JSON.toJSONString(webNotifySettingVoNew)); senderModel.setJsonSetting(JSON.toJSONString(webNotifySettingVoNew));
SenderUtil.updateSender(senderModel); SenderUtil.updateSender(senderModel);
@ -718,17 +721,18 @@ public class SenderActivity extends AppCompatActivity {
buttonbebnotifytest.setOnClickListener(new View.OnClickListener() { buttonbebnotifytest.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
String token = editTextWebNotifyToken.getText().toString(); String webServer = editTextWebNotifyWebServer.getText().toString();
String secret = editTextWebNotifySecret.getText().toString(); String secret = editTextWebNotifySecret.getText().toString();
if (!token.isEmpty()) { String method = radioGroupWebNotifyMethod.getCheckedRadioButtonId() == R.id.radioWebNotifyMethodGet ? "GET" : "POST";
if (!webServer.isEmpty()) {
try { try {
SenderWebNotifyMsg.sendMsg(handler, token, secret, "SmsForwarder Title", "测试内容(content)@" + (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()))); SenderWebNotifyMsg.sendMsg(handler, webServer, secret, method, "SmsForwarder Title", "测试内容(content)@" + (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())));
} catch (Exception e) { } catch (Exception e) {
Toast.makeText(SenderActivity.this, "发送失败:" + e.getMessage(), Toast.LENGTH_LONG).show(); Toast.makeText(SenderActivity.this, "发送失败:" + e.getMessage(), Toast.LENGTH_LONG).show();
e.printStackTrace(); e.printStackTrace();
} }
} else { } else {
Toast.makeText(SenderActivity.this, "token 不能为空", Toast.LENGTH_LONG).show(); Toast.makeText(SenderActivity.this, "WebServer 不能为空", Toast.LENGTH_LONG).show();
} }
} }
}); });

View File

@ -1,30 +0,0 @@
package com.idormy.sms.forwarder.model.vo;
import java.io.Serializable;
public class FeedBackResult implements Serializable {
Integer code;
String message;
Object result;
public FeedBackResult() {
}
public String getMessage() {
return message;
}
public boolean isSuccess() {
return 1 == code;
}
@Override
public String toString() {
return "FeedBackResult{" +
"code=" + code +
", message='" + message + '\'' +
", result=" + result +
'}';
}
}

View File

@ -1,25 +1,29 @@
package com.idormy.sms.forwarder.model.vo; package com.idormy.sms.forwarder.model.vo;
import com.idormy.sms.forwarder.R;
import java.io.Serializable; import java.io.Serializable;
public class WebNotifySettingVo implements Serializable { public class WebNotifySettingVo implements Serializable {
private String token; private String webServer;
private String secret; private String secret;
private String method;
public WebNotifySettingVo() { public WebNotifySettingVo() {
} }
public WebNotifySettingVo(String token, String secret) { public WebNotifySettingVo(String webServer, String secret, String method) {
this.token = token; this.webServer = webServer;
this.secret = secret; this.secret = secret;
this.method = method;
} }
public String getToken() { public String getWebServer() {
return token; return webServer;
} }
public void setToken(String token) { public void setWebServer(String webServer) {
this.token = token; this.webServer = webServer;
} }
public String getSecret() { public String getSecret() {
@ -29,4 +33,20 @@ public class WebNotifySettingVo implements Serializable {
public void setSecret(String secret) { public void setSecret(String secret) {
this.secret = secret; this.secret = secret;
} }
public String getMethod() {
return method;
}
public void setMethod(String method) {
this.method = method;
}
public int getWebNotifyMethodCheckId() {
if (method == null || method.equals("POST")) {
return R.id.radioWebNotifyMethodPost;
} else {
return R.id.radioWebNotifyMethodGet;
}
}
} }

View File

@ -152,7 +152,7 @@ public class SendUtil {
WebNotifySettingVo webNotifySettingVo = JSON.parseObject(senderModel.getJsonSetting(), WebNotifySettingVo.class); WebNotifySettingVo webNotifySettingVo = JSON.parseObject(senderModel.getJsonSetting(), WebNotifySettingVo.class);
if (webNotifySettingVo != null) { if (webNotifySettingVo != null) {
try { try {
SenderWebNotifyMsg.sendMsg(handError, webNotifySettingVo.getToken(), webNotifySettingVo.getSecret(), smsVo.getMobile(), smsVo.getSmsVoForSend()); SenderWebNotifyMsg.sendMsg(handError, webNotifySettingVo.getWebServer(), webNotifySettingVo.getSecret(), webNotifySettingVo.getMethod(), smsVo.getMobile(), smsVo.getSmsVoForSend());
} catch (Exception e) { } catch (Exception e) {
Log.e(TAG, "senderSendMsg: SenderWebNotifyMsg error " + e.getMessage()); Log.e(TAG, "senderSendMsg: SenderWebNotifyMsg error " + e.getMessage());
} }

View File

@ -109,7 +109,6 @@ public class SenderDingdingMsg {
handError.sendMessage(msg); handError.sendMessage(msg);
} }
} }
@Override @Override

View File

@ -13,7 +13,6 @@ import javax.crypto.spec.SecretKeySpec;
import okhttp3.Call; import okhttp3.Call;
import okhttp3.Callback; import okhttp3.Callback;
import okhttp3.MediaType;
import okhttp3.MultipartBody; import okhttp3.MultipartBody;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
import okhttp3.Request; import okhttp3.Request;
@ -26,41 +25,50 @@ public class SenderWebNotifyMsg {
static String TAG = "SenderWebNotifyMsg"; static String TAG = "SenderWebNotifyMsg";
public static void sendMsg(final Handler handError, String token, String secret, String from, String content) throws Exception { public static void sendMsg(final Handler handError, String webServer, String secret, String method, String from, String content) throws Exception {
Log.i(TAG, "sendMsg token:" + token + " from:" + from + " content:" + content); Log.i(TAG, "sendMsg webServer:" + webServer + " from:" + from + " content:" + content);
if (token == null || token.isEmpty()) { if (webServer == null || webServer.isEmpty()) {
return; return;
} }
OkHttpClient client = new OkHttpClient().newBuilder() Long timestamp = System.currentTimeMillis();
.build(); String sign = "";
MediaType mediaType = MediaType.parse("text/plain");
MultipartBody.Builder builder = new MultipartBody.Builder().setType(MultipartBody.FORM)
.addFormDataPart("from", from)
.addFormDataPart("content", content);
if (secret != null && !secret.isEmpty()) { if (secret != null && !secret.isEmpty()) {
Long timestamp = System.currentTimeMillis();
String stringToSign = timestamp + "\n" + secret; String stringToSign = timestamp + "\n" + secret;
Mac mac = Mac.getInstance("HmacSHA256"); Mac mac = Mac.getInstance("HmacSHA256");
mac.init(new SecretKeySpec(secret.getBytes("UTF-8"), "HmacSHA256")); mac.init(new SecretKeySpec(secret.getBytes("UTF-8"), "HmacSHA256"));
byte[] signData = mac.doFinal(stringToSign.getBytes("UTF-8")); byte[] signData = mac.doFinal(stringToSign.getBytes("UTF-8"));
String sign = URLEncoder.encode(new String(Base64.encode(signData, Base64.NO_WRAP)), "UTF-8"); sign = URLEncoder.encode(new String(Base64.encode(signData, Base64.NO_WRAP)), "UTF-8");
Log.i(TAG, "sign:" + sign); Log.i(TAG, "sign:" + sign);
builder.addFormDataPart("timestamp", String.valueOf(timestamp));
builder.addFormDataPart("sign", sign);
} }
RequestBody body = builder.build(); Request request;
Request request = new Request.Builder() if (method.equals("GET")) {
.url(token) webServer += (webServer.contains("?") ? "&" : "?") + "from=" + URLEncoder.encode(from, "UTF-8");
.method("POST", body) webServer += "&content=" + URLEncoder.encode(content, "UTF-8");
.build(); if (secret != null && !secret.isEmpty()) {
// Response response = client.newCall(request).execute(); webServer += "&timestamp=" + timestamp;
webServer += "&sign=" + sign;
}
Log.d(TAG, "method = GET, Url = " + webServer);
request = new Request.Builder().url(webServer).get().build();
} else {
MultipartBody.Builder builder = new MultipartBody.Builder().setType(MultipartBody.FORM)
.addFormDataPart("from", from)
.addFormDataPart("content", content);
if (secret != null && !secret.isEmpty()) {
builder.addFormDataPart("timestamp", String.valueOf(timestamp));
builder.addFormDataPart("sign", sign);
}
RequestBody body = builder.build();
Log.d(TAG, "method = POST, Body = " + body);
request = new Request.Builder().url(webServer).method("POST", body).build();
}
OkHttpClient client = new OkHttpClient().newBuilder().build();
Call call = client.newCall(request); Call call = client.newCall(request);
call.enqueue(new Callback() { call.enqueue(new Callback() {
@Override @Override
@ -81,7 +89,7 @@ public class SenderWebNotifyMsg {
@Override @Override
public void onResponse(Call call, Response response) throws IOException { public void onResponse(Call call, Response response) throws IOException {
final String responseStr = response.body().string(); final String responseStr = response.body().string();
Log.d(TAG, "Code" + String.valueOf(response.code()) + responseStr); Log.d(TAG, "Code" + response.code() + " Response" + responseStr);
if (handError != null) { if (handError != null) {
android.os.Message msg = new android.os.Message(); android.os.Message msg = new android.os.Message();
@ -90,7 +98,6 @@ public class SenderWebNotifyMsg {
bundle.putString("DATA", "发送状态:" + responseStr); bundle.putString("DATA", "发送状态:" + responseStr);
msg.setData(bundle); msg.setData(bundle);
handError.sendMessage(msg); handError.sendMessage(msg);
Log.d(TAG, "Coxxyyde" + String.valueOf(response.code()) + responseStr);
} }
} }

View File

@ -327,6 +327,7 @@ public class PhoneUtils {
Log.d(TAG, "Build.VERSION.SDK_INT = " + Build.VERSION.SDK_INT); Log.d(TAG, "Build.VERSION.SDK_INT = " + Build.VERSION.SDK_INT);
Log.d(TAG, "Build.VERSION_CODES.LOLLIPOP_MR1 = " + Build.VERSION_CODES.LOLLIPOP_MR1); Log.d(TAG, "Build.VERSION_CODES.LOLLIPOP_MR1 = " + Build.VERSION_CODES.LOLLIPOP_MR1);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
Log.d(TAG, "1.版本超过5.1,调用系统方法");
//1.版本超过5.1调用系统方法 //1.版本超过5.1调用系统方法
SubscriptionManager mSubscriptionManager = (SubscriptionManager) context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); SubscriptionManager mSubscriptionManager = (SubscriptionManager) context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
List<SubscriptionInfo> activeSubscriptionInfoList = null; List<SubscriptionInfo> activeSubscriptionInfoList = null;
@ -354,16 +355,18 @@ public class PhoneUtils {
simInfo.mImsi = getReflexMethodWithId(context, "getSubscriberId", String.valueOf(subscriptionInfo.getSubscriptionId())); simInfo.mImsi = getReflexMethodWithId(context, "getSubscriberId", String.valueOf(subscriptionInfo.getSubscriptionId()));
} catch (MethodNotFoundException ignored) { } catch (MethodNotFoundException ignored) {
} }
Log.d(TAG, String.valueOf(simInfo));
infos.add(simInfo); infos.add(simInfo);
} }
} }
} else { } else {
Log.d(TAG, "2.版本低于5.1的系统,首先调用数据库,看能不能访问到");
//2.版本低于5.1的系统首先调用数据库看能不能访问到 //2.版本低于5.1的系统首先调用数据库看能不能访问到
Uri uri = Uri.parse("content://telephony/siminfo"); //访问raw_contacts表 Uri uri = Uri.parse("content://telephony/siminfo"); //访问raw_contacts表
ContentResolver resolver = context.getContentResolver(); ContentResolver resolver = context.getContentResolver();
Cursor cursor = resolver.query(uri, new String[]{"_id", "icc_id", "sim_id", "display_name", "carrier_name", "name_source", "color", "number", "display_number_format", "data_roaming", "mcc", "mnc"}, null, null, null); Cursor cursor = resolver.query(uri, new String[]{"_id", "icc_id", "sim_id", "display_name", "carrier_name", "name_source", "color", "number", "display_number_format", "data_roaming", "mcc", "mnc"}, null, null, null);
if (cursor != null) { if (cursor != null && cursor.moveToFirst()) {
while (cursor.moveToNext()) { do {
SimInfo simInfo = new SimInfo(); SimInfo simInfo = new SimInfo();
simInfo.mCarrierName = cursor.getString(cursor.getColumnIndex("carrier_name")); simInfo.mCarrierName = cursor.getString(cursor.getColumnIndex("carrier_name"));
simInfo.mIccId = cursor.getString(cursor.getColumnIndex("icc_id")); simInfo.mIccId = cursor.getString(cursor.getColumnIndex("icc_id"));
@ -377,12 +380,14 @@ public class PhoneUtils {
simInfo.mImsi = getReflexMethodWithId(context, "getSubscriberId", String.valueOf(id)); simInfo.mImsi = getReflexMethodWithId(context, "getSubscriberId", String.valueOf(id));
} catch (MethodNotFoundException ignored) { } catch (MethodNotFoundException ignored) {
} }
Log.d(TAG, String.valueOf(simInfo));
infos.add(simInfo); infos.add(simInfo);
} } while (cursor.moveToNext());
cursor.close(); cursor.close();
} }
} }
Log.d(TAG, "3.通过反射读取卡槽信息最后通过IMEI去重");
//3.通过反射读取卡槽信息最后通过IMEI去重 //3.通过反射读取卡槽信息最后通过IMEI去重
for (int i = 0; i < getSimCount(); i++) { for (int i = 0; i < getSimCount(); i++) {
infos.add(getReflexSimInfo(context, i)); infos.add(getReflexSimInfo(context, i));

View File

@ -30,6 +30,43 @@
android:text="" /> android:text="" />
</LinearLayout> </LinearLayout>
<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:paddingTop="5dp"
android:text="请求方式" />
<RadioGroup
android:id="@+id/radioGroupWebNotifyMethod"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:orientation="horizontal">
<RadioButton
android:id="@+id/radioWebNotifyMethodPost"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="POST" />
<RadioButton
android:id="@+id/radioWebNotifyMethodGet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="GET" />
</RadioGroup>
</LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
@ -40,10 +77,10 @@
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="设置Token示例:https://a.b.com/msg?token=xyz" /> android:text="设置WebServer例如https://a.b.com/msg?token=xyz" />
<EditText <EditText
android:id="@+id/editTextWebNotifyToken" android:id="@+id/editTextWebNotifyWebServer"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:ems="14" android:ems="14"

View File

@ -1,4 +1,4 @@
ext { ext {
appVersionCode = 18 appVersionCode = 19
appVersionName = "1.6.2" appVersionName = "1.6.3"
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 206 KiB

After

Width:  |  Height:  |  Size: 98 KiB