转发到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] 转发到邮箱支持SMTP
- [x] 转发到Bark支持验证码/动态密码自动复制)
- [x] 转发到webhook支持单个web页面[向设置的url发送POST请求](doc/POST_WEB.md)
- [x] 转发到webhook支持单个web页面[向设置的url发送POST/GET请求](doc/POST_WEB.md)
- [x] 转发到企业微信群机器人
- [x] 转发到企业微信应用消息
- [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.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.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",
"filters": [],
"versionCode": 18,
"versionName": "1.6.2",
"outputFile": "SmsForwarder_release_20210312_1.6.2.apk"
"versionCode": 19,
"versionName": "1.6.3",
"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.LinearLayout;
import android.widget.ListView;
import android.widget.RadioGroup;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;
@ -652,12 +653,12 @@ public class SenderActivity extends AppCompatActivity {
final EditText editTextWebNotifyName = view1.findViewById(R.id.editTextWebNotifyName);
if (senderModel != null) editTextWebNotifyName.setText(senderModel.getName());
final EditText editTextWebNotifyToken = view1.findViewById(R.id.editTextWebNotifyToken);
if (webNotifySettingVo != null)
editTextWebNotifyToken.setText(webNotifySettingVo.getToken());
final EditText editTextWebNotifyWebServer = view1.findViewById(R.id.editTextWebNotifyWebServer);
if (webNotifySettingVo != null) editTextWebNotifyWebServer.setText(webNotifySettingVo.getWebServer());
final EditText editTextWebNotifySecret = view1.findViewById(R.id.editTextWebNotifySecret);
if (webNotifySettingVo != null)
editTextWebNotifySecret.setText(webNotifySettingVo.getSecret());
if (webNotifySettingVo != null) 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 buttonbebnotifydel = view1.findViewById(R.id.buttonbebnotifydel);
@ -679,8 +680,9 @@ public class SenderActivity extends AppCompatActivity {
newSenderModel.setType(TYPE_WEB_NOTIFY);
newSenderModel.setStatus(STATUS_ON);
WebNotifySettingVo webNotifySettingVoNew = new WebNotifySettingVo(
editTextWebNotifyToken.getText().toString(),
editTextWebNotifySecret.getText().toString()
editTextWebNotifyWebServer.getText().toString(),
editTextWebNotifySecret.getText().toString(),
(radioGroupWebNotifyMethod.getCheckedRadioButtonId() == R.id.radioWebNotifyMethodGet ? "GET" : "POST")
);
newSenderModel.setJsonSetting(JSON.toJSONString(webNotifySettingVoNew));
SenderUtil.addSender(newSenderModel);
@ -691,8 +693,9 @@ public class SenderActivity extends AppCompatActivity {
senderModel.setType(TYPE_WEB_NOTIFY);
senderModel.setStatus(STATUS_ON);
WebNotifySettingVo webNotifySettingVoNew = new WebNotifySettingVo(
editTextWebNotifyToken.getText().toString(),
editTextWebNotifySecret.getText().toString()
editTextWebNotifyWebServer.getText().toString(),
editTextWebNotifySecret.getText().toString(),
(radioGroupWebNotifyMethod.getCheckedRadioButtonId() == R.id.radioWebNotifyMethodGet ? "GET" : "POST")
);
senderModel.setJsonSetting(JSON.toJSONString(webNotifySettingVoNew));
SenderUtil.updateSender(senderModel);
@ -718,17 +721,18 @@ public class SenderActivity extends AppCompatActivity {
buttonbebnotifytest.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String token = editTextWebNotifyToken.getText().toString();
String webServer = editTextWebNotifyWebServer.getText().toString();
String secret = editTextWebNotifySecret.getText().toString();
if (!token.isEmpty()) {
String method = radioGroupWebNotifyMethod.getCheckedRadioButtonId() == R.id.radioWebNotifyMethodGet ? "GET" : "POST";
if (!webServer.isEmpty()) {
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) {
Toast.makeText(SenderActivity.this, "发送失败:" + e.getMessage(), Toast.LENGTH_LONG).show();
e.printStackTrace();
}
} 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;
import com.idormy.sms.forwarder.R;
import java.io.Serializable;
public class WebNotifySettingVo implements Serializable {
private String token;
private String webServer;
private String secret;
private String method;
public WebNotifySettingVo() {
}
public WebNotifySettingVo(String token, String secret) {
this.token = token;
public WebNotifySettingVo(String webServer, String secret, String method) {
this.webServer = webServer;
this.secret = secret;
this.method = method;
}
public String getToken() {
return token;
public String getWebServer() {
return webServer;
}
public void setToken(String token) {
this.token = token;
public void setWebServer(String webServer) {
this.webServer = webServer;
}
public String getSecret() {
@ -29,4 +33,20 @@ public class WebNotifySettingVo implements Serializable {
public void setSecret(String 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);
if (webNotifySettingVo != null) {
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) {
Log.e(TAG, "senderSendMsg: SenderWebNotifyMsg error " + e.getMessage());
}

View File

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

View File

@ -13,7 +13,6 @@ import javax.crypto.spec.SecretKeySpec;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
@ -26,41 +25,50 @@ public class SenderWebNotifyMsg {
static String TAG = "SenderWebNotifyMsg";
public static void sendMsg(final Handler handError, String token, String secret, String from, String content) throws Exception {
Log.i(TAG, "sendMsg token:" + token + " from:" + from + " content:" + content);
public static void sendMsg(final Handler handError, String webServer, String secret, String method, String from, String content) throws Exception {
Log.i(TAG, "sendMsg webServer:" + webServer + " from:" + from + " content:" + content);
if (token == null || token.isEmpty()) {
if (webServer == null || webServer.isEmpty()) {
return;
}
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("text/plain");
MultipartBody.Builder builder = new MultipartBody.Builder().setType(MultipartBody.FORM)
.addFormDataPart("from", from)
.addFormDataPart("content", content);
Long timestamp = System.currentTimeMillis();
String sign = "";
if (secret != null && !secret.isEmpty()) {
Long timestamp = System.currentTimeMillis();
String stringToSign = timestamp + "\n" + secret;
Mac mac = Mac.getInstance("HmacSHA256");
mac.init(new SecretKeySpec(secret.getBytes("UTF-8"), "HmacSHA256"));
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);
builder.addFormDataPart("timestamp", String.valueOf(timestamp));
builder.addFormDataPart("sign", sign);
}
RequestBody body = builder.build();
Request request = new Request.Builder()
.url(token)
.method("POST", body)
.build();
// Response response = client.newCall(request).execute();
Request request;
if (method.equals("GET")) {
webServer += (webServer.contains("?") ? "&" : "?") + "from=" + URLEncoder.encode(from, "UTF-8");
webServer += "&content=" + URLEncoder.encode(content, "UTF-8");
if (secret != null && !secret.isEmpty()) {
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.enqueue(new Callback() {
@Override
@ -81,7 +89,7 @@ public class SenderWebNotifyMsg {
@Override
public void onResponse(Call call, Response response) throws IOException {
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) {
android.os.Message msg = new android.os.Message();
@ -90,7 +98,6 @@ public class SenderWebNotifyMsg {
bundle.putString("DATA", "发送状态:" + responseStr);
msg.setData(bundle);
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_CODES.LOLLIPOP_MR1 = " + Build.VERSION_CODES.LOLLIPOP_MR1);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
Log.d(TAG, "1.版本超过5.1,调用系统方法");
//1.版本超过5.1调用系统方法
SubscriptionManager mSubscriptionManager = (SubscriptionManager) context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
List<SubscriptionInfo> activeSubscriptionInfoList = null;
@ -354,16 +355,18 @@ public class PhoneUtils {
simInfo.mImsi = getReflexMethodWithId(context, "getSubscriberId", String.valueOf(subscriptionInfo.getSubscriptionId()));
} catch (MethodNotFoundException ignored) {
}
Log.d(TAG, String.valueOf(simInfo));
infos.add(simInfo);
}
}
} else {
Log.d(TAG, "2.版本低于5.1的系统,首先调用数据库,看能不能访问到");
//2.版本低于5.1的系统首先调用数据库看能不能访问到
Uri uri = Uri.parse("content://telephony/siminfo"); //访问raw_contacts表
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);
if (cursor != null) {
while (cursor.moveToNext()) {
if (cursor != null && cursor.moveToFirst()) {
do {
SimInfo simInfo = new SimInfo();
simInfo.mCarrierName = cursor.getString(cursor.getColumnIndex("carrier_name"));
simInfo.mIccId = cursor.getString(cursor.getColumnIndex("icc_id"));
@ -377,12 +380,14 @@ public class PhoneUtils {
simInfo.mImsi = getReflexMethodWithId(context, "getSubscriberId", String.valueOf(id));
} catch (MethodNotFoundException ignored) {
}
Log.d(TAG, String.valueOf(simInfo));
infos.add(simInfo);
}
} while (cursor.moveToNext());
cursor.close();
}
}
Log.d(TAG, "3.通过反射读取卡槽信息最后通过IMEI去重");
//3.通过反射读取卡槽信息最后通过IMEI去重
for (int i = 0; i < getSimCount(); i++) {
infos.add(getReflexSimInfo(context, i));

View File

@ -30,6 +30,43 @@
android:text="" />
</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
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -40,10 +77,10 @@
<TextView
android:layout_width="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
android:id="@+id/editTextWebNotifyToken"
android:id="@+id/editTextWebNotifyWebServer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="14"

View File

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 206 KiB

After

Width:  |  Height:  |  Size: 98 KiB