diff --git a/README.md b/README.md index 0d4236a1..509bc1b9 100644 --- a/README.md +++ b/README.md @@ -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拼接错误问题 -------- diff --git a/app/release/SmsForwarder_release_20210313_1.6.3.apk b/app/release/SmsForwarder_release_20210313_1.6.3.apk new file mode 100644 index 00000000..62fa7e10 Binary files /dev/null and b/app/release/SmsForwarder_release_20210313_1.6.3.apk differ diff --git a/app/release/output-metadata.json b/app/release/output-metadata.json index d276d06f..11d46b5e 100644 --- a/app/release/output-metadata.json +++ b/app/release/output-metadata.json @@ -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" } ] } \ No newline at end of file diff --git a/app/src/main/java/com/idormy/sms/forwarder/SenderActivity.java b/app/src/main/java/com/idormy/sms/forwarder/SenderActivity.java index 2ca78ae8..fd0255b4 100644 --- a/app/src/main/java/com/idormy/sms/forwarder/SenderActivity.java +++ b/app/src/main/java/com/idormy/sms/forwarder/SenderActivity.java @@ -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(); } } }); diff --git a/app/src/main/java/com/idormy/sms/forwarder/model/vo/FeedBackResult.java b/app/src/main/java/com/idormy/sms/forwarder/model/vo/FeedBackResult.java deleted file mode 100644 index 1c85a619..00000000 --- a/app/src/main/java/com/idormy/sms/forwarder/model/vo/FeedBackResult.java +++ /dev/null @@ -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 + - '}'; - } -} diff --git a/app/src/main/java/com/idormy/sms/forwarder/model/vo/WebNotifySettingVo.java b/app/src/main/java/com/idormy/sms/forwarder/model/vo/WebNotifySettingVo.java index 7c4232be..96b26c52 100644 --- a/app/src/main/java/com/idormy/sms/forwarder/model/vo/WebNotifySettingVo.java +++ b/app/src/main/java/com/idormy/sms/forwarder/model/vo/WebNotifySettingVo.java @@ -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; + } + } } diff --git a/app/src/main/java/com/idormy/sms/forwarder/sender/SendUtil.java b/app/src/main/java/com/idormy/sms/forwarder/sender/SendUtil.java index 7c1625f7..a4315a8b 100644 --- a/app/src/main/java/com/idormy/sms/forwarder/sender/SendUtil.java +++ b/app/src/main/java/com/idormy/sms/forwarder/sender/SendUtil.java @@ -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()); } diff --git a/app/src/main/java/com/idormy/sms/forwarder/sender/SenderDingdingMsg.java b/app/src/main/java/com/idormy/sms/forwarder/sender/SenderDingdingMsg.java index ae1bb305..863dd6c1 100644 --- a/app/src/main/java/com/idormy/sms/forwarder/sender/SenderDingdingMsg.java +++ b/app/src/main/java/com/idormy/sms/forwarder/sender/SenderDingdingMsg.java @@ -109,7 +109,6 @@ public class SenderDingdingMsg { handError.sendMessage(msg); } - } @Override diff --git a/app/src/main/java/com/idormy/sms/forwarder/sender/SenderWebNotifyMsg.java b/app/src/main/java/com/idormy/sms/forwarder/sender/SenderWebNotifyMsg.java index 9bbcddc5..ef1b8d55 100644 --- a/app/src/main/java/com/idormy/sms/forwarder/sender/SenderWebNotifyMsg.java +++ b/app/src/main/java/com/idormy/sms/forwarder/sender/SenderWebNotifyMsg.java @@ -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 += "×tamp=" + 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); } } diff --git a/app/src/main/java/com/idormy/sms/forwarder/utils/PhoneUtils.java b/app/src/main/java/com/idormy/sms/forwarder/utils/PhoneUtils.java index 728135f3..76ac84bb 100644 --- a/app/src/main/java/com/idormy/sms/forwarder/utils/PhoneUtils.java +++ b/app/src/main/java/com/idormy/sms/forwarder/utils/PhoneUtils.java @@ -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 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)); diff --git a/app/src/main/res/layout/alert_dialog_setview_webnotify.xml b/app/src/main/res/layout/alert_dialog_setview_webnotify.xml index 7483bd79..23295b1c 100644 --- a/app/src/main/res/layout/alert_dialog_setview_webnotify.xml +++ b/app/src/main/res/layout/alert_dialog_setview_webnotify.xml @@ -30,6 +30,43 @@ android:text="" /> + + + + + + + + + + + + + + + android:text="设置WebServer:例如:https://a.b.com/msg?token=xyz" />