From d70fc4d59670a3b563864f05db6756c13e7f1da2 Mon Sep 17 00:00:00 2001 From: weihuagu Date: Sun, 19 Aug 2018 18:54:51 +0800 Subject: [PATCH] first v0.1 --- README.md | 30 +++ app/.gitignore | 1 + app/build.gradle | 46 +++++ app/proguard-rules.pro | 21 ++ .../com/xinri/ExampleInstrumentedTest.java | 26 +++ app/src/main/AndroidManifest.xml | 25 +++ .../weihuagu/receiptnotice/AsyncResponse.java | 8 + .../com/weihuagu/receiptnotice/Constants.java | 98 ++++++++++ .../weihuagu/receiptnotice/MainActivity.java | 94 +++++++++ .../com/weihuagu/receiptnotice/NLService.java | 185 ++++++++++++++++++ .../com/weihuagu/receiptnotice/PostTask.java | 113 +++++++++++ .../com/weihuagu/receiptnotice/UrlUtil.java | 80 ++++++++ .../drawable-v24/ic_launcher_foreground.xml | 34 ++++ app/src/main/res/drawable/ic_launcher.png | Bin 0 -> 3777 bytes .../res/drawable/ic_launcher_background.xml | 170 ++++++++++++++++ app/src/main/res/layout/activity_main.xml | 28 +++ .../res/mipmap-anydpi-v26/ic_launcher.xml | 5 + .../mipmap-anydpi-v26/ic_launcher_round.xml | 5 + app/src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 3056 bytes .../res/mipmap-hdpi/ic_launcher_round.png | Bin 0 -> 5024 bytes app/src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2096 bytes .../res/mipmap-mdpi/ic_launcher_round.png | Bin 0 -> 2858 bytes app/src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4569 bytes .../res/mipmap-xhdpi/ic_launcher_round.png | Bin 0 -> 7098 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 6464 bytes .../res/mipmap-xxhdpi/ic_launcher_round.png | Bin 0 -> 10676 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 9250 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.png | Bin 0 -> 15523 bytes app/src/main/res/values/colors.xml | 6 + app/src/main/res/values/strings.xml | 3 + app/src/main/res/values/styles.xml | 11 ++ .../test/java/com/xinri/ExampleUnitTest.java | 17 ++ build.gradle | 27 +++ gradle.properties | 17 ++ gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 53636 bytes gradle/wrapper/gradle-wrapper.properties | 6 + gradlew | 160 +++++++++++++++ gradlew.bat | 90 +++++++++ settings.gradle | 1 + 39 files changed, 1307 insertions(+) create mode 100644 README.md create mode 100644 app/.gitignore create mode 100644 app/build.gradle create mode 100644 app/proguard-rules.pro create mode 100644 app/src/androidTest/java/com/xinri/ExampleInstrumentedTest.java create mode 100644 app/src/main/AndroidManifest.xml create mode 100644 app/src/main/java/com/weihuagu/receiptnotice/AsyncResponse.java create mode 100644 app/src/main/java/com/weihuagu/receiptnotice/Constants.java create mode 100644 app/src/main/java/com/weihuagu/receiptnotice/MainActivity.java create mode 100644 app/src/main/java/com/weihuagu/receiptnotice/NLService.java create mode 100644 app/src/main/java/com/weihuagu/receiptnotice/PostTask.java create mode 100644 app/src/main/java/com/weihuagu/receiptnotice/UrlUtil.java create mode 100644 app/src/main/res/drawable-v24/ic_launcher_foreground.xml create mode 100644 app/src/main/res/drawable/ic_launcher.png create mode 100644 app/src/main/res/drawable/ic_launcher_background.xml create mode 100644 app/src/main/res/layout/activity_main.xml create mode 100644 app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml create mode 100644 app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png create mode 100644 app/src/main/res/values/colors.xml create mode 100644 app/src/main/res/values/strings.xml create mode 100644 app/src/main/res/values/styles.xml create mode 100644 app/src/test/java/com/xinri/ExampleUnitTest.java create mode 100644 build.gradle create mode 100644 gradle.properties create mode 100644 gradle/wrapper/gradle-wrapper.jar create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100755 gradlew create mode 100644 gradlew.bat create mode 100644 settings.gradle diff --git a/README.md b/README.md new file mode 100644 index 0000000..ce1666f --- /dev/null +++ b/README.md @@ -0,0 +1,30 @@ +# 没有办法的获取到收款推送的办法 + +#### 目前个人收款现状 + +##### 个人申请支付接口现状 + +- 原生支付宝,微信支付 + + - `支付宝只服务于有营业执照、个体工商户的商户。就算你有钱但没实体店铺在某宝上也是买不到的。截止目前(2018-01-01)无法以个人身份(或以个人为主体)直接申请API。网上那些 “个人申请支付宝xx接口” 的文章就不要看了,节约时间。微信同支付宝,不支付个人申请。` + + - 结论:不可行 +##### 原先的方法不管用了 + +- 最好的方法是抓取与支付宝绑定的邮件,但是只要你绑定了电话,支付包就不发邮件和短信提醒你有收款到帐了。 + +- 抓自己支付宝网页版的账单,这个关键在于复制出cookie,原先一个cookie可以使用一个月,现在是动态的5分钟就变了。使用模拟登录,支付宝的风控很厉害,导致模拟登录容易被封。 + + + +##### 实在是没有法子的办法 + +- 手机安装一个app,然后这个服务监听手机收到的通知,如果是收到收款的通知,就把信息推送到指定的url去。 + +##### 本软件使用方法 + +- 安装后先将软件加入系统白名单,各个安卓系统的方法各有不同 + +- 打开软件自动跳转到获取通知权限页面,允许本应用监控通知 + +- 返回到软件主页,填写你要接受收款信息通知的url,软件在接到收款通知后,会用post的方法,发送json信息. diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..55e3615 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,46 @@ + +def keystorePropertiesFile = rootProject.file("./app/key.properties") +def keystoreProperties = new Properties() +keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) + +apply plugin: 'com.android.application' +android { + compileSdkVersion 27 + defaultConfig { + applicationId "com.weihuagu.receiptnotice" + minSdkVersion 19 + targetSdkVersion 25 + versionCode 1 + versionName "0.1" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + + +signingConfigs{ + release { + keyAlias keystoreProperties['keyAlias'] + keyPassword keystoreProperties['keyPassword'] + storeFile file(keystoreProperties['storeFile']) + storePassword keystoreProperties['storePassword'] + } +} + +buildTypes { + release { + signingConfig signingConfigs.release + } + } + lintOptions { + abortOnError false + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation 'com.android.support:appcompat-v7:26.1.0' + implementation 'com.android.support.constraint:constraint-layout:1.0.2' + implementation 'com.squareup.okhttp3:okhttp:3.11.0' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'com.android.support.test:runner:1.0.1' + androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/app/src/androidTest/java/com/xinri/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/xinri/ExampleInstrumentedTest.java new file mode 100644 index 0000000..6afe8f1 --- /dev/null +++ b/app/src/androidTest/java/com/xinri/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.xinri; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() throws Exception { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("com.xinri", appContext.getPackageName()); + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..b2071d3 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + diff --git a/app/src/main/java/com/weihuagu/receiptnotice/AsyncResponse.java b/app/src/main/java/com/weihuagu/receiptnotice/AsyncResponse.java new file mode 100644 index 0000000..538b2dc --- /dev/null +++ b/app/src/main/java/com/weihuagu/receiptnotice/AsyncResponse.java @@ -0,0 +1,8 @@ +package com.weihuagu.receiptnotice; + +import java.util.List; + +public interface AsyncResponse { + public void onDataReceivedSuccess(String returnstr); + public void onDataReceivedFailed(); +} diff --git a/app/src/main/java/com/weihuagu/receiptnotice/Constants.java b/app/src/main/java/com/weihuagu/receiptnotice/Constants.java new file mode 100644 index 0000000..e20a633 --- /dev/null +++ b/app/src/main/java/com/weihuagu/receiptnotice/Constants.java @@ -0,0 +1,98 @@ +/* + * Created By WeihuaGu (email:weihuagu_work@163.com) + * Copyright (c) 2017 + * All right reserved. + */ + +package com.weihuagu.receiptnotice; + +public class Constants { + /** + * Actions. + */ + public static final String ACTION_BROWSER_CONTEXT_MENU = "ACTION_BROWSER_OPEN"; + + /** + * Extras. + */ + public static final String EXTRA_ID = "EXTRA_ID"; + public static final String EXTRA_ACTION_ID = "EXTRA_ACTION_ID"; + public static final String EXTRA_NEW_TAB = "EXTRA_NEW_TAB"; + public static final String EXTRA_LABEL = "EXTRA_LABEL"; + public static final String EXTRA_URL = "EXTRA_URL"; + public static final String EXTRA_FOLDER_ID = "EXTRA_FOLDER_ID"; + public static final String EXTRA_HIT_TEST_RESULT = "EXTRA_HIT_TEST_RESULT"; + public static final String EXTRA_INCOGNITO = "EXTRA_INCOGNITO"; + + /** + * Specials urls. + */ + public static final String URL_ABOUT_BLANK = "about:blank"; + public static final String URL_ABOUT_START = "about:start"; + public static final String URL_ABOUT_TUTORIAL = "about:tutorial"; + + /** + * User agents + */ + public static final String USER_AGENT_ANDROID = ""; + public static final String USER_AGENT_DESKTOP = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.34 Safari/534.24"; + + /** + * Preferences. + */ + public static final String PREFERENCE_HOME_PAGE = "PREFERENCE_HOME_PAGE"; + public static final String PREFERENCE_SEARCH_URL = "PREFERENCE_SEARCH_URL"; + public static final String PREFERENCE_START_PAGE_LIMIT = "PREFERENCE_START_PAGE_LIMIT"; + public static final String PREFERENCE_BUBBLE_POSITION = "PREFERENCE_BUBBLE_POSITION"; + public static final String PREFERENCE_TOOLBARS_AUTOHIDE_DURATION = "PREFERENCE_TOOLBARS_AUTOHIDE_DURATION"; + public static final String PREFERENCES_SWITCH_TABS_METHOD = "PREFERENCES_SWITCH_TABS_METHOD"; + + public static final String PREFERENCE_ENABLE_JAVASCRIPT = "PREFERENCE_ENABLE_JAVASCRIPT"; + public static final String PREFERENCE_ENABLE_IMAGES = "PREFERENCE_ENABLE_IMAGES"; + public static final String PREFERENCE_USE_WIDE_VIEWPORT = "PREFERENCE_USE_WIDE_VIEWPORT"; + public static final String PREFERENCE_LOAD_WITH_OVERVIEW = "PREFERENCE_LOAD_WITH_OVERVIEW"; + public static final String PREFERENCE_USER_AGENT = "PREFERENCE_USER_AGENT"; + public static final String PREFERENCE_PLUGINS = "PREFERENCE_PLUGINS"; + + public static final String PREFERENCE_ACCEPT_COOKIES = "PREFERENCE_ACCEPT_COOKIES"; + public static final String PREFERENCE_ENABLE_GEOLOCATION = "PREFERENCE_ENABLE_GEOLOCATION"; + public static final String PREFERENCE_REMEMBER_FORM_DATA = "PREFERENCE_REMEMBER_FORM_DATA"; + public static final String PREFERENCE_REMEMBER_PASSWORDS = "PREFERENCE_REMEMBER_PASSWORDS"; + + public static final String PREFERENCE_HISTORY_SIZE = "PREFERENCE_HISTORY_SIZE"; + public static final String PREFERENCE_CLEAR_CACHE = "PREFERENCE_CLEAR_CACHE"; + public static final String PREFERENCE_WEBSITES_SETTINGS = "PREFERENCE_WEBSITES_SETTINGS"; + public static final String PREFERENCE_SSL_EXCEPTIONS = "PREFERENCE_SSL_EXCEPTIONS"; + public static final String PREFERENCE_CLEAR_HISTORY = "PREFERENCE_CLEAR_HISTORY"; + public static final String PREFERENCE_CLEAR_COOKIES = "PREFERENCE_CLEAR_COOKIES"; + public static final String PREFERENCE_CLEAR_GEOLOCATION = "PREFERENCE_CLEAR_GEOLOCATION"; + public static final String PREFERENCE_CLEAR_FORM_DATA = "PREFERENCE_CLEAR_FORM_DATA"; + public static final String PREFERENCE_CLEAR_PASSWORDS = "PREFERENCE_CLEAR_PASSWORDS"; + public static final String PREFERENCE_INCOGNITO_BY_DEFAULT = "PREFERENCE_INCOGNITO_BY_DEFAULT"; + + public static final String PREFERENCE_TEXT_SCALING = "PREFERENCE_TEXT_SCALING"; + public static final String PREFERENCE_MINIMUM_FONT_SIZE = "PREFERENCE_MINIMUM_FONT_SIZE"; + public static final String PREFERENCE_INVERTED_DISPLAY = "PREFERENCE_INVERTED_DISPLAY"; + public static final String PREFERENCE_INVERTED_DISPLAY_CONTRAST = "PREFERENCE_INVERTED_DISPLAY_CONTRAST"; + + public static final String PREFERENCE_BOOKMARKS_SORT_MODE = "PREFERENCE_BOOKMARKS_SORT_MODE"; + + public static final String PREFERENCE_FULL_SCREEN = "PREFERENCE_FULL_SCREEN"; + + public static final String PREFERENCE_RESTORE_TABS = "PREFERENCE_RESTORE_TABS"; + + public static final String PREFERENCE_UI_TYPE = "PREFERENCE_UI_TYPE"; + public static final String PREFERENCE_CLOSE_PANEL_ON_NEW_TAB = "PREFERENCE_CLOSE_PANEL_ON_NEW_TAB"; + + public static final String PREFERENCE_JS_LOG_ON_LOGCAT = "PREFERENCE_JS_LOG_ON_LOGCAT"; + + /** + * Technical preferences. + */ + public static final String TECHNICAL_PREFERENCE_LAST_HISTORY_TRUNCATION = "TECHNICAL_PREFERENCE_LAST_HISTORY_TRUNCATION"; + public static final String TECHNICAL_PREFERENCE_FIRST_RUN = "TECHNICAL_PREFERENCE_FIRST_RUN"; + public static final String TECHNICAL_PREFERENCE_LAST_RUN_VERSION_CODE = "TECHNICAL_PREFERENCE_LAST_RUN_VERSION_CODE"; + public static final String TECHNICAL_PREFERENCE_ADDON_ENABLED = "TECHNICAL_PREFERENCE_ADDON_ENABLED_"; + public static final String TECHNICAL_PREFERENCE_SAVED_TABS = "TECHNICAL_PREFERENCE_SAVED_TABS"; + public static final String TECHNICAL_PREFERENCE_HOMEPAGE_URL_UPDATE_NEEDED = "TECHNICAL_PREFERENCE_HOMEPAGE_URL_UPDATE_NEEDED"; +} diff --git a/app/src/main/java/com/weihuagu/receiptnotice/MainActivity.java b/app/src/main/java/com/weihuagu/receiptnotice/MainActivity.java new file mode 100644 index 0000000..4c736c4 --- /dev/null +++ b/app/src/main/java/com/weihuagu/receiptnotice/MainActivity.java @@ -0,0 +1,94 @@ +package com.weihuagu.receiptnotice; + +import android.support.v7.app.AppCompatActivity; +import android.app.Notification; +import android.app.NotificationManager; +import android.content.BroadcastReceiver; +import android.content.Context; + +import android.content.SharedPreferences; +import android.widget.Toast; +import android.content.Intent; +import android.content.IntentFilter; +import android.os.Bundle; +import android.support.v4.app.NotificationManagerCompat; +import android.support.v4.content.LocalBroadcastManager; +import android.view.View; +import android.widget.Button; +import android.widget.TextView; +import android.widget.EditText; + + +public class MainActivity extends AppCompatActivity implements View.OnClickListener{ + + private static final String TAG = "MainActivity"; + private Button btnsetposturl; + private EditText posturl; + private SharedPreferences sp ; + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + initView(); + } + + private void initView() { + + btnsetposturl=(Button) findViewById(R.id.btnsetposturl); + btnsetposturl.setOnClickListener(this); + posturl = (EditText) findViewById(R.id.posturl); + sp = getSharedPreferences("url", Context.MODE_PRIVATE); + + + } + + @Override + protected void onResume() { + super.onResume(); + boolean isAuthor=isNotificationServiceEnable(); + if (!isAuthor){ + //直接跳转通知授权界面 + //android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS是API 22才加入到Settings里,这里直接写死 + startActivity(new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS")); + } + } + + @Override + protected void onDestroy() { + super.onDestroy(); + } + + /** + * 是否已授权 + * + * @return + */ + private boolean isNotificationServiceEnable() { + return NotificationManagerCompat.getEnabledListenerPackages(this).contains(getPackageName()); + } + + @Override + public void onClick(View v) { + switch (v.getId()) { + case R.id.btnsetposturl: + setPostUrl(); + break; + } + } + + private void setPostUrl() { + SharedPreferences.Editor edit = sp.edit(); + //通过editor对象写入数据 + edit.putString("posturl",posturl.getText().toString()); + //提交数据存入到xml文件中 + edit.commit(); + Toast.makeText(getApplicationContext(), "已经设置posturl为:"+posturl.getText().toString(), + Toast.LENGTH_SHORT).show(); + } + + + + +} diff --git a/app/src/main/java/com/weihuagu/receiptnotice/NLService.java b/app/src/main/java/com/weihuagu/receiptnotice/NLService.java new file mode 100644 index 0000000..8949c3f --- /dev/null +++ b/app/src/main/java/com/weihuagu/receiptnotice/NLService.java @@ -0,0 +1,185 @@ +package com.weihuagu.receiptnotice; + +import android.content.Intent; +import android.service.notification.NotificationListenerService; +import android.app.Notification; +import android.service.notification.StatusBarNotification; +import android.support.v4.content.LocalBroadcastManager; +import android.text.TextUtils; +import android.util.Log; +import android.os.Bundle; +import android.content.SharedPreferences; + +import java.util.HashMap; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + + +public class NLService extends NotificationListenerService implements AsyncResponse { + public String TAG="NLService"; + public String posturl=null; + public String getPostUrl(){ + SharedPreferences sp=getSharedPreferences("url", 0); + this.posturl =sp.getString("posturl", ""); + if (posturl==null) + return null; + else + return posturl; + } + @Override + public void onNotificationPosted(StatusBarNotification sbn) { +// super.onNotificationPosted(sbn); + //这里只是获取了包名和通知提示信息,其他数据可根据需求取,注意空指针就行 + Log.d(TAG,"接受到通知消息"); + if(getPostUrl()==null) + return; + Notification notification = sbn.getNotification(); + String pkg = sbn.getPackageName(); + if (notification == null) { + return; + } + + long when=notification.when; + Date date=new Date(when); + SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm"); + String notitime=format.format(date); + + + Bundle extras = notification.extras; + if(extras==null) + return; + + String title=null; + String content=null; + // 获取通知标题 + title = extras.getString(Notification.EXTRA_TITLE, ""); + // 获取通知内容 + content = extras.getString(Notification.EXTRA_TEXT, ""); + + Log.d(TAG,"-----------------"); + + //mipush + if("com.xiaomi.xmsf".equals(pkg)){ + if(title.contains("支付宝")){ + //printNotify(notitime,title,content); + } + + } + + //支付宝 + if("com.eg.android.AlipayGphone".equals(pkg)){ + if(title.contains("支付宝")){ + if(content.contains("成功收款")){ + Map postmap=new HashMap(); + if(this.posturl!=null){ + postmap.put("time",notitime); + postmap.put("title","支付宝支付"); + postmap.put("money",extractMoney(content)); + postmap.put("content",content); + + doPost(posturl,postmap); + return ; + } + } + } + + //return; + + } + //应用管理GCM代收 + if("android".equals(pkg)){ + if(content.contains("微信支付")&&content.contains("收款")){ + Map postmap=new HashMap(); + if(this.posturl!=null){ + postmap.put("time",notitime); + postmap.put("title","微信支付"); + postmap.put("money",extractMoney(content)); + postmap.put("content",content); + doPost(posturl,postmap); + return ; + } + } + + } + //微信 + if("com.tencent.mm".equals(pkg)){ + if(title.contains("微信支付")&&content.contains("收款")){ + Map postmap=new HashMap(); + if(this.posturl!=null){ + postmap.put("time",notitime); + postmap.put("title",title); + postmap.put("money",extractMoney(content)); + postmap.put("content",content); + doPost(posturl,postmap); + return ; + } + } + + + + } + + Log.d(TAG,"这是检测之外的其它通知"); + Log.d(TAG,"包名是"+pkg); + printNotify(notitime,title,content); + + Log.d(TAG,"**********************"); + + + } + + private void sendBroadcast(String msg) { + Intent intent = new Intent(getPackageName()); + intent.putExtra("text", msg); + LocalBroadcastManager.getInstance(this).sendBroadcast(intent); + } + + private void printNotify(String notitime,String title,String content){ + Log.d(TAG,notitime); + Log.d(TAG,title); + Log.d(TAG,content); + } + + private void doPost(String url,Map params){ + Log.d(TAG,"开始准备进行post"); + PostTask mtask = new PostTask(); + mtask.setOnAsyncResponse(this); + params.put("url",url); + mtask.execute(params); + + } + + private String extractMoney(String content){ + Pattern pattern = Pattern.compile("收款(([1-9]{1}\\d*)|([0]{1}))(\\.(\\d){0,2})?元"); + Matcher matcher = pattern.matcher(content); + if(matcher.find()){ + String tmp=matcher.group(); + Pattern patternnum = Pattern.compile("(([1-9]{1}\\d*)|([0]{1}))(\\.(\\d){0,2})?"); + Matcher matchernum = patternnum.matcher(tmp); + if(matchernum.find()) + return matchernum.group(); + return null; + }else + return null; + + + } + + + @Override + public void onDataReceivedSuccess(String returnstr) { + Log.d(TAG,"Post Receive-returned post string"); + Log.d(TAG,returnstr); + + + } + @Override + public void onDataReceivedFailed() { + // TODO Auto-generated method stub + Log.d(TAG,"Post Receive-post error"); + + } +} diff --git a/app/src/main/java/com/weihuagu/receiptnotice/PostTask.java b/app/src/main/java/com/weihuagu/receiptnotice/PostTask.java new file mode 100644 index 0000000..a52c16d --- /dev/null +++ b/app/src/main/java/com/weihuagu/receiptnotice/PostTask.java @@ -0,0 +1,113 @@ +package com.weihuagu.receiptnotice; + +import java.util.List; + +import android.os.AsyncTask; +import java.util.Map; +import java.io.IOException; +import okhttp3.MediaType; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; +import java.util.Iterator; +import android.util.Log; + +public class PostTask extends AsyncTask, Void, String> { + + public AsyncResponse asyncResponse; + public static final MediaType JSON = MediaType.get("application/json; charset=utf-8"); +public String TAG="NLService"; + OkHttpClient client = new OkHttpClient(); + String httppost(String url, String json) throws IOException { + RequestBody body = RequestBody.create(JSON, json); + Request request = new Request.Builder() + .url(url) + .post(body) + .build(); + try (Response response = client.newCall(request).execute()) { + return response.body().string(); + } + } + + String httpspost(String url, String json) throws IOException { + RequestBody body = RequestBody.create(JSON, json); + Request request = new Request.Builder() + .url(url) + .post(body) + .build(); + try (Response response = client.newCall(request).execute()) { + return response.body().string(); + } + } + //fuck 竟然不导包找不到个好的map转json的 + public String map2Json(Map map){ + + + String mapjson=""; + Iterator> entries = map.entrySet().iterator(); + while (entries.hasNext()) { + + Map.Entry entry = entries.next(); + + mapjson=mapjson+'"'+entry.getKey()+'"' + ":"+'"'+entry.getValue()+'"'+","; + + +} + int strlength=(int)mapjson.length(); + mapjson=mapjson.substring(0,(strlength-1)); + mapjson="{"+mapjson+"}"; + return mapjson; + + + } + public void setOnAsyncResponse(AsyncResponse asyncResponse) + { + this.asyncResponse = asyncResponse; + } + + @Override + protected String doInBackground(Map ... key) { + Map postmap=key[0]; + if(postmap==null) + return null; + String url = postmap.get("url"); + + if(url==null) + return null; + + postmap.remove("url"); + String protocol=UrlUtil.httpOrHttps(url); + String postjson=map2Json(postmap); + if("http".equals(protocol)){ + try{ + Log.d(TAG,"post task url:"+url); + Log.d(TAG,"post task postjson:"+postjson); + return httppost(url,postjson); + }catch(IOException e){} + } + if("https".equals(protocol)){ + try{ + Log.d(TAG,"post task url:"+url); + Log.d(TAG,"post task postjson:"+postjson); + return httpspost(url,postjson); + }catch(IOException e){} + + } + return null; + } + + @Override + protected void onPostExecute(String returnstr) { + super.onPostExecute(returnstr); + if (returnstr != null) + { + asyncResponse.onDataReceivedSuccess(returnstr);//将结果传给回调接口中的函数 + } + else { + asyncResponse.onDataReceivedFailed(); + } + + } + +} diff --git a/app/src/main/java/com/weihuagu/receiptnotice/UrlUtil.java b/app/src/main/java/com/weihuagu/receiptnotice/UrlUtil.java new file mode 100644 index 0000000..11424d2 --- /dev/null +++ b/app/src/main/java/com/weihuagu/receiptnotice/UrlUtil.java @@ -0,0 +1,80 @@ +/* + * Created By WeihuaGu (email:weihuagu_work@163.com) + * Copyright (c) 2017 + * All right reserved. + */ + +package com.weihuagu.receiptnotice; + +public class UrlUtil { + public static String [] commonusedurls={"m.baidu.com","www.baidu.com","cn.bing.com","Jd.com","weibo.com","weibo.cn","sina.cn","www.tmall.com","www.taobao.com","tianya.cn","github.com","news.163.com","mail.163.com","image.baidu.com","wwww.zhihu.com","www.huanqiu.com","www.ifeng.com","www.jianshu.com","www.xueqiu.com"}; + public static String [] getCommonlyUsedUrls(){ + return commonusedurls; + } + + public static boolean isUrl(String url) { + return + url.contains(".") || + url.equals(Constants.URL_ABOUT_BLANK) || + url.equals(Constants.URL_ABOUT_START) || + url.equals(Constants.URL_ABOUT_TUTORIAL); + } + + + public static String getSearchUrl(String searchurl,String serchcontent) { + return searchurl.replaceAll("\\{searchTerms\\}", serchcontent); + } + + public static String httpOrHttps(String address){ + if(address.startsWith("http://")){ + return "http"; + } + if(address.startsWith("https://")) + return "https"; + + return null; + + } + public static String addressMatch(String address){ + + + if(address.startsWith("jian://")){ + return address; + } + + if(address.startsWith("alipay://")){ + return address; + } + + if(address.startsWith("wechat://")){ + return address; + } + + + if(address.startsWith("http://")){ + return address; + } + if(address.startsWith("https://")) + return address; + + if(!address.startsWith("http://")|!address.startsWith("https://")) { + address = "http://" + address; + } // 如果不以http://开头,识别不了,所以判断 + + + return address; + } + public static String addressMatchInHttps(String address){ + if(address.startsWith("https://")){ + return address; + + } + if(address.startsWith("http://")){ + return address.replaceAll("http","https"); + } + else{ + return "https://"+address; + } + + } +} diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..c7bd21d --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_launcher.png b/app/src/main/res/drawable/ic_launcher.png new file mode 100644 index 0000000000000000000000000000000000000000..6ae570b4db4da165fada0650079061cb56aa8793 GIT binary patch literal 3777 zcmV;y4nFaTP)<5O4m2Hnvj*wc>ks?G z2G34C@E_ZLZKgG#r9IGlue=QUde;x0&cEf}-^JJmm+rK2tvlk-Rei)^T;Dlp|J|h@ z^m+gPwY2+#Jp|DwyKZ{cr#D)vv<3?RYtkmp$A#M_scJjzTH4xNh5}{7UZcq4B{H*L zAbrC#D0V!CY|}%?3-2R&-YsP7u%Pze_gYZ0)AsviO2LRhr%`gXg-+>Ct8*6~gsguK z#ocE}dD{&cL$1D$Nahk|Gw0#KoMAkBPxj3Dsk7U=vbNLla&#_VG^p9{qm1aoZlq4X z^Cs&0V~Cl@NMI=QP@|Gq(}0&K#8vp=Jm%rVTTdK%=7x@k&di334&4O8uk5(sqd^Q_ zOZx$2J`a)j^giNo8q0Qj^e(~C7xVD# zBMhtX326_pU@IUwD0ag^9a#=8X??`t?%Wdb?IN60 zFU5H#fIN^s2jJ9e3jX;b?0@8i_S^2*cGVr<-K)a(^8r}3&jQ&SjUUMBc)a)44{XT~ zKlMpG`6^Vs@6j}zdy)c%>BZfb9XR-87LGiduL=0*b8mD$U4(;==VR}EFYLPIfh||3 zVcW$8=vDXN$A_m-+HT1LV5F7&O24xA)DN34P8+uS&iwD&Z+kG?ZaSg;#ynhn(2U*J z7o+`-JNDe0iH`fTu;=b9%D4zSZ+fEb+6-*E=!SLQIb-b!2XtJJqGfL^@-~|yYrPpH zDuess3cWG!rE%Avcd_4iaawO{mmOL!+JO`WtzC|EbjIc@u9RgrY^6+Z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*qrZemoxgSt^x&P}~w2oLp(ECMgBm2W%DCBg%Eu?1ZCOGtXt46rC#51~p{aY#0c z`aGt9nm3n+@Jucu(`^teae7Gt>w0my z;V&Ln!n%O8UVy%9OsOf&5Lax5m^@RWkO0AQV|HnW#zhVNjC5 z&QD@+Hdsah<~Spv&<&Cz7l@0TATD-5La7szST==8DxV7Zs{bJOfUMjT(h?8E<+;)F z!Txoy+^oY-%AX;UzQ^EytyJMjQ?gy>e-5`rU&AY8B9^Q)L6}^K6uFI2=56;OsRLQ@nJU84FF?X+ZtcpuQhaRJtXG zD#wv5j=}th(WK?Nm^^zVY^Qx)p{04H1a1Eam)SPchpC-reSv9~ID z7K0BUr^!7&reGoynL827)AeXt>rs#sFm=wD@_tQ^l)HO)28`%k7(JSHS2WS3T=>T6 zVPTl%AOoP_((0%B#uRYWQ3QY;PNAthc*p87(-(~w_s@@*G!OGdG2?n@Z;MccKEjmj zCWXg%N1Cl3@FMN^ww3wT!Rl3Nx>pqNmCoPihHyw&svtvB z==>~sl?Ri&TGShnW^;H!%-D(l5HGuff;fK;5F6Qtr8xR6OL27eUe15#ClL1K1%cH| ruJZJht7Zygm5zVW`osRPe+>Ii)X|D+8y7?e00000NkvXXu0mjf#L-I; literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..d5fccc5 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..ec74d64 --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,28 @@ + + + + + + + +