Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
严琪
/
paysplug-in
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
4d7bd544
authored
Mar 21, 2018
by
jeffrey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
把主干代码合并过来了
parent
97f6615d
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
140 additions
and
85 deletions
+140
-85
app/build.gradle
+3
-3
app/src/main/java/com/yuqirong/listenwechatnotification/MainActivity.java
+14
-11
app/src/main/java/com/yuqirong/listenwechatnotification/askhttp/ActivePullCashList.java
+2
-5
app/src/main/java/com/yuqirong/listenwechatnotification/bean/BaseResult.java
+18
-0
app/src/main/java/com/yuqirong/listenwechatnotification/function/BuildNotification.java
+1
-1
app/src/main/java/com/yuqirong/listenwechatnotification/http/HttpLoggingInterceptor.java
+1
-1
app/src/main/java/com/yuqirong/listenwechatnotification/http/HttpService.java
+14
-3
app/src/main/java/com/yuqirong/listenwechatnotification/http/PayHttp.java
+8
-11
app/src/main/java/com/yuqirong/listenwechatnotification/service/WeChatNotificationListenerService.java
+52
-45
app/src/main/java/com/yuqirong/listenwechatnotification/uitl/Save2SharedPreferences.java
+4
-0
app/src/main/java/com/yuqirong/listenwechatnotification/uitl/Utils.java
+2
-2
app/src/main/res/layout/activity_main.xml
+21
-3
No files found.
app/build.gradle
View file @
4d7bd544
...
@@ -22,8 +22,8 @@ android {
...
@@ -22,8 +22,8 @@ android {
applicationId
"com.yuqirong.listenwechatnotification"
applicationId
"com.yuqirong.listenwechatnotification"
minSdkVersion
16
minSdkVersion
16
targetSdkVersion
26
targetSdkVersion
26
versionCode
12
versionCode
200000
versionName
"
1.21
"
versionName
"
2.0.0
"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}
}
buildTypes
{
buildTypes
{
...
@@ -52,7 +52,7 @@ dependencies {
...
@@ -52,7 +52,7 @@ dependencies {
compile
'com.squareup.retrofit2:converter-gson:2.1.0'
compile
'com.squareup.retrofit2:converter-gson:2.1.0'
//添加返回的字符串支付
//添加返回的字符串支付
compile
'com.squareup.retrofit2:converter-scalars: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
'com.google.zxing:core:3.2.1'
compile
'org.greenrobot:eventbus:3.0.0'
compile
'org.greenrobot:eventbus:3.0.0'
...
...
app/src/main/java/com/yuqirong/listenwechatnotification/MainActivity.java
View file @
4d7bd544
...
@@ -17,10 +17,11 @@ import android.widget.EditText;
...
@@ -17,10 +17,11 @@ import android.widget.EditText;
import
android.widget.TextView
;
import
android.widget.TextView
;
import
android.widget.Toast
;
import
android.widget.Toast
;
import
com.yuqirong.listenwechatnotification.askhttp.ActivePullCashList
;
import
com.yuqirong.listenwechatnotification.askhttp.UpdateApk
;
import
com.yuqirong.listenwechatnotification.askhttp.UpdateApk
;
import
com.yuqirong.listenwechatnotification.bean.WorkAction
;
import
com.yuqirong.listenwechatnotification.bean.WorkAction
;
import
com.yuqirong.listenwechatnotification.broadcastReceiver.MyCashReceiver
;
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.service.WeChatNotificationListenerService
;
import
com.yuqirong.listenwechatnotification.uitl.Save2SharedPreferences
;
import
com.yuqirong.listenwechatnotification.uitl.Save2SharedPreferences
;
import
com.yuqirong.listenwechatnotification.uitl.Utils
;
import
com.yuqirong.listenwechatnotification.uitl.Utils
;
...
@@ -48,6 +49,7 @@ public class MainActivity extends ParentActivity {
...
@@ -48,6 +49,7 @@ public class MainActivity extends ParentActivity {
public
static
String
ALIPAYNAME
=
"key1"
;
public
static
String
ALIPAYNAME
=
"key1"
;
public
static
String
WECHATPAYNAME
=
"key3"
;
public
static
String
WECHATPAYNAME
=
"key3"
;
public
static
String
API
=
"key2"
;
public
static
String
API
=
"key2"
;
public
static
String
TOKEN
=
"token"
;
String
TAG
=
"MainActivity"
;
String
TAG
=
"MainActivity"
;
...
@@ -67,6 +69,7 @@ public class MainActivity extends ParentActivity {
...
@@ -67,6 +69,7 @@ public class MainActivity extends ParentActivity {
final
EditText
etText1
=
(
EditText
)
findViewById
(
R
.
id
.
et_text1
);
final
EditText
etText1
=
(
EditText
)
findViewById
(
R
.
id
.
et_text1
);
final
EditText
etText2
=
(
EditText
)
findViewById
(
R
.
id
.
et_text2
);
final
EditText
etText2
=
(
EditText
)
findViewById
(
R
.
id
.
et_text2
);
final
EditText
etText3
=
(
EditText
)
findViewById
(
R
.
id
.
et_text3
);
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
);
versionCode
=
(
TextView
)
findViewById
(
R
.
id
.
tv_version_name
);
...
@@ -74,6 +77,7 @@ public class MainActivity extends ParentActivity {
...
@@ -74,6 +77,7 @@ public class MainActivity extends ParentActivity {
etText1
.
setText
(
Save2SharedPreferences
.
read
(
ALIPAYNAME
,
this
),
TextView
.
BufferType
.
NORMAL
);
etText1
.
setText
(
Save2SharedPreferences
.
read
(
ALIPAYNAME
,
this
),
TextView
.
BufferType
.
NORMAL
);
etText2
.
setText
(
Save2SharedPreferences
.
read
(
API
,
this
),
TextView
.
BufferType
.
NORMAL
);
etText2
.
setText
(
Save2SharedPreferences
.
read
(
API
,
this
),
TextView
.
BufferType
.
NORMAL
);
etText3
.
setText
(
Save2SharedPreferences
.
read
(
WECHATPAYNAME
,
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
);
Button
btButton
=
(
Button
)
findViewById
(
R
.
id
.
btn_save_url
);
btButton
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
btButton
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
...
@@ -85,8 +89,11 @@ public class MainActivity extends ParentActivity {
...
@@ -85,8 +89,11 @@ public class MainActivity extends ParentActivity {
Save2SharedPreferences
.
save
(
WECHATPAYNAME
,
stringWeChatPay
,
MainActivity
.
this
);
Save2SharedPreferences
.
save
(
WECHATPAYNAME
,
stringWeChatPay
,
MainActivity
.
this
);
stringAPI
=
etText2
.
getText
().
toString
();
stringAPI
=
etText2
.
getText
().
toString
();
Save2SharedPreferences
.
save
(
API
,
stringAPI
,
MainActivity
.
this
);
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 {
...
@@ -132,9 +139,11 @@ public class MainActivity extends ParentActivity {
findViewById
(
R
.
id
.
btn_test
).
setOnClickListener
(
new
View
.
OnClickListener
()
{
findViewById
(
R
.
id
.
btn_test
).
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
@Override
public
void
onClick
(
View
v
)
{
public
void
onClick
(
View
v
)
{
String
userName
=
Save2SharedPreferences
.
read
(
ALIPAYNAME
,
MainActivity
.
this
);
// String userName = Save2SharedPreferences.read(ALIPAYNAME,MainActivity.this);
ActivePullCashList
pullCashList
=
new
ActivePullCashList
();
// ActivePullCashList pullCashList = new ActivePullCashList();
pullCashList
.
pullList
(
Utils
.
payChannelZFB
,
userName
);
// pullCashList.pullList(Utils.payChannelZFB,userName);
WeChatNotificationListenerService
.
sendRequestWithOkHttp
(
"hello"
,
"1111"
,
Utils
.
payChannelZFB
,
HttpService
.
token
);
}
}
});
});
...
@@ -328,12 +337,6 @@ private void checkNotificationPermission() {
...
@@ -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
@Override
protected
void
onDestroy
()
{
protected
void
onDestroy
()
{
...
...
app/src/main/java/com/yuqirong/listenwechatnotification/askhttp/ActivePullCashList.java
View file @
4d7bd544
...
@@ -23,10 +23,7 @@ import retrofit2.Response;
...
@@ -23,10 +23,7 @@ import retrofit2.Response;
public
class
ActivePullCashList
{
public
class
ActivePullCashList
{
/**
*固定的 在服务器后台配置的
*/
private
static
final
String
token
=
"9908506dc651b6ce6e488c838c118354"
;
...
@@ -93,7 +90,7 @@ public class ActivePullCashList {
...
@@ -93,7 +90,7 @@ public class ActivePullCashList {
public
void
pullList
(
String
channel
,
String
username
){
public
void
pullList
(
String
channel
,
String
username
){
HttpService
httpService
=
PayHttp
.
get
();
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
>()
{
call
.
enqueue
(
new
Callback
<
PullMoneyResp
>()
{
@Override
@Override
...
...
app/src/main/java/com/yuqirong/listenwechatnotification/bean/BaseResult.java
View file @
4d7bd544
...
@@ -7,4 +7,22 @@ package com.yuqirong.listenwechatnotification.bean;
...
@@ -7,4 +7,22 @@ package com.yuqirong.listenwechatnotification.bean;
*/
*/
public
class
BaseResult
{
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
;
}
}
}
app/src/main/java/com/yuqirong/listenwechatnotification/function/BuildNotification.java
View file @
4d7bd544
...
@@ -47,7 +47,7 @@ public class BuildNotification {
...
@@ -47,7 +47,7 @@ public class BuildNotification {
public
void
postSuccessOrFaild
(
String
mString
){
public
void
postSuccessOrFaild
(
String
mString
){
//实例化NotificationCompat.Builde并设置相关属性
//实例化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
)
.
setSmallIcon
(
R
.
mipmap
.
ic_launcher
)
//设置通知标题
//设置通知标题
...
...
app/src/main/java/com/yuqirong/listenwechatnotification/http/HttpLoggingInterceptor.java
View file @
4d7bd544
package
com
.
yuqirong
.
listenwechatnotification
.
ask
http
;
package
com
.
yuqirong
.
listenwechatnotification
.
http
;
/**
/**
* Created by Li on 2016/9/26.
* Created by Li on 2016/9/26.
...
...
app/src/main/java/com/yuqirong/listenwechatnotification/http/HttpService.java
View file @
4d7bd544
package
com
.
yuqirong
.
listenwechatnotification
.
http
;
package
com
.
yuqirong
.
listenwechatnotification
.
http
;
import
com.yuqirong.listenwechatnotification.bean.BaseResult
;
import
com.yuqirong.listenwechatnotification.bean.ImageBean
;
import
com.yuqirong.listenwechatnotification.bean.ImageBean
;
import
com.yuqirong.listenwechatnotification.bean.PullMoneyResp
;
import
com.yuqirong.listenwechatnotification.bean.PullMoneyResp
;
import
com.yuqirong.listenwechatnotification.bean.UpdateBean
;
import
com.yuqirong.listenwechatnotification.bean.UpdateBean
;
...
@@ -7,6 +8,7 @@ import com.yuqirong.listenwechatnotification.bean.UpdateBean;
...
@@ -7,6 +8,7 @@ import com.yuqirong.listenwechatnotification.bean.UpdateBean;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
io.reactivex.Observable
;
import
retrofit2.Call
;
import
retrofit2.Call
;
import
retrofit2.http.Field
;
import
retrofit2.http.Field
;
import
retrofit2.http.FormUrlEncoded
;
import
retrofit2.http.FormUrlEncoded
;
...
@@ -21,14 +23,23 @@ import retrofit2.http.Query;
...
@@ -21,14 +23,23 @@ import retrofit2.http.Query;
*/
*/
public
interface
HttpService
{
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 base_url = "http://www.haoyiwangluo.com/";
// public String base_url = "http://www.haoyiwangluo.com/";
public
String
notify_money_come
=
"index/pay/notify/person_app"
;
public
String
notify_money_come
=
"index/pay/notify/person_app"
;
@POST
(
"index/pay/notify/person_app"
)
@POST
(
"/app-api/notify"
)
Call
<
String
>
postClientMoney
(
@Field
(
"notify_text"
)
String
notify_text
,
@Field
(
"pay_to"
)
String
pay_to
,
@Field
(
"type"
)
String
type
);
@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"
)
@GET
(
"/app-api/app/status"
)
Call
<
UpdateBean
>
postSoftVersion
(
@Query
(
"version"
)
String
version
);
Call
<
UpdateBean
>
postSoftVersion
(
@Query
(
"version"
)
String
version
);
...
...
app/src/main/java/com/yuqirong/listenwechatnotification/http/PayHttp.java
View file @
4d7bd544
package
com
.
yuqirong
.
listenwechatnotification
.
http
;
package
com
.
yuqirong
.
listenwechatnotification
.
http
;
import
com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
;
import
com.yuqirong.listenwechatnotification.MyApplication
;
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.Save2SharedPreferences
;
import
com.yuqirong.listenwechatnotification.uitl.Utils
;
import
java.io.IOException
;
import
okhttp3.Interceptor
;
import
okhttp3.OkHttpClient
;
import
okhttp3.OkHttpClient
;
import
okhttp3.Request
;
import
okhttp3.Response
;
import
retrofit2.Retrofit
;
import
retrofit2.Retrofit
;
import
retrofit2.converter.gson.GsonConverterFactory
;
import
retrofit2.converter.gson.GsonConverterFactory
;
import
retrofit2.converter.scalars.ScalarsConverterFactory
;
import
static
com
.
yuqirong
.
listenwechatnotification
.
MainActivity
.
API
;
import
static
com
.
yuqirong
.
listenwechatnotification
.
MainActivity
.
API
;
...
@@ -33,7 +25,13 @@ public class PayHttp {
...
@@ -33,7 +25,13 @@ public class PayHttp {
}
}
return
httpService
;
return
httpService
;
}
}
}
/**
* 首页改变地址后 重新更新下url
*/
public
static
void
recreateService
(){
httpService
=
init
();
}
}
private
static
HttpService
init
(){
private
static
HttpService
init
(){
OkHttpClient
okHttpClient
=
new
OkHttpClient
.
Builder
()
OkHttpClient
okHttpClient
=
new
OkHttpClient
.
Builder
()
...
@@ -44,10 +42,9 @@ public class PayHttp {
...
@@ -44,10 +42,9 @@ public class PayHttp {
String
url
=
Save2SharedPreferences
.
read
(
API
,
MyApplication
.
get
());
String
url
=
Save2SharedPreferences
.
read
(
API
,
MyApplication
.
get
());
//建立retrofit对象
//建立retrofit对象
Retrofit
retrofit
=
new
Retrofit
.
Builder
().
baseUrl
(
url
)
Retrofit
retrofit
=
new
Retrofit
.
Builder
().
baseUrl
(
url
)
// //添加返回字符串的支持--不知道返回的是什么,添加字符串支持
// .addConverterFactory(ScalarsConverterFactory.create())
//添加GSON转换支持
//添加GSON转换支持
.
addConverterFactory
(
GsonConverterFactory
.
create
())
.
addConverterFactory
(
GsonConverterFactory
.
create
())
.
addCallAdapterFactory
(
RxJava2CallAdapterFactory
.
create
())
.
client
(
okHttpClient
)
.
client
(
okHttpClient
)
.
build
();
.
build
();
...
...
app/src/main/java/com/yuqirong/listenwechatnotification/service/WeChatNotificationListenerService.java
View file @
4d7bd544
...
@@ -18,15 +18,23 @@ import com.orhanobut.logger.AndroidLogAdapter;
...
@@ -18,15 +18,23 @@ import com.orhanobut.logger.AndroidLogAdapter;
import
com.orhanobut.logger.CsvFormatStrategy
;
import
com.orhanobut.logger.CsvFormatStrategy
;
import
com.orhanobut.logger.DiskLogAdapter
;
import
com.orhanobut.logger.DiskLogAdapter
;
import
com.orhanobut.logger.Logger
;
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.function.BuildNotification
;
import
com.yuqirong.listenwechatnotification.MainActivity
;
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.Save2SharedPreferences
;
import
com.yuqirong.listenwechatnotification.uitl.Utils
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Field
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
io.reactivex.Observer
;
import
io.reactivex.functions.Consumer
;
import
io.reactivex.schedulers.Schedulers
;
import
okhttp3.FormBody
;
import
okhttp3.FormBody
;
import
okhttp3.OkHttpClient
;
import
okhttp3.OkHttpClient
;
import
okhttp3.Request
;
import
okhttp3.Request
;
...
@@ -40,24 +48,15 @@ import okhttp3.Response;
...
@@ -40,24 +48,15 @@ import okhttp3.Response;
@TargetApi
(
Build
.
VERSION_CODES
.
JELLY_BEAN_MR2
)
@TargetApi
(
Build
.
VERSION_CODES
.
JELLY_BEAN_MR2
)
public
class
WeChatNotificationListenerService
extends
NotificationListenerService
{
public
class
WeChatNotificationListenerService
extends
NotificationListenerService
{
private
String
ticker
;
private
static
String
aliPayPackageName
=
"com.eg.android.AlipayGphone"
;
private
static
String
aliPayPackageName
=
"com.eg.android.AlipayGphone"
;
private
static
String
weChatPayPackageName
=
"com.tencent.mm"
;
private
static
String
weChatPayPackageName
=
"com.tencent.mm"
;
private
static
String
aliPayType
=
"zfbperson"
;
private
static
String
weChatPayType
=
"wxperson"
;
private
static
String
paytype
;
private
static
String
paytype
;
// private Save2SharedPreferences save2SharedPreferences;
// @Override
// public void onCreate() {
// super.onCreate();
// android.os.Debug.waitForDebugger();
// }
@Override
@Override
...
@@ -81,6 +80,14 @@ public class WeChatNotificationListenerService extends NotificationListenerServi
...
@@ -81,6 +80,14 @@ public class WeChatNotificationListenerService extends NotificationListenerServi
public
void
onNotificationPosted
(
StatusBarNotification
sbn
)
{
public
void
onNotificationPosted
(
StatusBarNotification
sbn
)
{
Logger
.
d
(
"WeChatNotificationListenerService onNotificationPosted"
);
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
()))
{
if
(!
aliPayPackageName
.
equals
(
sbn
.
getPackageName
())&&
!
weChatPayPackageName
.
equals
(
sbn
.
getPackageName
()))
{
return
;
return
;
}
}
...
@@ -88,12 +95,12 @@ public class WeChatNotificationListenerService extends NotificationListenerServi
...
@@ -88,12 +95,12 @@ public class WeChatNotificationListenerService extends NotificationListenerServi
String
pay2set
=
""
;
String
pay2set
=
""
;
// save2SharedPreferences = new Save2SharedPreferences();
// save2SharedPreferences = new Save2SharedPreferences();
if
(
aliPayPackageName
.
equals
(
sbn
.
getPackageName
()))
{
if
(
aliPayPackageName
.
equals
(
sbn
.
getPackageName
()))
{
paytype
=
aliPayType
;
paytype
=
Utils
.
payChannelZFB
;
pay2set
=
Save2SharedPreferences
.
read
(
MainActivity
.
ALIPAYNAME
,
getApplicationContext
());
pay2set
=
Save2SharedPreferences
.
read
(
MainActivity
.
ALIPAYNAME
,
getApplicationContext
());
}
}
if
(
weChatPayPackageName
.
equals
(
sbn
.
getPackageName
()))
{
if
(
weChatPayPackageName
.
equals
(
sbn
.
getPackageName
()))
{
paytype
=
weChatPayType
;
paytype
=
Utils
.
payChannelWX
;
pay2set
=
Save2SharedPreferences
.
read
(
MainActivity
.
WECHATPAYNAME
,
getApplicationContext
());
pay2set
=
Save2SharedPreferences
.
read
(
MainActivity
.
WECHATPAYNAME
,
getApplicationContext
());
}
}
...
@@ -109,18 +116,26 @@ public class WeChatNotificationListenerService extends NotificationListenerServi
...
@@ -109,18 +116,26 @@ public class WeChatNotificationListenerService extends NotificationListenerServi
Log
.
i
(
"xiaolong"
,
"open"
+
"------"
+
api
);
Log
.
i
(
"xiaolong"
,
"open"
+
"------"
+
api
);
BuildNotification
mBuildNotification
=
new
BuildNotification
(
getApplicationContext
());
BuildNotification
mBuildNotification
=
new
BuildNotification
(
getApplicationContext
());
if
(
sbn
.
getNotification
().
tickerText
!=
""
&&
sbn
.
getNotification
().
tickerText
!=
"null"
)
{
String
contentText
=
null
;
ticker
=
sbn
.
getNotification
().
tickerText
.
toString
();
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
(
weChatPayPackageName
.
equals
(
sbn
.
getPackageName
()))
{
if
(
ticker
.
contains
(
"微信支付:"
))
{
if
(
contentText
.
contains
(
"微信支付:"
))
{
ticker
=
ticker
.
substring
(
5
);
contentText
=
contentText
.
substring
(
5
);
mBuildNotification
.
listenSuccess
(
ticker
);
mBuildNotification
.
listenSuccess
(
contentText
);
sendRequestWithOkHttp
(
pay2set
);
sendRequestWithOkHttp
(
contentText
,
pay2set
,
paytype
,
HttpService
.
token
);
}
}
}
else
{
}
else
{
mBuildNotification
.
listenSuccess
(
ticker
);
mBuildNotification
.
listenSuccess
(
contentText
);
sendRequestWithOkHttp
(
pay2set
);
sendRequestWithOkHttp
(
contentText
,
pay2set
,
paytype
,
HttpService
.
token
);
}
}
...
@@ -187,39 +202,31 @@ public class WeChatNotificationListenerService extends NotificationListenerServi
...
@@ -187,39 +202,31 @@ public class WeChatNotificationListenerService extends NotificationListenerServi
super
.
onListenerDisconnected
();
super
.
onListenerDisconnected
();
}
}
p
rivate
void
sendRequestWithOkHttp
(
final
String
payto
)
{
p
ublic
static
void
sendRequestWithOkHttp
(
String
ticker
,
String
payto
,
String
paytype
,
String
token
)
{
Logger
.
d
(
"WeChatNotificationListenerService sendRequestWithOkHttp "
+
payto
);
Logger
.
d
(
"WeChatNotificationListenerService sendRequestWithOkHttp "
+
payto
);
//开启线程来发起网络请求
//开启线程来发起网络请求
new
Thread
(
new
Runnable
()
{
PayHttp
.
get
().
postClientMoney
(
ticker
,
payto
,
paytype
,
token
)
.
subscribeOn
(
Schedulers
.
io
())
.
observeOn
(
Schedulers
.
io
())
.
subscribe
(
new
Consumer
<
BaseResult
>()
{
@Override
@Override
public
void
run
()
{
public
void
accept
(
BaseResult
s
)
throws
Exception
{
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
)
{
Logger
.
d
(
"返回结果:"
+
s
.
getStatus_code
()
+
" "
+
s
.
getMessage
());
e
.
printStackTrace
();
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 alipay = save2SharedPreferences.read(MainActivity.ALIPAYNAME,getApplicationContext());
// String api = save2SharedPreferences.read(MainActivity.API,getApplicationContext());
// String api = save2SharedPreferences.read(MainActivity.API,getApplicationContext());
...
...
app/src/main/java/com/yuqirong/listenwechatnotification/uitl/Save2SharedPreferences.java
View file @
4d7bd544
...
@@ -35,6 +35,10 @@ public class Save2SharedPreferences {
...
@@ -35,6 +35,10 @@ public class Save2SharedPreferences {
SharedPreferences
sharedPreferences
=
context
.
getSharedPreferences
(
name
,
MODE_PRIVATE
);
SharedPreferences
sharedPreferences
=
context
.
getSharedPreferences
(
name
,
MODE_PRIVATE
);
return
sharedPreferences
.
getString
(
key
,
HttpService
.
base_url
);
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
);
SharedPreferences
sharedPreferences
=
context
.
getSharedPreferences
(
name
,
MODE_PRIVATE
);
return
sharedPreferences
.
getString
(
key
,
""
);
return
sharedPreferences
.
getString
(
key
,
""
);
}
}
...
...
app/src/main/java/com/yuqirong/listenwechatnotification/uitl/Utils.java
View file @
4d7bd544
...
@@ -23,9 +23,9 @@ public class Utils {
...
@@ -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
)
{
public
static
int
getLocalVersion
(
Context
ctx
)
{
int
localVersion
=
0
;
int
localVersion
=
0
;
...
...
app/src/main/res/layout/activity_main.xml
View file @
4d7bd544
...
@@ -24,7 +24,7 @@
...
@@ -24,7 +24,7 @@
<RelativeLayout
<RelativeLayout
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"
100dp
"
>
android:layout_height=
"
wrap_content
"
>
<TextView
<TextView
android:id=
"@+id/text1"
android:id=
"@+id/text1"
...
@@ -45,7 +45,7 @@
...
@@ -45,7 +45,7 @@
<RelativeLayout
<RelativeLayout
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"
100dp
"
>
android:layout_height=
"
wrap_content
"
>
<TextView
<TextView
android:id=
"@+id/text3"
android:id=
"@+id/text3"
...
@@ -66,7 +66,7 @@
...
@@ -66,7 +66,7 @@
<RelativeLayout
<RelativeLayout
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"
100dp
"
>
android:layout_height=
"
wrap_content
"
>
<TextView
<TextView
android:id=
"@+id/text2"
android:id=
"@+id/text2"
...
@@ -85,6 +85,24 @@
...
@@ -85,6 +85,24 @@
</RelativeLayout>
</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
<LinearLayout
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment