Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upload sms to server #74

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public interface PrefConst {

// SMS Code
String KEY_SHOW_TOAST = "pref_show_toast";
String KEY_UPLOAD_SERVER = "pre_upload_sms";
String KEY_SERVER_URL ="pref_url";
String KEY_COPY_TO_CLIPBOARD = "pref_copy_to_clipboard";
String KEY_ENABLE_AUTO_INPUT_CODE = "pref_enable_auto_input_code";
String KEY_AUTO_INPUT_CODE_DELAY = "pref_auto_input_code_delay";
Expand All @@ -25,6 +27,7 @@ public interface PrefConst {
String KEY_DEDUPLICATE_SMS = "pref_deduplicate_sms";



// Code Notification
String KEY_SHOW_CODE_NOTIFICATION = "pref_show_code_notification";
String KEY_AUTO_CANCEL_CODE_NOTIFICATION = "pref_auto_cancel_code_notification";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.tianma.xsmscode.common.utils;

import android.text.TextUtils;
import android.util.Log;

import org.json.JSONObject;

import java.util.HashMap;

import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

public class RequestUtils {
private int times = 0;

public synchronized void run(HashMap<String, String> data, String str_url) {
String errmsg = null;
while (times < 5) {
errmsg = "";
OkHttpClient client = new OkHttpClient();

JSONObject jsonBody = new JSONObject(data);
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, jsonBody.toString());

Request request = new Request.Builder()
.url(str_url)
.post(body)
.build();

try (Response response = client.newCall(request).execute()) {
String html = response.body().string();
XLog.i(html);
if (response.isSuccessful()) {
XLog.i("请求成功");
} else {
errmsg = String.format("请求失败,状态码为:%s", response.code());
XLog.e("请求失败:%s", html.substring(0, 20));
continue;
}
break;
} catch (Exception e) {
times += 1;
errmsg = Log.getStackTraceString(e);
XLog.e(errmsg);
}
}
if (!TextUtils.isEmpty(errmsg)) {
XLog.e(errmsg);
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ public static boolean shouldShowToast(XSharedPreferences preferences) {
return preferences.getBoolean(PrefConst.KEY_SHOW_TOAST, true);
}

public static boolean uploadToServer(XSharedPreferences preferences) {
// 是否上报服务器
return preferences.getBoolean(PrefConst.KEY_UPLOAD_SERVER, true);
}
public static String getServerUrl(XSharedPreferences preferences) {
// 是否上报服务器
return preferences.getString(PrefConst.KEY_SERVER_URL, "");
}
/**
* 获取短信验证码关键字
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.tianma.xsmscode.xp.hook.code.action.impl.RecordSmsAction;
import com.tianma.xsmscode.xp.hook.code.action.impl.SmsParseAction;
import com.tianma.xsmscode.xp.hook.code.action.impl.ToastAction;
import com.tianma.xsmscode.xp.hook.code.action.impl.UploadAction;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
Expand Down Expand Up @@ -94,6 +95,11 @@ public ParseResult parse() {
// 显示Toast Action
mUIHandler.post(new ToastAction(mPluginContext, mPhoneContext, smsMsg, xsp));

// 上传 Action
mUIHandler.post(new UploadAction(mPluginContext, mPhoneContext, smsMsg, xsp));



// 自动输入 Action
if (XSPUtils.autoInputCodeEnabled(xsp)) {
AutoInputAction autoInputAction = new AutoInputAction(mPluginContext, mPhoneContext, smsMsg, xsp);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.tianma.xsmscode.xp.hook.code.action.impl;

import android.content.Context;
import android.os.Bundle;
import android.widget.Toast;

import com.github.tianma8023.xposed.smscode.R;
import com.tianma.xsmscode.common.utils.RequestUtils;
import com.tianma.xsmscode.common.utils.XLog;
import com.tianma.xsmscode.common.utils.XSPUtils;
import com.tianma.xsmscode.data.db.entity.SmsMsg;
import com.tianma.xsmscode.xp.hook.code.action.RunnableAction;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import de.robv.android.xposed.XSharedPreferences;

/**
* 显示验证码Toast
*/
public class UploadAction extends RunnableAction {

public UploadAction(Context pluginContext, Context phoneContext, SmsMsg smsMsg, XSharedPreferences xsp) {
super(pluginContext, phoneContext, smsMsg, xsp);
}

@Override
public Bundle action() {
if (XSPUtils.uploadToServer(xsp)) {
uploadSmsToServer();
}
return null;
}

private void uploadSmsToServer() {
String text = mSmsMsg.getBody(); //接收到验证的信息
String code = mSmsMsg.getSmsCode(); //接收到验证的信息
HashMap<String, String> uploadMap = new HashMap<>();
uploadMap.put("msg",text);
uploadMap.put("code",code);
String url = XSPUtils.getServerUrl(xsp);
XLog.i("当前的url为:"+url);

new Thread(new Runnable() {
@Override
public void run() {
new RequestUtils().run(uploadMap,url);

}
}).start();

if (mPhoneContext != null) {
Toast.makeText(mPhoneContext, text, Toast.LENGTH_LONG).show();
}
}
}
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_upload.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/preferenceIconColor"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M12,4C8.13,4 5,7.13 5,11h2c0,-2.76 2.24,-5 5,-5s5,2.24 5,5h2c0,-3.87 -3.13,-7 -7,-7zM19.42,13h-1.79C17.55,15.24 15.43,17 13,17s-4.55,-1.76 -4.63,-3.99H6.58L12,7.58L19.42,13zM4,18h16v2H4v-2z"/>
</vector>
4 changes: 4 additions & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
<string name="pref_sms_code_title">验证码</string>
<string name="pref_show_toast_title">显示Toast</string>
<string name="pref_show_toast_summary">接收到验证码时显示Toast</string>
<string name="pref_upload_sms_title">上传服务器</string>
<string name="pref_upload_sms_summary">上传到指定的服务器</string>
<string name="pref_upload_url_title">服务器URL</string>
<string name="pref_upload_url_summary">点击修改指定要上传的URL</string>
<string name="pref_copy_to_clipboard_title">复制到剪切板</string>
<string name="pref_copy_to_clipboard_summary">提取成功后复制验证码到系统剪切板</string>
<string name="pref_block_sms_title">拦截验证码短信</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/common_strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<string name="pref_choose_theme">pref_choose_theme</string>

<string name="pref_show_toast">pref_show_toast</string>
<string name="pref_url">pref_url</string>
<string name="pref_upload_sms">pref_upload_sms</string>
<string name="pref_copy_to_clipboard">pref_copy_to_clipboard</string>
<string name="pref_block_sms">pref_block_sms</string>
<string name="pref_deduplicate_sms">pref_deduplicate_sms</string>
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@
<string name="pref_sms_code_title">SMS Code</string>
<string name="pref_show_toast_title">Show toast</string>
<string name="pref_show_toast_summary">Show toast when the SMS code is copied</string>
<!--upload to server-->
<string name="pref_upload_sms_title">Upload Sms to Server</string>
<string name="pref_upload_sms_summary">Upload Sms to Your Server</string>

<string name="pref_upload_url_title">Server URL</string>
<string name="pref_upload_url_summary">Enter the Server URL</string>

<string name="pref_copy_to_clipboard_title">Copy to clipboard</string>
<string name="pref_copy_to_clipboard_summary">Copy code to clipboard if it\'s extracted</string>
<string name="pref_block_sms_title">Block code SMS</string>
Expand Down
18 changes: 18 additions & 0 deletions app/src/main/res/xml/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,24 @@
android:summary="@string/pref_show_toast_summary"
android:title="@string/pref_show_toast_title"/>

<EditTextPreference
android:defaultValue=""
android:key="@string/pref_url"
android:icon="@drawable/ic_upload"
android:title="@string/pref_upload_url_title"
android:summary="@string/pref_upload_url_summary"
android:inputType="textUri"
android:selectAllOnFocus="true"
android:singleLine="true" />

<SwitchPreference
android:defaultValue="false"
android:dependency="@string/pref_enable"
android:icon="@drawable/ic_upload"
android:key="@string/pref_upload_sms"
android:summary="@string/pref_upload_sms_summary"
android:title="@string/pref_upload_sms_title"/>

<SwitchPreference
android:defaultValue="false"
android:dependency="@string/pref_enable"
Expand Down