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
aa7df233
authored
Mar 21, 2018
by
jeffrey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
升级适配
parent
4d7bd544
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
166 additions
and
52 deletions
+166
-52
app/build.gradle
+2
-2
app/src/main/java/com/yuqirong/listenwechatnotification/MainActivity.java
+3
-3
app/src/main/java/com/yuqirong/listenwechatnotification/askhttp/UpdateApk.java
+55
-35
app/src/main/java/com/yuqirong/listenwechatnotification/bean/BaseResult.java
+10
-1
app/src/main/java/com/yuqirong/listenwechatnotification/bean/UpgradeResult.java
+74
-0
app/src/main/java/com/yuqirong/listenwechatnotification/http/HttpService.java
+8
-3
app/src/main/java/com/yuqirong/listenwechatnotification/service/WeChatNotificationListenerService.java
+14
-8
No files found.
app/build.gradle
View file @
aa7df233
...
...
@@ -22,8 +22,8 @@ android {
applicationId
"com.yuqirong.listenwechatnotification"
minSdkVersion
16
targetSdkVersion
26
versionCode
20000
0
versionName
"2.0.0"
versionCode
20000
2
versionName
"2.0.0
2
"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes
{
...
...
app/src/main/java/com/yuqirong/listenwechatnotification/MainActivity.java
View file @
aa7df233
...
...
@@ -101,7 +101,7 @@ public class MainActivity extends ParentActivity {
buttonUpDate
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
checkPermission
();
upgrade
();
}
});
...
...
@@ -184,7 +184,7 @@ public class MainActivity extends ParentActivity {
private
void
checkPermission
()
{
private
void
upgrade
()
{
//检查权限(NEED_PERMISSION)是否被授权 PackageManager.PERMISSION_GRANTED表示同意授权
if
(
ActivityCompat
.
checkSelfPermission
(
this
,
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
)
!=
PackageManager
.
PERMISSION_GRANTED
)
{
...
...
@@ -197,7 +197,7 @@ public class MainActivity extends ParentActivity {
ActivityCompat
.
requestPermissions
(
this
,
new
String
[]{
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
},
1
);
}
else
{
UpdateApk
updateApkhttps
=
new
UpdateApk
(
MainActivity
.
this
);
UpdateApk
.
checkAndUpdate
(
MainActivity
.
this
);
}
}
...
...
app/src/main/java/com/yuqirong/listenwechatnotification/askhttp/UpdateApk.java
View file @
aa7df233
...
...
@@ -3,18 +3,27 @@ package com.yuqirong.listenwechatnotification.askhttp;
import
android.content.Context
;
import
android.widget.Toast
;
import
com.yuqirong.listenwechatnotification.MainActivity
;
import
com.yuqirong.listenwechatnotification.MyApplication
;
import
com.yuqirong.listenwechatnotification.bean.BaseResult
;
import
com.yuqirong.listenwechatnotification.bean.UpdateBean
;
import
com.yuqirong.listenwechatnotification.bean.UpgradeResult
;
import
com.yuqirong.listenwechatnotification.function.UpgradeFunction
;
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
io.reactivex.android.schedulers.AndroidSchedulers
;
import
io.reactivex.functions.Consumer
;
import
io.reactivex.schedulers.Schedulers
;
import
retrofit2.Call
;
import
retrofit2.Callback
;
import
retrofit2.Response
;
import
retrofit2.Retrofit
;
import
retrofit2.converter.gson.GsonConverterFactory
;
import
retrofit2.converter.scalars.ScalarsConverterFactory
;
import
retrofit2.http.HTTP
;
import
static
com
.
yuqirong
.
listenwechatnotification
.
MainActivity
.
API
;
...
...
@@ -32,45 +41,56 @@ public class UpdateApk {
public
UpdateApk
()
{
}
public
UpdateApk
(
final
Context
context
){
String
temp
=
Utils
.
getLocalVersionName
(
context
);
String
url
=
Save2SharedPreferences
.
read
(
API
,
context
);
//建立retrofit对象
Retrofit
retrofit
=
new
Retrofit
.
Builder
().
baseUrl
(
url
)
//添加返回字符串的支持--不知道返回的是什么,添加字符串支持
.
addConverterFactory
(
ScalarsConverterFactory
.
create
())
//添加GSON转换支持
.
addConverterFactory
(
GsonConverterFactory
.
create
())
.
build
();
public
static
void
checkAndUpdate
(
final
Context
context
){
final
String
versionName
=
Utils
.
getLocalVersionName
(
context
);
String
token
=
Save2SharedPreferences
.
read
(
MainActivity
.
TOKEN
,
MyApplication
.
get
());
PayHttp
.
get
()
.
postSoftVersion
(
versionName
,
token
)
.
subscribeOn
(
Schedulers
.
io
())
.
observeOn
(
AndroidSchedulers
.
mainThread
())
.
subscribe
(
new
Consumer
<
BaseResult
<
UpgradeResult
>>()
{
@Override
public
void
accept
(
BaseResult
<
UpgradeResult
>
upgradeResult
)
throws
Exception
{
if
(
upgradeResult
.
getStatus_code
()
==
200
&&
upgradeResult
.
getData
()
!=
null
){
if
(
checkNew
(
versionName
,
upgradeResult
.
getData
().
getVersion
())){
UpgradeFunction
updateApk
=
new
UpgradeFunction
(
context
);
String
baseUrl
=
Save2SharedPreferences
.
read
(
MainActivity
.
API
,
MyApplication
.
get
());
updateApk
.
downloadApk
(
baseUrl
+
upgradeResult
.
getData
().
getUrl
());
Toast
.
makeText
(
context
,
"有新版本,准备下载"
,
Toast
.
LENGTH_SHORT
).
show
();
}
else
{
Toast
.
makeText
(
context
,
"当前为最高版本"
,
Toast
.
LENGTH_SHORT
).
show
();
}
}
}
},
new
Consumer
<
Throwable
>()
{
@Override
public
void
accept
(
Throwable
throwable
)
throws
Exception
{
Toast
.
makeText
(
context
,
throwable
.
getMessage
(),
Toast
.
LENGTH_SHORT
).
show
();
}
});
//获取接口
HttpService
service
=
retrofit
.
create
(
HttpService
.
class
);
//调用方法-返回 回调更换为对象
Call
<
UpdateBean
>
call
=
service
.
postSoftVersion
(
temp
);
//异步调用
call
.
enqueue
(
new
Callback
<
UpdateBean
>()
{
@Override
public
void
onResponse
(
Call
<
UpdateBean
>
call
,
Response
<
UpdateBean
>
response
)
{
if
(
response
.
body
().
getStatus
().
equals
(
NEEDUPGRADE
)){
updateApk
=
new
UpgradeFunction
(
context
);
updateApk
.
downloadApk
(
response
.
body
().
getUrl
());
}
else
{
Toast
.
makeText
(
context
,
"当前为最高版本"
,
Toast
.
LENGTH_SHORT
).
show
();
}
}
}
@Override
public
void
onFailure
(
Call
<
UpdateBean
>
call
,
Throwable
t
)
{
/**
*
* @param ourVersion
* @param remoteVersion
* @return true remote > our
*/
private
static
boolean
checkNew
(
String
ourVersion
,
String
remoteVersion
){
String
[]
ourVersions
=
ourVersion
.
split
(
"[.]"
);
String
[]
remoteVersions
=
remoteVersion
.
split
(
"[.]"
);
int
our
=
Integer
.
valueOf
(
ourVersions
[
0
])*
10000
+
Integer
.
valueOf
(
ourVersions
[
1
])*
100
+
Integer
.
valueOf
(
ourVersions
[
2
]);
int
remote
=
Integer
.
valueOf
(
remoteVersions
[
0
])*
10000
+
Integer
.
valueOf
(
remoteVersions
[
1
])*
100
+
Integer
.
valueOf
(
remoteVersions
[
2
]);
if
(
remote
>
our
){
return
true
;
}
else
{
return
false
;
}
}
});
}
}
app/src/main/java/com/yuqirong/listenwechatnotification/bean/BaseResult.java
View file @
aa7df233
...
...
@@ -6,9 +6,10 @@ package com.yuqirong.listenwechatnotification.bean;
* 作者:Li
*/
public
class
BaseResult
{
public
class
BaseResult
<
T
>
{
int
status_code
;
String
message
;
T
data
;
public
int
getStatus_code
()
{
return
status_code
;
...
...
@@ -25,4 +26,12 @@ public class BaseResult {
public
void
setMessage
(
String
message
)
{
this
.
message
=
message
;
}
public
T
getData
()
{
return
data
;
}
public
void
setData
(
T
data
)
{
this
.
data
=
data
;
}
}
app/src/main/java/com/yuqirong/listenwechatnotification/bean/UpgradeResult.java
0 → 100644
View file @
aa7df233
package
com
.
yuqirong
.
listenwechatnotification
.
bean
;
/**
* 创建日期:2018/3/21 on 15:08
* 描述:
* 作者:Li
*/
public
class
UpgradeResult
extends
BaseResult
{
/**
* id : 2
* version : 2.2.33
* version_number : 20233
* created_at : 2018-03-20 16:53:48
* updated_at : 2018-03-20 16:53:48
* url : http://localhost/storage/public/apps/5879ab88346017d0ed1ffec92227c9e9.apk
*/
private
int
id
;
private
String
version
;
private
int
version_number
;
private
String
created_at
;
private
String
updated_at
;
private
String
url
;
public
int
getId
()
{
return
id
;
}
public
void
setId
(
int
id
)
{
this
.
id
=
id
;
}
public
String
getVersion
()
{
return
version
;
}
public
void
setVersion
(
String
version
)
{
this
.
version
=
version
;
}
public
int
getVersion_number
()
{
return
version_number
;
}
public
void
setVersion_number
(
int
version_number
)
{
this
.
version_number
=
version_number
;
}
public
String
getCreated_at
()
{
return
created_at
;
}
public
void
setCreated_at
(
String
created_at
)
{
this
.
created_at
=
created_at
;
}
public
String
getUpdated_at
()
{
return
updated_at
;
}
public
void
setUpdated_at
(
String
updated_at
)
{
this
.
updated_at
=
updated_at
;
}
public
String
getUrl
()
{
return
url
;
}
public
void
setUrl
(
String
url
)
{
this
.
url
=
url
;
}
}
app/src/main/java/com/yuqirong/listenwechatnotification/http/HttpService.java
View file @
aa7df233
...
...
@@ -4,6 +4,7 @@ import com.yuqirong.listenwechatnotification.bean.BaseResult;
import
com.yuqirong.listenwechatnotification.bean.ImageBean
;
import
com.yuqirong.listenwechatnotification.bean.PullMoneyResp
;
import
com.yuqirong.listenwechatnotification.bean.UpdateBean
;
import
com.yuqirong.listenwechatnotification.bean.UpgradeResult
;
import
java.util.ArrayList
;
import
java.util.List
;
...
...
@@ -26,7 +27,7 @@ public interface HttpService {
/**
*固定的 在服务器后台配置的
*/
public
static
final
String
token
=
"
43ee9ffb8ce4509437b7734ae3095473
"
;
public
static
final
String
token
=
"
52e05c504da884303a10e8d0fa749c12
"
;
// public String base_url = "http://test.fourth-pay.checheng.net/";
public
String
base_url
=
"http://test.personal-pay.checheng.net"
;
...
...
@@ -41,8 +42,12 @@ public interface HttpService {
})
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
);
@POST
(
"/app-api/upgrade"
)
@FormUrlEncoded
@Headers
({
"Accept: application/json"
})
Observable
<
BaseResult
<
UpgradeResult
>>
postSoftVersion
(
@Field
(
"version"
)
String
version
,
@Field
(
"token"
)
String
token
);
@POST
(
"/app-api/amounts"
)
@FormUrlEncoded
...
...
app/src/main/java/com/yuqirong/listenwechatnotification/service/WeChatNotificationListenerService.java
View file @
aa7df233
...
...
@@ -13,6 +13,7 @@ import android.service.notification.StatusBarNotification;
import
android.text.TextUtils
;
import
android.util.Log
;
import
android.widget.RemoteViews
;
import
android.widget.Toast
;
import
com.orhanobut.logger.AndroidLogAdapter
;
import
com.orhanobut.logger.CsvFormatStrategy
;
...
...
@@ -33,6 +34,7 @@ import java.util.ArrayList;
import
java.util.List
;
import
io.reactivex.Observer
;
import
io.reactivex.android.schedulers.AndroidSchedulers
;
import
io.reactivex.functions.Consumer
;
import
io.reactivex.schedulers.Schedulers
;
import
okhttp3.FormBody
;
...
...
@@ -123,18 +125,21 @@ public class WeChatNotificationListenerService extends NotificationListenerServi
if
(!
TextUtils
.
isEmpty
(
sbn
.
getNotification
().
tickerText
)){
contentText
=
sbn
.
getNotification
().
tickerText
.
toString
();
}
String
token
=
Save2SharedPreferences
.
read
(
MainActivity
.
TOKEN
,
MyApplication
.
get
());
if
(!
TextUtils
.
isEmpty
(
contentText
))
{
if
(
weChatPayPackageName
.
equals
(
sbn
.
getPackageName
()))
{
if
(
contentText
.
contains
(
"微信支付:"
))
{
contentText
=
contentText
.
substring
(
5
);
if
(
contentText
.
contains
(
"微信支付"
))
{
int
pos
=
contentText
.
indexOf
(
":"
);
if
(
pos
>
0
){
contentText
=
contentText
.
substring
(
pos
+
1
);
}
mBuildNotification
.
listenSuccess
(
contentText
);
sendRequestWithOkHttp
(
contentText
,
pay2set
,
paytype
,
HttpService
.
token
);
sendRequestWithOkHttp
(
contentText
,
pay2set
,
paytype
,
token
);
}
}
else
{
mBuildNotification
.
listenSuccess
(
contentText
);
sendRequestWithOkHttp
(
contentText
,
pay2set
,
paytype
,
HttpService
.
token
);
sendRequestWithOkHttp
(
contentText
,
pay2set
,
paytype
,
token
);
}
...
...
@@ -207,13 +212,14 @@ public class WeChatNotificationListenerService extends NotificationListenerServi
//开启线程来发起网络请求
PayHttp
.
get
().
postClientMoney
(
ticker
,
payto
,
paytype
,
token
)
.
subscribeOn
(
Schedulers
.
io
())
.
observeOn
(
Schedulers
.
io
())
.
observeOn
(
AndroidSchedulers
.
mainThread
())
.
subscribe
(
new
Consumer
<
BaseResult
>()
{
@Override
public
void
accept
(
BaseResult
s
)
throws
Exception
{
//发送请求获取服务器数据
Logger
.
d
(
"返回结果:"
+
s
.
getStatus_code
()
+
" "
+
s
.
getMessage
());
String
result
=
"返回结果:"
+
s
.
getStatus_code
()
+
" "
+
s
.
getMessage
();
Logger
.
d
(
result
);
Toast
.
makeText
(
MyApplication
.
get
(),
result
,
Toast
.
LENGTH_LONG
).
show
();
BuildNotification
mBuildNotification
=
new
BuildNotification
(
MyApplication
.
get
());
mBuildNotification
.
postSuccessOrFaild
(
s
.
getMessage
());
}
...
...
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