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();
......
......@@ -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