Commit e94744a9 by jeffrey

把拉取金额,跑金额,然后提交金额跑通了

parent aa7df233
......@@ -22,8 +22,8 @@ android {
applicationId "com.yuqirong.listenwechatnotification"
minSdkVersion 16
targetSdkVersion 26
versionCode 200002
versionName "2.0.02"
versionCode 200003
versionName "2.0.03"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
......
......@@ -5,23 +5,31 @@ import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.Environment;
import android.provider.Settings;
import android.support.v4.app.ActivityCompat;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.google.gson.Gson;
import com.yuqirong.listenwechatnotification.askhttp.ActivePullCashList;
import com.yuqirong.listenwechatnotification.askhttp.UpdateApk;
import com.yuqirong.listenwechatnotification.bean.BaseResult;
import com.yuqirong.listenwechatnotification.bean.ImageBean;
import com.yuqirong.listenwechatnotification.bean.OneBatchResult;
import com.yuqirong.listenwechatnotification.bean.WorkAction;
import com.yuqirong.listenwechatnotification.broadcastReceiver.MyCashReceiver;
import com.yuqirong.listenwechatnotification.http.HttpService;
import com.yuqirong.listenwechatnotification.http.PayHttp;
import com.yuqirong.listenwechatnotification.service.MyAccessibilityService;
import com.yuqirong.listenwechatnotification.service.WeChatNotificationListenerService;
import com.yuqirong.listenwechatnotification.uitl.Save2SharedPreferences;
import com.yuqirong.listenwechatnotification.uitl.Utils;
......@@ -32,6 +40,12 @@ import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;
public class MainActivity extends ParentActivity {
......@@ -113,7 +127,7 @@ public class MainActivity extends ParentActivity {
Intent intent = new Intent("CashPull");
sendBroadcast(intent);
// TODO: 2018/3/6 0006 正式测试数据的时候开放这个方法
//timingRequest();
// timingRequest();
}
});
......@@ -139,11 +153,11 @@ public class MainActivity extends ParentActivity {
findViewById(R.id.btn_test).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// String userName = Save2SharedPreferences.read(ALIPAYNAME,MainActivity.this);
// ActivePullCashList pullCashList = new ActivePullCashList();
// pullCashList.pullList(Utils.payChannelZFB,userName);
String userName = Save2SharedPreferences.read(ALIPAYNAME,MainActivity.this);
ActivePullCashList pullCashList = new ActivePullCashList();
pullCashList.pullListAndRun(Utils.payChannelZFB,userName);
WeChatNotificationListenerService.sendRequestWithOkHttp("hello","1111",Utils.payChannelZFB, HttpService.token);
// WeChatNotificationListenerService.sendRequestWithOkHttp("hello","1111",Utils.payChannelZFB, HttpService.token);
}
});
......@@ -152,9 +166,11 @@ public class MainActivity extends ParentActivity {
public void onClick(View v) {
// String userName = Save2SharedPreferences.read(ALIPAYNAME,MainActivity.this);
// ActivePullCashList pullCashList = new ActivePullCashList();
// pullCashList.pullList(Utils.payChannelZFB,userName);
// pullCashList.pullListAndRun(Utils.payChannelZFB,userName);
// EventBus.getDefault().post(new WorkAction(WorkAction.ACTION_TYPE_BILL));
MyAccessibilityService.testQRcodeResult();
EventBus.getDefault().post(new WorkAction(WorkAction.ACTION_TYPE_BILL));
}
});
checkWritePermission();
......
package com.yuqirong.listenwechatnotification.askhttp;
import android.util.Log;
import android.widget.Toast;
import com.google.gson.Gson;
import com.yuqirong.listenwechatnotification.MainActivity;
import com.yuqirong.listenwechatnotification.MyApplication;
import com.yuqirong.listenwechatnotification.bean.BaseResult;
import com.yuqirong.listenwechatnotification.bean.ImageBean;
import com.yuqirong.listenwechatnotification.bean.PullMoneyResp;
import com.yuqirong.listenwechatnotification.bean.WorkAction;
import com.yuqirong.listenwechatnotification.function.ParseImageFunc;
import com.yuqirong.listenwechatnotification.function.QRCodeFunction;
import com.yuqirong.listenwechatnotification.http.HttpService;
import com.yuqirong.listenwechatnotification.http.PayHttp;
import com.yuqirong.listenwechatnotification.service.MyAccessibilityService;
import com.yuqirong.listenwechatnotification.uitl.Save2SharedPreferences;
import com.yuqirong.listenwechatnotification.uitl.Utils;
import org.greenrobot.eventbus.EventBus;
import java.util.ArrayList;
import java.util.List;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
......@@ -36,19 +50,15 @@ public class ActivePullCashList {
public void testPullList(){
ArrayList<String> moneylist = new ArrayList<>();
// moneylist.add("11.01");
// moneylist.add("1.01");
// moneylist.add("111.01");
ArrayList<String> result = moneyWithFilter();
ArrayList<String> result = moneyWithFilter(generateMoneys());
for (String i : result ){
moneylist.add(String.valueOf(i));
}
EventBus.getDefault().post(moneylist);
}
public static ArrayList<String> moneyWithFilter(){
public static ArrayList<String> moneyWithFilter(Double[] result ){
ArrayList<String> strResult = new ArrayList<>();
double[] result = generateMoneys();
ArrayList<String> done = QRCodeFunction.listAllZfbFileNames();
for (int i = 0 ; i < result.length ;i++){
if(done.indexOf(String.valueOf(result[i])) == -1){
......@@ -58,7 +68,7 @@ public class ActivePullCashList {
return strResult;
}
public static double[] generateMoneys(){
public static Double[] generateMoneys(){
// int[] baseMoney = {10,20,50,100,200,300,400,500,600,700,800,900,1000,1500,2000,2500,3000};
// ArrayList<String> result = new ArrayList<>();
// for (int oneMoney : baseMoney){
......@@ -82,24 +92,56 @@ public class ActivePullCashList {
// }
// }
// double[] result = {9.95,9.96,9.97,9.98,9.99,10,10.01,10.02,10.03,10.04,10.05,19.95,19.96,19.97,19.98,19.99,20,20.01,20.02,20.03,20.04,20.05,49.95,49.96,49.97,49.98,49.99,50,50.01,50.02,50.03,50.04,50.05,99.9,99.91,99.92,99.93,99.94,99.95,99.96,99.97,99.98,99.99,100,100.01,100.02,100.03,100.04,100.05,100.06,100.07,100.08,100.09,100.1,199.9,199.91,199.92,199.93,199.94,199.95,199.96,199.97,199.98,199.99,200,200.01,200.02,200.03,200.04,200.05,200.06,200.07,200.08,200.09,200.1,299.9,299.91,299.92,299.93,299.94,299.95,299.96,299.97,299.98,299.99,300,300.01,300.02,300.03,300.04,300.05,300.06,300.07,300.08,300.09,300.1,399.9,399.91,399.92,399.93,399.94,399.95,399.96,399.97,399.98,399.99,400,400.01,400.02,400.03,400.04,400.05,400.06,400.07,400.08,400.09,400.1,499.9,499.91,499.92,499.93,499.94,499.95,499.96,499.97,499.98,499.99,500,500.01,500.02,500.03,500.04,500.05,500.06,500.07,500.08,500.09,500.1,599.9,599.91,599.92,599.93,599.94,599.95,599.96,599.97,599.98,599.99,600,600.01,600.02,600.03,600.04,600.05,600.06,600.07,600.08,600.09,600.1,699.9,699.91,699.92,699.93,699.94,699.95,699.96,699.97,699.98,699.99,700,700.01,700.02,700.03,700.04,700.05,700.06,700.07,700.08,700.09,700.1,799.9,799.91,799.92,799.93,799.94,799.95,799.96,799.97,799.98,799.99,800,800.01,800.02,800.03,800.04,800.05,800.06,800.07,800.08,800.09,800.1,899.9,899.91,899.92,899.93,899.94,899.95,899.96,899.97,899.98,899.99,900,900.01,900.02,900.03,900.04,900.05,900.06,900.07,900.08,900.09,900.1,999.9,999.91,999.92,999.93,999.94,999.95,999.96,999.97,999.98,999.99,1000,1000.01,1000.02,1000.03,1000.04,1000.05,1000.06,1000.07,1000.08,1000.09,1000.1,1499.9,1499.91,1499.92,1499.93,1499.94,1499.95,1499.96,1499.97,1499.98,1499.99,1500,1500.01,1500.02,1500.03,1500.04,1500.05,1500.06,1500.07,1500.08,1500.09,1500.1,1999.9,1999.91,1999.92,1999.93,1999.94,1999.95,1999.96,1999.97,1999.98,1999.99,2000,2000.01,2000.02,2000.03,2000.04,2000.05,2000.06,2000.07,2000.08,2000.09,2000.1,2499.9,2499.91,2499.92,2499.93,2499.94,2499.95,2499.96,2499.97,2499.98,2499.99,2500,2500.01,2500.02,2500.03,2500.04,2500.05,2500.06,2500.07,2500.08,2500.09,2500.1,2999.9,2999.91,2999.92,2999.93,2999.94,2999.95,2999.96,2999.97,2999.98,2999.99,3000,3000.01,3000.02,3000.03,3000.04,3000.05,3000.06,3000.07,3000.08,3000.09,3000.1};
double[] result = {9.95,9.96,9.97,9.98,9.99,10,10.01,10.02,10.03,10.04,10.05,19.95,19.96,19.97,19.98,19.99,20,20.01,20.02,20.03,20.04,20.05,49.95,49.96,49.97,49.98,49.99,50,50.01,50.02,50.03,50.04,50.05,99.9,99.91,99.92,99.93,99.94,99.95,99.96,99.97,99.98,99.99,100,100.01,100.02,100.03,100.04,100.05,100.06,100.07,100.08,100.09,100.1,199.9,199.91,199.92,199.93,199.94,199.95,199.96,199.97,199.98,199.99,200,200.01,200.02,200.03,200.04,200.05,200.06,200.07,200.08,200.09,200.1,299.9,299.91,299.92,299.93,299.94,299.95,299.96,299.97,299.98,299.99,300,300.01,300.02,300.03,300.04,300.05,300.06,300.07,300.08,300.09,300.1,399.9,399.91,399.92,399.93,399.94,399.95,399.96,399.97,399.98,399.99,400,400.01,400.02,400.03,400.04,400.05,400.06,400.07,400.08,400.09,400.1,499.9,499.91,499.92,499.93,499.94,499.95,499.96,499.97,499.98,499.99,500,500.01,500.02,500.03,500.04,500.05,500.06,500.07,500.08,500.09,500.1,599.9,599.91,599.92,599.93,599.94,599.95,599.96,599.97,599.98,599.99,600,600.01,600.02,600.03,600.04,600.05,600.06,600.07,600.08,600.09,600.1,699.9,699.91,699.92,699.93,699.94,699.95,699.96,699.97,699.98,699.99,700,700.01,700.02,700.03,700.04,700.05,700.06,700.07,700.08,700.09,700.1,799.9,799.91,799.92,799.93,799.94,799.95,799.96,799.97,799.98,799.99,800,800.01,800.02,800.03,800.04,800.05,800.06,800.07,800.08,800.09,800.1,899.9,899.91,899.92,899.93,899.94,899.95,899.96,899.97,899.98,899.99,900,900.01,900.02,900.03,900.04,900.05,900.06,900.07,900.08,900.09,900.1,999.9,999.91,999.92,999.93,999.94,999.95,999.96,999.97,999.98,999.99,1000,1000.01,1000.02,1000.03,1000.04,1000.05,1000.06,1000.07,1000.08,1000.09,1000.1,1199.9,1199.91,1199.92,1199.93,1199.94,1199.95,1199.96,1199.97,1199.98,1199.99,1200,1200.01,1200.02,1200.03,1200.04,1200.05,1200.06,1200.07,1200.08,1200.09,1200.1,1499.9,1499.91,1499.92,1499.93,1499.94,1499.95,1499.96,1499.97,1499.98,1499.99,1500,1500.01,1500.02,1500.03,1500.04,1500.05,1500.06,1500.07,1500.08,1500.09,1500.1,1599.9,1599.91,1599.92,1599.93,1599.94,1599.95,1599.96,1599.97,1599.98,1599.99,1600,1600.01,1600.02,1600.03,1600.04,1600.05,1600.06,1600.07,1600.08,1600.09,1600.1,1799.9,1799.91,1799.92,1799.93,1799.94,1799.95,1799.96,1799.97,1799.98,1799.99,1800,1800.01,1800.02,1800.03,1800.04,1800.05,1800.06,1800.07,1800.08,1800.09,1800.1,1999.9,1999.91,1999.92,1999.93,1999.94,1999.95,1999.96,1999.97,1999.98,1999.99,2000,2000.01,2000.02,2000.03,2000.04,2000.05,2000.06,2000.07,2000.08,2000.09,2000.1,2999.9,2999.91,2999.92,2999.93,2999.94,2999.95,2999.96,2999.97,2999.98,2999.99,3000,3000.01,3000.02,3000.03,3000.04,3000.05,3000.06,3000.07,3000.08,3000.09,3000.1};
// Double[] result = {9.95,9.96,9.97,9.98,9.99,10.0,10.01,10.02,10.03,10.04,10.05,19.95,19.96,19.97,19.98,19.99,20.0,20.01,20.02,20.03,20.04,20.05,49.95,49.96,49.97,49.98,49.99,50.0,50.01,50.02,50.03,50.04,50.05,99.9,99.91,99.92,99.93,99.94,99.95,99.96,99.97,99.98,99.99,100,100.01,100.02,100.03,100.04,100.05,100.06,100.07,100.08,100.09,100.1,199.9,199.91,199.92,199.93,199.94,199.95,199.96,199.97,199.98,199.99,200,200.01,200.02,200.03,200.04,200.05,200.06,200.07,200.08,200.09,200.1,299.9,299.91,299.92,299.93,299.94,299.95,299.96,299.97,299.98,299.99,300,300.01,300.02,300.03,300.04,300.05,300.06,300.07,300.08,300.09,300.1,399.9,399.91,399.92,399.93,399.94,399.95,399.96,399.97,399.98,399.99,400,400.01,400.02,400.03,400.04,400.05,400.06,400.07,400.08,400.09,400.1,499.9,499.91,499.92,499.93,499.94,499.95,499.96,499.97,499.98,499.99,500,500.01,500.02,500.03,500.04,500.05,500.06,500.07,500.08,500.09,500.1,599.9,599.91,599.92,599.93,599.94,599.95,599.96,599.97,599.98,599.99,600,600.01,600.02,600.03,600.04,600.05,600.06,600.07,600.08,600.09,600.1,699.9,699.91,699.92,699.93,699.94,699.95,699.96,699.97,699.98,699.99,700,700.01,700.02,700.03,700.04,700.05,700.06,700.07,700.08,700.09,700.1,799.9,799.91,799.92,799.93,799.94,799.95,799.96,799.97,799.98,799.99,800,800.01,800.02,800.03,800.04,800.05,800.06,800.07,800.08,800.09,800.1,899.9,899.91,899.92,899.93,899.94,899.95,899.96,899.97,899.98,899.99,900,900.01,900.02,900.03,900.04,900.05,900.06,900.07,900.08,900.09,900.1,999.9,999.91,999.92,999.93,999.94,999.95,999.96,999.97,999.98,999.99,1000,1000.01,1000.02,1000.03,1000.04,1000.05,1000.06,1000.07,1000.08,1000.09,1000.1,1199.9,1199.91,1199.92,1199.93,1199.94,1199.95,1199.96,1199.97,1199.98,1199.99,1200,1200.01,1200.02,1200.03,1200.04,1200.05,1200.06,1200.07,1200.08,1200.09,1200.1,1499.9,1499.91,1499.92,1499.93,1499.94,1499.95,1499.96,1499.97,1499.98,1499.99,1500,1500.01,1500.02,1500.03,1500.04,1500.05,1500.06,1500.07,1500.08,1500.09,1500.1,1599.9,1599.91,1599.92,1599.93,1599.94,1599.95,1599.96,1599.97,1599.98,1599.99,1600,1600.01,1600.02,1600.03,1600.04,1600.05,1600.06,1600.07,1600.08,1600.09,1600.1,1799.9,1799.91,1799.92,1799.93,1799.94,1799.95,1799.96,1799.97,1799.98,1799.99,1800,1800.01,1800.02,1800.03,1800.04,1800.05,1800.06,1800.07,1800.08,1800.09,1800.1,1999.9,1999.91,1999.92,1999.93,1999.94,1999.95,1999.96,1999.97,1999.98,1999.99,2000,2000.01,2000.02,2000.03,2000.04,2000.05,2000.06,2000.07,2000.08,2000.09,2000.1,2999.9,2999.91,2999.92,2999.93,2999.94,2999.95,2999.96,2999.97,2999.98,2999.99,3000,3000.01,3000.02,3000.03,3000.04,3000.05,3000.06,3000.07,3000.08,3000.09,3000.1};
Double[] result = {9.95};
return result;
}
public void pullList(String channel,String username){
public void pullListAndRun(String channel, String username){
HttpService httpService = PayHttp.get();
Call<PullMoneyResp> call = httpService.pullZFBCashList(channel,username,HttpService.token);
call.enqueue(new Callback<PullMoneyResp>() {
@Override
public void onResponse(Call<PullMoneyResp> call, Response<PullMoneyResp> response) {
PullMoneyResp object = response.body();
Log.d("fei",new Gson().toJson(object));
//1.当根据类型请求的金额列表数字为空的时候,不需要用eventbus来发送数据
//2.只需要替换一下请求类型就可以了
//3.删除文件夹下所有内容
String token = Save2SharedPreferences.read(MainActivity.TOKEN, MyApplication.get());
httpService.pullZFBCashList(channel,username,token)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<BaseResult<ArrayList<Double>>>() {
@Override
public void accept(BaseResult<ArrayList<Double>> dataBean) throws Exception {
Log.d("fei",new Gson().toJson(dataBean));
if (dataBean.getStatus_code() == 200 && dataBean.getData() != null && dataBean.getData().size() >0){
ArrayList<String> result = moneyWithFilter(dataBean.getData().toArray(new Double[dataBean.getData().size()]));
//本地都有了,直接解析上传
if (result.size() == 0){
ParseImageFunc parseImageFunc = new ParseImageFunc();
parseImageFunc.start(Utils.ZFBImgPath, new ParseImageFunc.ParseListener() {
@Override
public void onStartWork() {
Toast.makeText(MyApplication.get(),"图片保存完毕,准备解析",Toast.LENGTH_LONG).show();
}
@Override
public void onWorkDone(List<ImageBean> list) {
String username = Save2SharedPreferences.read(MainActivity.ALIPAYNAME,MyApplication.get());
MyAccessibilityService.postQRcodeResult(username,Utils.payChannelZFB);
}
});
return ;
}
WorkAction workAction = new WorkAction(WorkAction.ACTION_TYPE_MONEY);
workAction.setTargetAppType(Utils.payTypeZFB);
workAction.setMoneys(result);
EventBus.getDefault().post(workAction);
Toast.makeText(MyApplication.get(),"拉取成功 准备运行",Toast.LENGTH_LONG).show();
}else {
Toast.makeText(MyApplication.get(),"拉取失败" + dataBean.getMessage(),Toast.LENGTH_LONG).show();
}
//1.当根据类型请求的金额列表数字为空的时候,不需要用eventbus来发送数据
//2.只需要替换一下请求类型就可以了
//3.删除文件夹下所有内容
// if (object.size() == 0){
// if (PayTypeSingleTon.newInstance().getPayType().equals(Utils.payTypeZFB)){
// PayTypeSingleTon.newInstance().setPayType(Utils.payTypeWeiXin);
......@@ -109,13 +151,16 @@ public class ActivePullCashList {
// }else{
// EventBus.getDefault().post(object);
// }
}
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
Toast.makeText(MyApplication.get(),"拉取失败" + throwable.getMessage(),Toast.LENGTH_LONG).show();
}
});
@Override
public void onFailure(Call<PullMoneyResp> call, Throwable t) {
}
});
}
}
......@@ -28,41 +28,41 @@ public class ActivePushCashList {
public ActivePushCashList() {
}
public void pushCashList(ArrayList<ImageBean> list){
Retrofit retrofit = new Retrofit.Builder().baseUrl(HttpService.base_url)
//添加返回字符串的支持--不知道返回的是什么,添加字符串支持
.addConverterFactory(ScalarsConverterFactory.create())
//添加GSON转换支持
.addConverterFactory(GsonConverterFactory.create())
.build();
//获取接口
HttpService service = retrofit.create(HttpService.class);
Call<String> call =service.pushZFBCashList(PayTypeSingleTon.newInstance().getPayType(),list);
call.enqueue(new Callback<String>() {
@Override
public void onResponse(Call<String> call, Response<String> response) {
//数据发送成功的话,这边修改下次请求参数类型
//还需要删除当前类型文件夹下所有图片
if (PayTypeSingleTon.newInstance().getPayType().equals(Utils.payTypeZFB)){
PayTypeSingleTon.newInstance().setPayType(Utils.payTypeWeiXin);
FileUtils.deleteFiles(Utils.ZFBImgPath);
}else{
PayTypeSingleTon.newInstance().setPayType(Utils.payTypeZFB);
FileUtils.deleteFiles(Utils.WeiXinImgPath);
}
}
@Override
public void onFailure(Call<String> call, Throwable t) {
}
});
}
// public void pushCashList(ArrayList<ImageBean> list){
// Retrofit retrofit = new Retrofit.Builder().baseUrl(HttpService.base_url)
// //添加返回字符串的支持--不知道返回的是什么,添加字符串支持
// .addConverterFactory(ScalarsConverterFactory.create())
// //添加GSON转换支持
// .addConverterFactory(GsonConverterFactory.create())
// .build();
//
// //获取接口
// HttpService service = retrofit.create(HttpService.class);
//
// Call<String> call =service.pushZFBCashList(PayTypeSingleTon.newInstance().getPayType(),list);
//
// call.enqueue(new Callback<String>() {
// @Override
// public void onResponse(Call<String> call, Response<String> response) {
//
// //数据发送成功的话,这边修改下次请求参数类型
// //还需要删除当前类型文件夹下所有图片
// if (PayTypeSingleTon.newInstance().getPayType().equals(Utils.payTypeZFB)){
// PayTypeSingleTon.newInstance().setPayType(Utils.payTypeWeiXin);
// FileUtils.deleteFiles(Utils.ZFBImgPath);
// }else{
// PayTypeSingleTon.newInstance().setPayType(Utils.payTypeZFB);
// FileUtils.deleteFiles(Utils.WeiXinImgPath);
// }
// }
//
// @Override
// public void onFailure(Call<String> call, Throwable t) {
//
// }
// });
//
// }
}
package com.yuqirong.listenwechatnotification.bean;
import com.google.gson.annotations.SerializedName;
/**
* Created by yanqi on 2018/2/27 0027.
*/
public class ImageBean {
String url;
String code;
String description;
String amount;
public String getUrl() {
return url;
public String getCode() {
return code;
}
public void setUrl(String url) {
this.url = url;
public String getAmount() {
return amount;
}
public String getDescription() {
return description;
public void setCode(String code) {
this.code = code;
}
public void setDescription(String description) {
this.description = description;
public void setAmount(String amount) {
this.amount = amount;
}
}
package com.yuqirong.listenwechatnotification.bean;
import com.yuqirong.listenwechatnotification.uitl.Utils;
import java.util.ArrayList;
/**
* 创建日期:2018/3/19 on 14:50
* 描述:
......@@ -8,11 +12,39 @@ package com.yuqirong.listenwechatnotification.bean;
public class WorkAction {
public static final int ACTION_TYPE_NONE = 0;
/**
* 生成二维码
*/
public static final int ACTION_TYPE_MONEY = 1;
/**
* 识别账单
*/
public static final int ACTION_TYPE_BILL = 2;
/**
* 动作类型
*/
private int type = ACTION_TYPE_NONE;
/**
* 如果是生成二维码的话 需要这个
*/
private ArrayList<String> moneys;
/**
* 目标app就下面这两种类型
* @see com.yuqirong.listenwechatnotification.uitl.Utils#payTypeWeiXin
* @see com.yuqirong.listenwechatnotification.uitl.Utils#payTypeZFB
*/
private String targetAppType = Utils.payTypeZFB ;
public ArrayList<String> getMoneys() {
return moneys;
}
public void setMoneys(ArrayList<String> moneys) {
this.moneys = moneys;
}
public WorkAction(int type) {
this.type = type;
......@@ -25,4 +57,12 @@ public class WorkAction {
public void setType(int type) {
this.type = type;
}
public String getTargetAppType() {
return targetAppType;
}
public void setTargetAppType(String targetAppType) {
this.targetAppType = targetAppType;
}
}
......@@ -9,6 +9,9 @@ import com.yuqirong.listenwechatnotification.askhttp.ActivePullCashList;
import com.yuqirong.listenwechatnotification.uitl.PayTypeSingleTon;
import com.yuqirong.listenwechatnotification.uitl.Utils;
import static com.yuqirong.listenwechatnotification.askhttp.ActivePullCashList.generateMoneys;
import static com.yuqirong.listenwechatnotification.askhttp.ActivePullCashList.moneyWithFilter;
/**
* Created by yanqi on 2018/3/2 0002.
*/
......
......@@ -27,6 +27,7 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
......@@ -39,15 +40,16 @@ import static android.graphics.BitmapFactory.decodeFile;
*/
public class ParseImageFunc {
private final int MAX_COUNT = 3;
private final String TAG = ParseImageFunc.class.getSimpleName();
private List<ImageBean> imageBeanList = new ArrayList<>() ;
private ConcurrentLinkedQueue<File> queue = new ConcurrentLinkedQueue<File>();
private CountDownLatch countDownLatch = new CountDownLatch(MAX_COUNT);
public void start(String filePath){
public void start(String filePath, final ParseListener parseListener){
parseListener.onStartWork();
final List<File> imageFiles = foundImageFile(filePath);
if (imageFiles == null || imageFiles.size() == 0){
return;
......@@ -56,8 +58,8 @@ public class ParseImageFunc {
queue.add(file);
}
ExecutorService service = Executors.newFixedThreadPool(3);
for (int i = 0 ; i < 3 ;i ++){
ExecutorService service = Executors.newFixedThreadPool(MAX_COUNT);
for (int i = 0 ; i < MAX_COUNT ;i ++){
service.submit(new Runnable() {
@Override
public void run() {
......@@ -69,30 +71,47 @@ public class ParseImageFunc {
imageBeanList.add(result);
}
}
countDownLatch.countDown();
}
});
}
Collections.sort(imageBeanList,new Comparator<ImageBean>() {
@Override
public int compare(ImageBean o1, ImageBean o2) {
try {
float left = Float.valueOf(o1.getDescription().replace(".jpg",""));
float right = Float.valueOf(o2.getDescription().replace(".jpg",""));
return left < right ? -1 : 1;
}catch (Exception e){
Log.d("fei","parse err " + e.getMessage());
return 0;
}
new Thread(new Runnable() {
@Override
public void run() {
try {
Log.d(TAG,"等待执行任务");
countDownLatch.await();
} catch (InterruptedException e) {
Log.d(TAG,"执行任务异常" + e.getMessage());
e.printStackTrace();
}
Log.d(TAG,"执行任务完成");
Collections.sort(imageBeanList,new Comparator<ImageBean>() {
@Override
public int compare(ImageBean o1, ImageBean o2) {
try {
float left = Float.valueOf(o1.getCode().replace(".jpg",""));
float right = Float.valueOf(o2.getCode().replace(".jpg",""));
return left < right ? -1 : 1;
}catch (Exception e){
Log.d("fei","parse err " + e.getMessage());
return 0;
}
});
OneBatchResult result = new OneBatchResult(new ArrayList<ImageBean>(imageBeanList));
String stringResult = new Gson().toJson(result);
SharedPreferences sp = MyApplication.get().getSharedPreferences("result", Context.MODE_PRIVATE);
sp.edit().putString("result",stringResult).apply();
Log.d("fei","parse done " + stringResult);
}
});
}
}
});
OneBatchResult result = new OneBatchResult(new ArrayList<ImageBean>(imageBeanList));
String stringResult = new Gson().toJson(result);
SharedPreferences sp = MyApplication.get().getSharedPreferences("result", Context.MODE_PRIVATE);
sp.edit().putString("result",stringResult).apply();
Log.d(TAG,"parse done " + stringResult);
parseListener.onWorkDone(imageBeanList);
}
}).start();
}
/**
......@@ -139,9 +158,9 @@ public class ParseImageFunc {
try {
re = reader.decode(bitmap1);
ImageBean bean = new ImageBean();
bean.setUrl(re.getText());
bean.setDescription(file.getName());
Log.d(TAG, "parseCode: "+bean.getUrl());
bean.setCode(re.getText());
bean.setAmount(file.getName().replace(".jpg",""));
Log.d(TAG, "parseCode: "+bean.getCode());
return bean;
......@@ -160,4 +179,10 @@ public class ParseImageFunc {
return null;
}
public interface ParseListener{
void onStartWork();
void onWorkDone(List<ImageBean> list);
}
}
......@@ -182,9 +182,9 @@ public class QRCodeFunction extends Thread{
try {
re = reader.decode(bitmap1);
ImageBean bean = new ImageBean();
bean.setUrl(re.getText());
bean.setDescription(file.getName());
Log.d(TAG, "parseCode: "+bean.getUrl());
bean.setCode(re.getText());
bean.setAmount(file.getName());
Log.d(TAG, "parseCode: "+bean.getCode());
return bean;
......
......@@ -7,10 +7,12 @@ import com.yuqirong.listenwechatnotification.bean.UpdateBean;
import com.yuqirong.listenwechatnotification.bean.UpgradeResult;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import io.reactivex.Observable;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
......@@ -54,9 +56,12 @@ public interface HttpService {
@Headers({
"Accept: application/json"
})
Call<PullMoneyResp> pullZFBCashList(@Field("channel") String channel, @Field("username") String username, @Field("token") String token);
Observable<BaseResult<ArrayList<Double>>> pullZFBCashList(@Field("gateway") String channel, @Field("username") String username, @Field("token") String token);
@POST("/app-api/amounts/submit")
Call<String> pushZFBCashList(@Field("channel") String channel,@Field("list") ArrayList<ImageBean> imageBeans);
@Headers({
"Accept: application/json"
})
Observable<BaseResult> pushZFBCashList(@Body HashMap<String,Object> params);
}
......@@ -3,21 +3,33 @@ package com.yuqirong.listenwechatnotification.service;
import android.accessibilityservice.AccessibilityService;
import android.accessibilityservice.AccessibilityServiceInfo;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.text.TextUtils;
import android.util.Log;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.Toast;
import com.google.gson.Gson;
import com.yuqirong.listenwechatnotification.MainActivity;
import com.yuqirong.listenwechatnotification.MyApplication;
import com.yuqirong.listenwechatnotification.bean.BaseResult;
import com.yuqirong.listenwechatnotification.bean.ImageBean;
import com.yuqirong.listenwechatnotification.bean.OneBatchResult;
import com.yuqirong.listenwechatnotification.bean.WorkAction;
import com.yuqirong.listenwechatnotification.function.AlipayBill;
import com.yuqirong.listenwechatnotification.function.AlipayFunction;
import com.yuqirong.listenwechatnotification.function.AlipaySimulation;
import com.yuqirong.listenwechatnotification.function.JobAwaken;
import com.yuqirong.listenwechatnotification.function.ParseImageFunc;
import com.yuqirong.listenwechatnotification.function.QRCodeFunction;
import com.yuqirong.listenwechatnotification.function.WeChatFunction;
import com.yuqirong.listenwechatnotification.function.WeChatSimulation;
import com.yuqirong.listenwechatnotification.http.PayHttp;
import com.yuqirong.listenwechatnotification.uitl.PayTypeSingleTon;
import com.yuqirong.listenwechatnotification.uitl.Save2SharedPreferences;
import com.yuqirong.listenwechatnotification.uitl.Utils;
import org.greenrobot.eventbus.EventBus;
......@@ -25,8 +37,14 @@ import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;
import static com.yuqirong.listenwechatnotification.bean.WorkAction.ACTION_TYPE_NONE;
/**
......@@ -52,6 +70,7 @@ public class MyAccessibilityService extends AccessibilityService {
private ArrayList<String> moneylist = new ArrayList<>();
private int ACTION_TYPE = ACTION_TYPE_NONE;
private String TARGET_APP_TYPE = Utils.payTypeZFB;
// @Override
// public void onCreate() {
// android.os.Debug.waitForDebugger();
......@@ -119,13 +138,54 @@ public class MyAccessibilityService extends AccessibilityService {
if (moneylist.size() == indexCount){
Log.d(TAG, "这次任务已经完成!");
if (PayTypeSingleTon.newInstance().getPayType().equals(Utils.payTypeZFB)){
QRCodeFunction qrThread = new QRCodeFunction("QRCodeFunction---ZFB", Utils.ZFBImgPath);
qrThread.start();
if (this.TARGET_APP_TYPE.equals(Utils.payTypeZFB)){
ParseImageFunc parseImageFunc = new ParseImageFunc();
parseImageFunc.start(Utils.ZFBImgPath, new ParseImageFunc.ParseListener() {
@Override
public void onStartWork() {
Observable.just("图片保存完毕,准备解析")
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<String>() {
@Override
public void accept(String s) throws Exception {
Toast.makeText(MyApplication.get(),s,Toast.LENGTH_LONG).show();
}
});
}
@Override
public void onWorkDone(List<ImageBean> list) {
String username = Save2SharedPreferences.read(MainActivity.ALIPAYNAME,MyApplication.get());
postQRcodeResult(username,Utils.payChannelZFB);
}
});
// QRCodeFunction qrThread = new QRCodeFunction("QRCodeFunction---ZFB", Utils.ZFBImgPath);
// qrThread.start();
}else{
QRCodeFunction qrThread = new QRCodeFunction("QRCodeFunction---WEIXIN", Utils.WeiXinImgPath);
qrThread.start();
ParseImageFunc parseImageFunc = new ParseImageFunc();
parseImageFunc.start(Utils.WeiXinImgPath, new ParseImageFunc.ParseListener() {
@Override
public void onStartWork() {
Observable.just("图片保存完毕,准备解析")
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<String>() {
@Override
public void accept(String s) throws Exception {
Toast.makeText(MyApplication.get(),s,Toast.LENGTH_LONG).show();
}
});
}
@Override
public void onWorkDone(List<ImageBean> list) {
String username = Save2SharedPreferences.read(MainActivity.WECHATPAYNAME,MyApplication.get());
postQRcodeResult(username,Utils.payChannelWX);
}
});
}
moneylist.clear();
......@@ -150,6 +210,10 @@ public class MyAccessibilityService extends AccessibilityService {
}
}
/**
* 二维码识别入口
* @param moneylist
*/
@Subscribe(threadMode = ThreadMode.ASYNC)
public void Event(ArrayList<String> moneylist){
for (String s:moneylist
......@@ -189,22 +253,25 @@ public class MyAccessibilityService extends AccessibilityService {
}
}
/**
* 这个是用来拉取账单的 跑二维码识别还是上面的
* @param action
*/
@Subscribe(threadMode = ThreadMode.ASYNC)
public void OnBillEvent(WorkAction action){
this.ACTION_TYPE = action.getType();
this.TARGET_APP_TYPE = action.getTargetAppType();
if (action.getType() == WorkAction.ACTION_TYPE_BILL){
alipayBill = new AlipayBill();
this.ACTION_TYPE = action.getType();
JobAwaken awaken = new JobAwaken();
awaken.awakenAPliay(getApplicationContext());
}else {
for (String s:moneylist
) {
}else if (action.getType() == WorkAction.ACTION_TYPE_MONEY){
this.moneylist = action.getMoneys();
for (String s:moneylist) {
Log.d(TAG, "Event: "+s);
}
this.moneylist = moneylist;
if (PayTypeSingleTon.newInstance().getPayType().equals(Utils.payTypeZFB)) {
if (action.getTargetAppType().equals(Utils.payTypeZFB)) {
alipaySimulation = new AlipaySimulation(moneylist, getApplicationContext()) {
@Override
public void jump2Menu(AlipayFunction function) {
......@@ -290,6 +357,40 @@ public class MyAccessibilityService extends AccessibilityService {
}
}
public static void testQRcodeResult(){
String username = Save2SharedPreferences.read(MainActivity.ALIPAYNAME,MyApplication.get());
postQRcodeResult(username,Utils.payChannelZFB);
}
public static void postQRcodeResult(String userName,String channel){
SharedPreferences sp = MyApplication.get().getSharedPreferences("result", Context.MODE_PRIVATE);
String parseResult = sp.getString("result","");
if (TextUtils.isEmpty(parseResult)){
return;
}
ArrayList<ImageBean> imageBeans = new Gson().fromJson(parseResult, OneBatchResult.class).getList();
String token = Save2SharedPreferences.read(MainActivity.TOKEN, MyApplication.get());
HashMap<String,Object> params = new HashMap<>();
params.put("gateway",channel);
params.put("token",token);
params.put("data",imageBeans);
params.put("username",userName);
PayHttp.get().pushZFBCashList(params)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<BaseResult>() {
@Override
public void accept(BaseResult baseResult) throws Exception {
Toast.makeText(MyApplication.get(), "上报结果"+baseResult.getMessage(), Toast.LENGTH_SHORT).show();
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
Toast.makeText(MyApplication.get(), throwable.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
public static boolean findNodeByText(String text,AccessibilityService service){
......
......@@ -133,6 +133,7 @@
<Button
android:id="@+id/bt_jianting"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="监听" />
......@@ -145,10 +146,11 @@
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="50dp"
android:text="测试" />
android:text="生成上报二维码" />
<Button
android:id="@+id/btn_test_bill"
android:layout_weight="1"
android:visibility="gone"
android:layout_width="0dp"
android:layout_height="50dp"
android:text="测试账单" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment