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
d8e8eb97
authored
Jul 12, 2019
by
patpat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加离线支付action
parent
9239cb6e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
83 additions
and
1 deletions
+83
-1
app/src/main/java/com/bgycc/smartcanteen/action/PayOfflineAction.java
+75
-0
app/src/main/java/com/bgycc/smartcanteen/action/PayOnlineAction.java
+5
-1
app/src/main/java/com/bgycc/smartcanteen/server/websocket/MainWebSocket.java
+3
-0
No files found.
app/src/main/java/com/bgycc/smartcanteen/action/PayOfflineAction.java
0 → 100644
View file @
d8e8eb97
package
com
.
bgycc
.
smartcanteen
.
action
;
import
com.bgycc.smartcanteen.App
;
import
com.bgycc.smartcanteen.event.PayStateEvent
;
import
com.bgycc.smartcanteen.server.websocket.MainWebSocket
;
import
org.greenrobot.eventbus.EventBus
;
import
org.json.JSONObject
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.Locale
;
public
class
PayOfflineAction
extends
Action
{
public
PayOfflineAction
()
{
super
(
ActionEnum
.
PAY_OFFLINE
.
name
());
}
@Override
protected
void
setState
(
State
state
)
{
if
(
state
!=
getState
())
{
switch
(
state
)
{
case
RESQUEST_SUCCESS:
success
(
""
);
break
;
case
RESQUEST_FAIL:
case
RESQUEST_TIMEOUT:
fail
(
""
);
break
;
}
}
setState
(
state
);
}
public
void
exec
(
String
payCode
,
String
payCodeType
,
ActionResult
result
)
{
if
(
getState
()
!=
State
.
INITED
)
return
;
setState
(
State
.
STARTED
);
setActionResult
(
result
);
final
MainWebSocket
.
Response
response
=
new
MainWebSocket
.
Response
()
{
@Override
protected
void
onSuccess
(
JSONObject
data
,
String
message
)
{
cancel
();
setState
(
State
.
RESQUEST_SUCCESS
);
}
@Override
protected
void
onFail
(
JSONObject
data
,
String
message
,
String
code
)
{
cancel
();
setState
(
State
.
RESQUEST_FAIL
);
}
};
timeout
(
new
Runnable
()
{
@Override
public
void
run
()
{
if
(
response
.
isCancelled
())
return
;
response
.
cancel
();
setState
(
State
.
RESQUEST_TIMEOUT
);
}
},
10000
);
try
{
JSONObject
params
=
new
JSONObject
();
params
.
put
(
"equipmentNo"
,
App
.
Companion
.
getDeviceSN
());
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
();
}
}
}
app/src/main/java/com/bgycc/smartcanteen/action/PayOnlineAction.java
View file @
d8e8eb97
...
...
@@ -66,18 +66,22 @@ public class PayOnlineAction extends Action {
final
MainWebSocket
.
Response
response
=
new
MainWebSocket
.
Response
()
{
@Override
protected
void
onSuccess
(
JSONObject
data
,
String
message
)
{
cancel
();
setState
(
State
.
RESQUEST_SUCCESS
,
message
);
}
@Override
protected
void
onFail
(
JSONObject
data
,
String
message
,
String
code
)
{
cancel
();
setState
(
State
.
RESQUEST_FAIL
,
message
);
}
};
timeout
(
new
Runnable
()
{
@Override
public
void
run
()
{
if
(
response
.
isCancelled
())
return
;
response
.
cancel
();
setState
(
State
.
RES
PONSE_FAIL
,
"交易失败"
);
setState
(
State
.
RES
QUEST_TIMEOUT
,
"交易失败"
);
}
},
10000
);
...
...
app/src/main/java/com/bgycc/smartcanteen/server/websocket/MainWebSocket.java
View file @
d8e8eb97
...
...
@@ -250,6 +250,9 @@ public class MainWebSocket extends WebSocketClient {
}
}
public
boolean
isCancelled
()
{
return
this
.
cancel
;
}
public
void
cancel
()
{
this
.
cancel
=
true
;
}
...
...
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