Commit 4d7bd544 by jeffrey

把主干代码合并过来了

parent 97f6615d
......@@ -22,8 +22,8 @@ android {
applicationId "com.yuqirong.listenwechatnotification"
minSdkVersion 16
targetSdkVersion 26
versionCode 12
versionName "1.21"
versionCode 200000
versionName "2.0.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
......@@ -52,7 +52,7 @@ dependencies {
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
//添加返回的字符串支付
compile 'com.squareup.retrofit2:converter-scalars:2.1.0'
compile 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'
compile 'com.google.zxing:core:3.2.1'
compile 'org.greenrobot:eventbus:3.0.0'
......
......@@ -17,10 +17,11 @@ import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.yuqirong.listenwechatnotification.askhttp.ActivePullCashList;
import com.yuqirong.listenwechatnotification.askhttp.UpdateApk;
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.WeChatNotificationListenerService;
import com.yuqirong.listenwechatnotification.uitl.Save2SharedPreferences;
import com.yuqirong.listenwechatnotification.uitl.Utils;
......@@ -48,6 +49,7 @@ public class MainActivity extends ParentActivity {
public static String ALIPAYNAME = "key1";
public static String WECHATPAYNAME = "key3";
public static String API = "key2";
public static String TOKEN = "token";
String TAG = "MainActivity";
......@@ -67,6 +69,7 @@ public class MainActivity extends ParentActivity {
final EditText etText1 = (EditText) findViewById(R.id.et_text1);
final EditText etText2 = (EditText) findViewById(R.id.et_text2);
final EditText etText3 = (EditText) findViewById(R.id.et_text3);
final EditText etToken = (EditText) findViewById(R.id.et_token);
versionCode = (TextView)findViewById(R.id.tv_version_name);
......@@ -74,6 +77,7 @@ public class MainActivity extends ParentActivity {
etText1.setText(Save2SharedPreferences.read(ALIPAYNAME,this),TextView.BufferType.NORMAL);
etText2.setText(Save2SharedPreferences.read(API,this),TextView.BufferType.NORMAL);
etText3.setText(Save2SharedPreferences.read(WECHATPAYNAME,this),TextView.BufferType.NORMAL);
etToken.setText(Save2SharedPreferences.read(TOKEN,this),TextView.BufferType.NORMAL);
Button btButton = (Button) findViewById(R.id.btn_save_url);
btButton.setOnClickListener(new View.OnClickListener() {
......@@ -85,8 +89,11 @@ public class MainActivity extends ParentActivity {
Save2SharedPreferences.save(WECHATPAYNAME,stringWeChatPay,MainActivity.this);
stringAPI = etText2.getText().toString();
Save2SharedPreferences.save(API,stringAPI,MainActivity.this);
Toast.makeText(MainActivity.this,"保存成功,支付宝账号="+ stringAliPay +";微信账号="+ stringWeChatPay+";api="+ stringAPI,Toast.LENGTH_SHORT).show();
String token = etToken.getText().toString();
Save2SharedPreferences.save(TOKEN,token,MainActivity.this);
Toast.makeText(MainActivity.this,"保存成功,支付宝账号="+ stringAliPay +";微信账号="+ stringWeChatPay+";api="+ stringAPI+"token =" + token,Toast.LENGTH_SHORT).show();
PayHttp.recreateService();
}
});
......@@ -132,9 +139,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.pullList(Utils.payChannelZFB,userName);
WeChatNotificationListenerService.sendRequestWithOkHttp("hello","1111",Utils.payChannelZFB, HttpService.token);
}
});
......@@ -328,12 +337,6 @@ private void checkNotificationPermission() {
@Subscribe(threadMode = ThreadMode.ASYNC)
public void Event(ImageBean bean){
functionUrls.getBeans().add(bean);
Log.d(TAG, "Event: "+bean.getUrl());
}
@Override
protected void onDestroy() {
......
......@@ -23,10 +23,7 @@ import retrofit2.Response;
public class ActivePullCashList {
/**
*固定的 在服务器后台配置的
*/
private static final String token ="9908506dc651b6ce6e488c838c118354";
......@@ -93,7 +90,7 @@ public class ActivePullCashList {
public void pullList(String channel,String username){
HttpService httpService = PayHttp.get();
Call<PullMoneyResp> call = httpService.pullZFBCashList(channel,username,token);
Call<PullMoneyResp> call = httpService.pullZFBCashList(channel,username,HttpService.token);
call.enqueue(new Callback<PullMoneyResp>() {
@Override
......
......@@ -7,4 +7,22 @@ package com.yuqirong.listenwechatnotification.bean;
*/
public class BaseResult {
int status_code;
String message;
public int getStatus_code() {
return status_code;
}
public void setStatus_code(int status_code) {
this.status_code = status_code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
......@@ -47,7 +47,7 @@ public class BuildNotification {
public void postSuccessOrFaild(String mString){
//实例化NotificationCompat.Builde并设置相关属性
NotificationCompat.Builder builder = (NotificationCompat.Builder) new NotificationCompat.Builder(this.mContext)
NotificationCompat.Builder builder = new NotificationCompat.Builder(this.mContext,"2")
//设置小图标
.setSmallIcon(R.mipmap.ic_launcher)
//设置通知标题
......
package com.yuqirong.listenwechatnotification.askhttp;
package com.yuqirong.listenwechatnotification.http;
/**
* Created by Li on 2016/9/26.
......
package com.yuqirong.listenwechatnotification.http;
import com.yuqirong.listenwechatnotification.bean.BaseResult;
import com.yuqirong.listenwechatnotification.bean.ImageBean;
import com.yuqirong.listenwechatnotification.bean.PullMoneyResp;
import com.yuqirong.listenwechatnotification.bean.UpdateBean;
......@@ -7,6 +8,7 @@ import com.yuqirong.listenwechatnotification.bean.UpdateBean;
import java.util.ArrayList;
import java.util.List;
import io.reactivex.Observable;
import retrofit2.Call;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
......@@ -21,14 +23,23 @@ import retrofit2.http.Query;
*/
public interface HttpService {
/**
*固定的 在服务器后台配置的
*/
public static final String token ="43ee9ffb8ce4509437b7734ae3095473";
public String base_url = "http://test.fourth-pay.checheng.net/";
// public String base_url = "http://test.fourth-pay.checheng.net/";
public String base_url = "http://test.personal-pay.checheng.net";
// public String base_url = "http://www.haoyiwangluo.com/";
// public String base_url = "http://www.haoyiwangluo.com/";
public String notify_money_come = "index/pay/notify/person_app";
@POST("index/pay/notify/person_app")
Call<String> postClientMoney(@Field("notify_text") String notify_text, @Field("pay_to") String pay_to, @Field("type") String type);
@POST("/app-api/notify")
@FormUrlEncoded
@Headers({
"Accept: application/json"
})
Observable<BaseResult> postClientMoney(@Field("text") String text, @Field("username") String userName, @Field("gateway") String gateway, @Field("token") String token);
@GET("/app-api/app/status")
Call<UpdateBean> postSoftVersion(@Query("version") String version);
......
package com.yuqirong.listenwechatnotification.http;
import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import com.yuqirong.listenwechatnotification.MyApplication;
import com.yuqirong.listenwechatnotification.askhttp.HttpLoggingInterceptor;
import com.yuqirong.listenwechatnotification.http.HttpService;
import com.yuqirong.listenwechatnotification.uitl.Save2SharedPreferences;
import com.yuqirong.listenwechatnotification.uitl.Utils;
import java.io.IOException;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.converter.scalars.ScalarsConverterFactory;
import static com.yuqirong.listenwechatnotification.MainActivity.API;
......@@ -33,7 +25,13 @@ public class PayHttp {
}
return httpService;
}
}
/**
* 首页改变地址后 重新更新下url
*/
public static void recreateService(){
httpService = init();
}
private static HttpService init(){
OkHttpClient okHttpClient = new OkHttpClient.Builder()
......@@ -44,10 +42,9 @@ public class PayHttp {
String url = Save2SharedPreferences.read(API,MyApplication.get());
//建立retrofit对象
Retrofit retrofit = new Retrofit.Builder().baseUrl(url)
// //添加返回字符串的支持--不知道返回的是什么,添加字符串支持
// .addConverterFactory(ScalarsConverterFactory.create())
//添加GSON转换支持
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.client(okHttpClient)
.build();
......
......@@ -18,15 +18,23 @@ import com.orhanobut.logger.AndroidLogAdapter;
import com.orhanobut.logger.CsvFormatStrategy;
import com.orhanobut.logger.DiskLogAdapter;
import com.orhanobut.logger.Logger;
import com.yuqirong.listenwechatnotification.MyApplication;
import com.yuqirong.listenwechatnotification.bean.BaseResult;
import com.yuqirong.listenwechatnotification.function.BuildNotification;
import com.yuqirong.listenwechatnotification.MainActivity;
import com.yuqirong.listenwechatnotification.http.HttpService;
import com.yuqirong.listenwechatnotification.http.PayHttp;
import com.yuqirong.listenwechatnotification.uitl.Save2SharedPreferences;
import com.yuqirong.listenwechatnotification.uitl.Utils;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import io.reactivex.Observer;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
......@@ -40,24 +48,15 @@ import okhttp3.Response;
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public class WeChatNotificationListenerService extends NotificationListenerService {
private String ticker;
private static String aliPayPackageName = "com.eg.android.AlipayGphone";
private static String weChatPayPackageName = "com.tencent.mm";
private static String aliPayType = "zfbperson";
private static String weChatPayType = "wxperson";
private static String paytype;
// private Save2SharedPreferences save2SharedPreferences;
// @Override
// public void onCreate() {
// super.onCreate();
// android.os.Debug.waitForDebugger();
// }
@Override
......@@ -81,6 +80,14 @@ public class WeChatNotificationListenerService extends NotificationListenerServi
public void onNotificationPosted(StatusBarNotification sbn) {
Logger.d("WeChatNotificationListenerService onNotificationPosted");
Bundle notificationExtras = sbn.getNotification().extras;
String notificationTitle = notificationExtras.getString(Notification.EXTRA_TITLE);
CharSequence notificationText = notificationExtras.getCharSequence(Notification.EXTRA_TEXT);
//这个可能为空,得注意
CharSequence notificationSubText=notificationExtras.getCharSequence(Notification.EXTRA_SUB_TEXT);
Logger.d("notificationTitle " + notificationTitle + " notificationText " + notificationText + " notificationSubText " + notificationSubText) ;
if (!aliPayPackageName.equals(sbn.getPackageName())&& !weChatPayPackageName.equals(sbn.getPackageName())) {
return;
}
......@@ -88,12 +95,12 @@ public class WeChatNotificationListenerService extends NotificationListenerServi
String pay2set = "";
// save2SharedPreferences = new Save2SharedPreferences();
if (aliPayPackageName.equals(sbn.getPackageName())) {
paytype = aliPayType;
paytype = Utils.payChannelZFB;
pay2set = Save2SharedPreferences.read(MainActivity.ALIPAYNAME,getApplicationContext());
}
if (weChatPayPackageName.equals(sbn.getPackageName())) {
paytype = weChatPayType;
paytype = Utils.payChannelWX;
pay2set = Save2SharedPreferences.read(MainActivity.WECHATPAYNAME,getApplicationContext());
}
......@@ -109,18 +116,26 @@ public class WeChatNotificationListenerService extends NotificationListenerServi
Log.i("xiaolong", "open" + "------" + api);
BuildNotification mBuildNotification = new BuildNotification(getApplicationContext());
if(sbn.getNotification().tickerText !="" && sbn.getNotification().tickerText!="null") {
ticker = sbn.getNotification().tickerText.toString();
String contentText = null ;
if (!TextUtils.isEmpty(notificationText)){
contentText = notificationText.toString();
}
if (!TextUtils.isEmpty(sbn.getNotification().tickerText)){
contentText = sbn.getNotification().tickerText.toString();
}
if(!TextUtils.isEmpty(contentText)) {
if (weChatPayPackageName.equals(sbn.getPackageName())) {
if (ticker.contains("微信支付:")) {
ticker = ticker.substring(5);
mBuildNotification.listenSuccess(ticker);
sendRequestWithOkHttp(pay2set);
if (contentText.contains("微信支付:")) {
contentText = contentText.substring(5);
mBuildNotification.listenSuccess(contentText);
sendRequestWithOkHttp(contentText,pay2set,paytype,HttpService.token);
}
}else{
mBuildNotification.listenSuccess(ticker);
sendRequestWithOkHttp(pay2set);
mBuildNotification.listenSuccess(contentText);
sendRequestWithOkHttp(contentText,pay2set,paytype,HttpService.token);
}
......@@ -187,39 +202,31 @@ public class WeChatNotificationListenerService extends NotificationListenerServi
super.onListenerDisconnected();
}
private void sendRequestWithOkHttp(final String payto) {
public static void sendRequestWithOkHttp(String ticker,String payto,String paytype,String token) {
Logger.d("WeChatNotificationListenerService sendRequestWithOkHttp " + payto);
//开启线程来发起网络请求
new Thread(new Runnable() {
@Override
public void run() {
try {
OkHttpClient client = new OkHttpClient();
String api = Save2SharedPreferences.read(MainActivity.API,getApplicationContext());
//这边讲请求不用ref的方式,是因为api地址后期会随着变化而变化,不可以写成结构形式
RequestBody requestBody = new FormBody.Builder()
.add("notify_text",ticker)
.add("pay_to",payto)
.add("type",paytype)
.build();
Request request = new Request.Builder()
.url(api+"index/pay/notify/person_app")
.post(requestBody)
.build();
//发送请求获取服务器数据
Response response = client.newCall(request).execute();
String responseData = response.body().string();
System.out.println("返回结果:"+responseData);
// BuildNotification mBuildNotification = new BuildNotification(getApplicationContext());
// mBuildNotification.postSuccessOrFaild(responseData);
} catch (IOException e) {
e.printStackTrace();
}
PayHttp.get().postClientMoney(ticker,payto,paytype, token)
.subscribeOn(Schedulers.io())
.observeOn(Schedulers.io())
.subscribe(new Consumer<BaseResult>() {
@Override
public void accept(BaseResult s) throws Exception {
//发送请求获取服务器数据
Logger.d("返回结果:"+s.getStatus_code() + " " + s.getMessage());
BuildNotification mBuildNotification = new BuildNotification(MyApplication.get());
mBuildNotification.postSuccessOrFaild(s.getMessage());
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
//发送请求获取服务器数据
Logger.d("返回结果:"+throwable.getMessage());
BuildNotification mBuildNotification = new BuildNotification(MyApplication.get());
mBuildNotification.postSuccessOrFaild(throwable.getMessage());
}
});
}
}).start();
// String alipay = save2SharedPreferences.read(MainActivity.ALIPAYNAME,getApplicationContext());
// String api = save2SharedPreferences.read(MainActivity.API,getApplicationContext());
......
......@@ -35,6 +35,10 @@ public class Save2SharedPreferences {
SharedPreferences sharedPreferences =context.getSharedPreferences(name, MODE_PRIVATE);
return sharedPreferences.getString(key, HttpService.base_url);
}
if (key == MainActivity.TOKEN){
SharedPreferences sharedPreferences =context.getSharedPreferences(name, MODE_PRIVATE);
return sharedPreferences.getString(key, HttpService.token);
}
SharedPreferences sharedPreferences =context.getSharedPreferences(name, MODE_PRIVATE);
return sharedPreferences.getString(key,"");
}
......
......@@ -23,9 +23,9 @@ public class Utils {
//支付宝支付类型
public static String payChannelZFB = "alipaypersonal_scan";
public static String payChannelZFB = "alipaypersonal";
public static String payChannelWX = "wechat_personal";
public static String payChannelWX = "wechatpersonal";
public static int getLocalVersion(Context ctx) {
int localVersion = 0;
......
......@@ -24,7 +24,7 @@
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="100dp">
android:layout_height="wrap_content">
<TextView
android:id="@+id/text1"
......@@ -45,7 +45,7 @@
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="100dp">
android:layout_height="wrap_content">
<TextView
android:id="@+id/text3"
......@@ -66,7 +66,7 @@
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="100dp">
android:layout_height="wrap_content">
<TextView
android:id="@+id/text2"
......@@ -85,6 +85,24 @@
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="token:" />
<EditText
android:id="@+id/et_token"
android:layout_width="match_parent"
android:layout_height="50dp"
android:focusable="true"
android:focusableInTouchMode="true"
android:maxLines="4" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
......
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