Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
huangzhicong
/
SmartCanteen
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
9239cb6e
authored
Jul 12, 2019
by
patpat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完善action处理
parent
f13aa4d3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
13 deletions
+30
-13
app/src/main/java/com/bgycc/smartcanteen/action/PayOnlineAction.java
+20
-5
app/src/main/java/com/bgycc/smartcanteen/server/websocket/MainWebSocket.java
+10
-8
No files found.
app/src/main/java/com/bgycc/smartcanteen/action/PayOnlineAction.java
View file @
9239cb6e
...
...
@@ -12,6 +12,8 @@ import java.util.Locale;
public
class
PayOnlineAction
extends
Action
{
private
String
mPayCode
;
public
PayOnlineAction
()
{
super
(
ActionEnum
.
PAY_ONLINE
.
name
());
MainWebSocket
.
subscribe
(
ActionEnum
.
PAY_RESULT
.
name
(),
mPayResultResponse
);
...
...
@@ -28,6 +30,7 @@ public class PayOnlineAction extends Action {
break
;
case
RESPONSE_SUCCESS:
EventBus
.
getDefault
().
post
(
new
PayStateEvent
(
PayStateEvent
.
StateEnum
.
SUCCESS
,
message
));
success
(
message
);
timeout
(
new
Runnable
()
{
@Override
public
void
run
()
{
...
...
@@ -40,6 +43,7 @@ public class PayOnlineAction extends Action {
case
RESPONSE_FAIL:
case
RESPONSE_TIMEOUT:
EventBus
.
getDefault
().
post
(
new
PayStateEvent
(
PayStateEvent
.
StateEnum
.
FAIL
,
message
));
fail
(
message
);
timeout
(
new
Runnable
()
{
@Override
public
void
run
()
{
...
...
@@ -55,7 +59,9 @@ public class PayOnlineAction extends Action {
public
void
exec
(
String
payCode
,
String
payCodeType
,
ActionResult
result
)
{
if
(
getState
()
!=
State
.
INITED
)
return
;
setState
(
State
.
STARTED
,
""
);
setActionResult
(
result
);
mPayCode
=
payCode
;
final
MainWebSocket
.
Response
response
=
new
MainWebSocket
.
Response
()
{
@Override
...
...
@@ -63,8 +69,8 @@ public class PayOnlineAction extends Action {
setState
(
State
.
RESQUEST_SUCCESS
,
message
);
}
@Override
protected
void
onFail
(
String
code
,
String
messag
e
)
{
setState
(
State
.
RES
PONSE
_FAIL
,
message
);
protected
void
onFail
(
JSONObject
data
,
String
message
,
String
cod
e
)
{
setState
(
State
.
RES
QUEST
_FAIL
,
message
);
}
};
timeout
(
new
Runnable
()
{
...
...
@@ -81,6 +87,7 @@ public class PayOnlineAction extends Action {
params
.
put
(
"payCode"
,
payCode
);
params
.
put
(
"terminalType"
,
payCodeType
);
params
.
put
(
"time"
,
new
SimpleDateFormat
(
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
,
Locale
.
getDefault
()).
format
(
new
Date
()));
setState
(
State
.
RESQUEST
,
""
);
MainWebSocket
.
action
(
getAction
(),
params
,
response
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
...
...
@@ -90,11 +97,19 @@ public class PayOnlineAction extends Action {
MainWebSocket
.
Response
mPayResultResponse
=
new
MainWebSocket
.
Response
()
{
@Override
protected
void
onSuccess
(
JSONObject
data
,
String
message
)
{
super
.
onSuccess
(
data
,
message
);
if
(
data
==
null
)
return
;
String
payCode
=
data
.
optString
(
"payCode"
,
""
);
if
(
payCode
.
equals
(
mPayCode
))
{
setState
(
State
.
RESPONSE_SUCCESS
,
message
);
}
}
@Override
protected
void
onFail
(
String
code
,
String
message
)
{
super
.
onFail
(
code
,
message
);
protected
void
onFail
(
JSONObject
data
,
String
message
,
String
code
)
{
if
(
data
==
null
)
return
;
String
payCode
=
data
.
optString
(
"payCode"
,
""
);
if
(
payCode
.
equals
(
mPayCode
))
{
setState
(
State
.
RESPONSE_FAIL
,
message
);
}
}
};
}
app/src/main/java/com/bgycc/smartcanteen/server/websocket/MainWebSocket.java
View file @
9239cb6e
...
...
@@ -52,7 +52,7 @@ public class MainWebSocket extends WebSocketClient {
if
(
sDeviceSN
==
null
||
sDeviceSN
.
isEmpty
())
return
;
EventBus
.
getDefault
().
post
(
new
ConnectStateEvent
(
ConnectStateEvent
.
CONNECTING
));
sInstance
=
new
MainWebSocket
(
new
URI
(
"ws://10.18
1.0.56:5000
/websocket/"
+
sDeviceSN
));
sInstance
=
new
MainWebSocket
(
new
URI
(
"ws://10.18
7.18.204:9001
/websocket/"
+
sDeviceSN
));
sInstance
.
connect
();
}
catch
(
URISyntaxException
e
)
{
e
.
printStackTrace
();
...
...
@@ -225,10 +225,11 @@ public class MainWebSocket extends WebSocketClient {
response
.
parse
(
code
,
res
);
String
message
=
res
.
optString
(
FieldEnum
.
message
.
name
());
JSONObject
data
=
res
.
optJSONObject
(
FieldEnum
.
data
.
name
());
if
(
CODE_OK
.
equals
(
code
))
{
response
.
onSuccess
(
res
.
optJSONObject
(
FieldEnum
.
data
.
name
())
,
message
);
response
.
onSuccess
(
data
,
message
);
}
else
{
response
.
onFail
(
code
,
messag
e
);
response
.
onFail
(
data
,
message
,
cod
e
);
}
}
}
...
...
@@ -241,10 +242,11 @@ public class MainWebSocket extends WebSocketClient {
if
(
res
==
null
)
return
;
String
message
=
res
.
optString
(
FieldEnum
.
message
.
name
());
JSONObject
data
=
res
.
optJSONObject
(
FieldEnum
.
data
.
name
());
if
(
CODE_OK
.
equals
(
code
))
{
success
(
res
.
optJSONObject
(
FieldEnum
.
data
.
name
())
,
message
);
success
(
data
,
message
);
}
else
{
fail
(
code
,
messag
e
);
fail
(
data
,
message
,
cod
e
);
}
}
...
...
@@ -257,12 +259,12 @@ public class MainWebSocket extends WebSocketClient {
onSuccess
(
data
,
message
);
}
public
void
fail
(
String
code
,
String
messag
e
){
public
void
fail
(
JSONObject
data
,
String
message
,
String
cod
e
){
if
(
this
.
cancel
)
return
;
onFail
(
code
,
messag
e
);
onFail
(
data
,
message
,
cod
e
);
}
protected
void
onSuccess
(
JSONObject
data
,
String
message
)
{}
protected
void
onFail
(
String
code
,
String
messag
e
)
{}
protected
void
onFail
(
JSONObject
data
,
String
message
,
String
cod
e
)
{}
}
}
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