Skip to content

Commit

Permalink
handle merge
Browse files Browse the repository at this point in the history
  • Loading branch information
weihuagu committed May 11, 2019
2 parents a2f6897 + b98bee0 commit 4bfa3ba
Show file tree
Hide file tree
Showing 19 changed files with 264 additions and 133 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.weihuagu.receiptnotice;
import android.app.Notification;
import android.os.Bundle;
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.*;
import static org.mockito.Mockito.*;
import org.mockito.ArgumentMatchers;
import java.util.Map;
import java.util.HashMap;

@RunWith(AndroidJUnit4.class)
public class TestCashbarNotificationHandle{
CashbarNotificationHandle cashbar=null;
protected void setUp() throws Exception {
IDoPost dopost=new IDoPost(){
public void doPost(Map<String, String> params){
if(params!=null)
System.out.println(params.toString());
}
};
Notification mocknoti=mock(Notification.class);
Bundle mockextras=mock(Bundle.class);
when(mockextras.getString(Notification.EXTRA_TITLE, "")).thenReturn("收钱吧");
when(mockextras.getString(Notification.EXTRA_TEXT, "")).thenReturn("成功收款0.12元,来自支付宝");
when(mocknoti.extras).thenReturn(mockextras);
long whenval = 1346524199000l;
when(mocknoti.when).thenReturn(whenval);
cashbar=new CashbarNotificationHandle ("package name",mocknoti,dopost);

}

@Test
public void testGetCashbarType() throws Exception{
setUp();
cashbar.handleNotification();

}




}
26 changes: 0 additions & 26 deletions app/src/androidTest/java/com/xinri/ExampleInstrumentedTest.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public void handleNotification(){
if(title.contains("支付宝")){
if(content.contains("成功收款") | content.contains("向你付款")){
Map<String,String> postmap=new HashMap<String,String>();
postmap.put("type","alipay");
postmap.put("time",notitime);
postmap.put("title","支付宝支付");
postmap.put("money",extractMoney(content));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.weihuagu.receiptnotice;
import android.app.Notification;

import java.util.Map;
import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class CashbarNotificationHandle extends NotificationHandle{
public CashbarNotificationHandle(String pkgtype,Notification notification,IDoPost postpush){
super(pkgtype,notification,postpush);
}

public void handleNotification(){
if(title.contains("收钱吧")){
if(content.contains("成功收款") | content.contains("向你付款")){
Map<String,String> postmap=new HashMap<String,String>();
postmap.put("type",getCashbarType(content));
postmap.put("time",notitime);
postmap.put("title","支付宝支付");
postmap.put("money",extractMoney(content));
postmap.put("content",content);

postpush.doPost(postmap);
return ;
}
}



}


private String getCashbarType(String content){
Pattern pattern = Pattern.compile("(来自)(微信|支付宝|.*)");
Matcher matcher = pattern.matcher(content);
if(matcher.find()){
String tmp=matcher.group(2);

return "cashbar-"+transType(tmp);
}else
return "";

}

private String transType(String chinesetype){
if(chinesetype.equals("微信"))
return "wechat";
if(chinesetype.equals("支付宝"))
return "alipay";
else return chinesetype;
}











}
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,18 @@ public MipushNotificationHandle(String pkgtype,Notification notification,IDoPost
}

public void handleNotification(){
if(title.contains("支付宝")){
if(content.contains("成功收款")){
Map<String,String> postmap=new HashMap<String,String>();
postmap.put("type","alipay");
postmap.put("time",notitime);
postmap.put("title","支付宝支付");
postmap.put("money",extractMoney(content));
postmap.put("content",content);

postpush.doPost(postmap);
return ;
}

}


}
Expand Down
32 changes: 5 additions & 27 deletions app/src/main/java/com/weihuagu/receiptnotice/NLService.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,33 +50,11 @@ public void onNotificationPosted(StatusBarNotification sbn) {

Log.d(TAG,"-----------------");

//mipush
if("com.xiaomi.xmsf".equals(pkg)){
if(getNotiTitle(extras).contains("支付宝")){
//printNotify(getNotitime(notification),getNotiTitle(extras),getNotiContent(extras));
new MipushNotificationHandle("com.xiaomi.xmsf",notification,this).handleNotification();

}

}
//支付宝
if("com.eg.android.AlipayGphone".equals(pkg)){

new AlipayNotificationHandle("com.eg.android.AlipayGphone",notification,this).handleNotification();

}
//应用管理GCM代收
if("android".equals(pkg)){

new XposedmoduleNotificationHandle("github.tornaco.xposedmoduletest",notification,this).handleNotification();
}
//微信
if("com.tencent.mm".equals(pkg)){

new WechatNotificationHandle("com.tencent.mm",notification,this).handleNotification();

}

//接受推送处理
NotificationHandle notihandle =new NotificationHandleFactory().getNotificationHandle(pkg,notification,this);
if(notihandle!=null)
notihandle.handleNotification();

Log.d(TAG,"这是检测之外的其它通知");
Log.d(TAG,"包名是"+pkg);
printNotify(getNotitime(notification),getNotiTitle(extras),getNotiContent(extras));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.Random;
import java.util.concurrent.TimeUnit;
import java.lang.System;
import java.lang.Thread;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.URISyntaxException;
Expand Down Expand Up @@ -82,7 +83,15 @@ private boolean echoServerBySocketio(String echourl,String echojson){
mSocket.emit("echo",echojson);
mSocket.on(Socket.EVENT_DISCONNECT, new Emitter.Listener() {
@Override
public void call(Object... args) {echoServer();}
public void call(Object... args) {
LogUtil.infoLog("socket disconnected,try start echo in 5 secend");
try{
Thread.sleep(5000);
}catch(InterruptedException e){
e.printStackTrace();
}
echoServer();
}
});
return true;
}
Expand All @@ -98,7 +107,9 @@ private void startEchoTimer(){
this.echointerval=(!interval.equals("") ? interval:getDefaultEchoInterval());
this.echotimertask=returnEchoTimerTask();
this.timer=new Timer();
timer.schedule(echotimertask,5*1000,Integer.parseInt(this.echointerval)*1000);
int intervalmilliseconds = Integer.parseInt(this.echointerval)*1000;
LogUtil.infoLog("now socketio timer milliseconds:"+intervalmilliseconds);
timer.schedule(echotimertask,5*1000,intervalmilliseconds);
}
private TimerTask returnEchoTimerTask(){
return new TimerTask() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public NotificationHandle(String pkgtype,Notification notification,IDoPost postp
this.notification=notification;
this.postpush=postpush;

this.extras=notification.extras;;
this.extras=notification.extras;
// 获取通知标题
title = extras.getString(Notification.EXTRA_TITLE, "");
// 获取通知内容
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.weihuagu.receiptnotice;
import android.app.Notification;
public class NotificationHandleFactory{
public NotificationHandle getNotificationHandle(String pkg,Notification notification,IDoPost postpush){
//mipush
if("com.xiaomi.xmsf".equals(pkg)){
return new MipushNotificationHandle("com.xiaomi.xmsf",notification,postpush);
}
//支付宝
if("com.eg.android.AlipayGphone".equals(pkg)){
return new AlipayNotificationHandle("com.eg.android.AlipayGphone",notification,postpush);
}

//应用管理GCM代收
if("android".equals(pkg)){
return new XposedmoduleNotificationHandle("github.tornaco.xposedmoduletest",notification,postpush);
}
//微信
if("com.tencent.mm".equals(pkg)){
return new WechatNotificationHandle("com.tencent.mm",notification,postpush);
}
//收钱吧
if("com.wosai.cashbar".equals(pkg)){
return new CashbarNotificationHandle("com.wosai.cashbar",notification,postpush);
}
//云闪付
if("com.unionpay".equals(pkg)){
return new UnionpayNotificationHandle("com.unionpay",notification,postpush);
}

return null;

}

}


Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.weihuagu.receiptnotice;
import android.app.Notification;

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


public class UnionpayNotificationHandle extends NotificationHandle{
public UnionpayNotificationHandle(String pkgtype,Notification notification,IDoPost postpush){
super(pkgtype,notification,postpush);
}

public void handleNotification(){
if(title.contains("消息推送")&&content.contains("云闪付收款")){
Map<String,String> postmap=new HashMap<String,String>();
postmap.put("type","unionpay");
postmap.put("time",notitime);
postmap.put("title",title);
postmap.put("money",extractMoney(content));
postmap.put("content",content);
postpush.doPost(postmap);
return ;
}



}













}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public WechatNotificationHandle(String pkgtype,Notification notification,IDoPost
public void handleNotification(){
if((title.contains("微信支付")|title.contains("微信收款"))&&content.contains("收款")){
Map<String,String> postmap=new HashMap<String,String>();
postmap.put("type","wechat");
postmap.put("time",notitime);
postmap.put("title",title);
postmap.put("money",extractMoney(content));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public XposedmoduleNotificationHandle(String pkgtype,Notification notification,I
public void handleNotification(){
if(content.contains("微信支付")&&content.contains("收款")){
Map<String,String> postmap=new HashMap<String,String>();
postmap.put("type","wechat");
postmap.put("time",notitime);
postmap.put("title","微信支付");
postmap.put("money",extractMoney(content));
Expand Down
Loading

0 comments on commit 4bfa3ba

Please sign in to comment.