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
d2bceb1b
authored
Sep 09, 2019
by
patpat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
在线支付增加3次重试机制,修改超时文案
parent
89869522
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
32 deletions
+37
-32
app/src/main/AndroidManifest.xml
+6
-2
app/src/main/java/com/bgycc/smartcanteen/action/Action.java
+1
-0
app/src/main/java/com/bgycc/smartcanteen/action/PayOnlineAction.java
+29
-29
app/src/main/java/com/bgycc/smartcanteen/server/websocket/MainWebSocket.java
+1
-1
No files found.
app/src/main/AndroidManifest.xml
View file @
d2bceb1b
...
@@ -19,15 +19,19 @@
...
@@ -19,15 +19,19 @@
<activity
android:name=
".activity.MainActivity"
>
<activity
android:name=
".activity.MainActivity"
>
<intent-filter>
<intent-filter>
<action
android:name=
"android.intent.action.MAIN"
/>
<action
android:name=
"android.intent.action.MAIN"
/>
<category
android:name=
"android.intent.category.LAUNCHER"
/>
<category
android:name=
"android.intent.category.LAUNCHER"
/>
</intent-filter>
</intent-filter>
<intent-filter>
<intent-filter>
<action
android:name=
"android.intent.action.MAIN"
/>
<action
android:name=
"android.intent.action.MAIN"
/>
<category
android:name=
"android.intent.category.HOME"
/>
<category
android:name=
"android.intent.category.HOME"
/>
<category
android:name=
"android.intent.category.DEFAULT"
/>
<category
android:name=
"android.intent.category.DEFAULT"
/>
</intent-filter>
</intent-filter>
<intent-filter>
<action
android:name=
"android.intent.action.VIEW"
/>
<category
android:name=
"android.intent.category.DEFAULT"
/>
<category
android:name=
"android.intent.category.BROWSABLE"
/>
<data
android:scheme=
"canteen"
/>
</intent-filter>
</activity>
</activity>
<!--<receiver android:name=".receiver.BootReceiver" >-->
<!--<receiver android:name=".receiver.BootReceiver" >-->
...
...
app/src/main/java/com/bgycc/smartcanteen/action/Action.java
View file @
d2bceb1b
...
@@ -7,6 +7,7 @@ public abstract class Action {
...
@@ -7,6 +7,7 @@ public abstract class Action {
RESPONSE_FAIL
,
RESPONSE_FAIL
,
RESQUEST_TIMEOUT
,
RESQUEST_TIMEOUT
,
RESQUEST_FAIL
,
RESQUEST_FAIL
,
TIMEOUT
,
FAIL
,
FAIL
,
UNINIT
,
UNINIT
,
INITED
,
INITED
,
...
...
app/src/main/java/com/bgycc/smartcanteen/action/PayOnlineAction.java
View file @
d2bceb1b
package
com
.
bgycc
.
smartcanteen
.
action
;
package
com
.
bgycc
.
smartcanteen
.
action
;
import
android.util.Log
;
import
com.bgycc.smartcanteen.App
;
import
com.bgycc.smartcanteen.App
;
import
com.bgycc.smartcanteen.event.PayStateEvent
;
import
com.bgycc.smartcanteen.event.PayStateEvent
;
import
com.bgycc.smartcanteen.helper.TimerHelper
;
import
com.bgycc.smartcanteen.helper.TimerHelper
;
...
@@ -9,10 +8,6 @@ import com.bgycc.smartcanteen.util.DateUtil;
...
@@ -9,10 +8,6 @@ import com.bgycc.smartcanteen.util.DateUtil;
import
org.greenrobot.eventbus.EventBus
;
import
org.greenrobot.eventbus.EventBus
;
import
org.json.JSONObject
;
import
org.json.JSONObject
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.Locale
;
public
class
PayOnlineAction
extends
Action
{
public
class
PayOnlineAction
extends
Action
{
private
static
final
String
TAG
=
PayOnlineAction
.
class
.
getSimpleName
();
private
static
final
String
TAG
=
PayOnlineAction
.
class
.
getSimpleName
();
...
@@ -26,16 +21,18 @@ public class PayOnlineAction extends Action {
...
@@ -26,16 +21,18 @@ public class PayOnlineAction extends Action {
}
}
private
String
mPayCode
;
private
String
mPayCode
;
private
long
mResponseTimeoutId
=
-
1
;
private
long
mTimeoutId
=
-
1
;
private
Runnable
mActionRunnable
;
public
PayOnlineAction
()
{
public
PayOnlineAction
()
{
super
(
ActionEnum
.
PAY_ONLINE
.
name
());
super
(
ActionEnum
.
PAY_ONLINE
.
name
());
MainWebSocket
.
subscribe
(
ActionEnum
.
PAY_RESULT
.
name
(),
mPayResultResponse
);
MainWebSocket
.
subscribe
(
ActionEnum
.
PAY_RESULT
.
name
(),
mPayResultResponse
);
}
}
private
void
cancelResponseTimeout
()
{
private
void
cancelTimeout
()
{
TimerHelper
.
INSTANCE
.
cancel
(
mResponseTimeoutId
);
TimerHelper
.
INSTANCE
.
cancel
(
mTimeoutId
);
mResponseTimeoutId
=
-
1
;
mTimeoutId
=
-
1
;
mActionRunnable
=
null
;
}
}
private
void
setState
(
State
state
,
String
message
)
{
private
void
setState
(
State
state
,
String
message
)
{
...
@@ -46,19 +43,11 @@ public class PayOnlineAction extends Action {
...
@@ -46,19 +43,11 @@ public class PayOnlineAction extends Action {
break
;
break
;
case
STARTED:
case
STARTED:
EventBus
.
getDefault
().
post
(
new
PayStateEvent
(
PayStateEvent
.
StateEnum
.
WAIT
,
message
));
EventBus
.
getDefault
().
post
(
new
PayStateEvent
(
PayStateEvent
.
StateEnum
.
WAIT
,
message
));
cancelResponseTimeout
();
cancelTimeout
();
break
;
case
RESQUEST_SUCCESS:
mResponseTimeoutId
=
TimerHelper
.
INSTANCE
.
timeout
(
new
Runnable
()
{
@Override
public
void
run
()
{
setState
(
State
.
RESPONSE_TIMEOUT
,
"交易失败"
);
}
},
10000
);
break
;
break
;
case
RESPONSE_SUCCESS:
case
RESPONSE_SUCCESS:
EventBus
.
getDefault
().
post
(
new
PayStateEvent
(
PayStateEvent
.
StateEnum
.
SUCCESS
,
message
));
EventBus
.
getDefault
().
post
(
new
PayStateEvent
(
PayStateEvent
.
StateEnum
.
SUCCESS
,
message
));
cancel
Response
Timeout
();
cancelTimeout
();
mPayCode
=
""
;
mPayCode
=
""
;
success
(
message
);
success
(
message
);
TimerHelper
.
INSTANCE
.
timeout
(
new
Runnable
()
{
TimerHelper
.
INSTANCE
.
timeout
(
new
Runnable
()
{
...
@@ -69,11 +58,10 @@ public class PayOnlineAction extends Action {
...
@@ -69,11 +58,10 @@ public class PayOnlineAction extends Action {
},
3000
);
},
3000
);
break
;
break
;
case
RESQUEST_FAIL:
case
RESQUEST_FAIL:
case
RESQUEST_TIMEOUT:
case
RESPONSE_FAIL:
case
RESPONSE_FAIL:
case
RESPONSE_
TIMEOUT:
case
TIMEOUT:
EventBus
.
getDefault
().
post
(
new
PayStateEvent
(
PayStateEvent
.
StateEnum
.
FAIL
,
message
));
EventBus
.
getDefault
().
post
(
new
PayStateEvent
(
PayStateEvent
.
StateEnum
.
FAIL
,
message
));
cancel
Response
Timeout
();
cancelTimeout
();
mPayCode
=
""
;
mPayCode
=
""
;
fail
(
message
);
fail
(
message
);
TimerHelper
.
INSTANCE
.
timeout
(
new
Runnable
()
{
TimerHelper
.
INSTANCE
.
timeout
(
new
Runnable
()
{
...
@@ -100,34 +88,44 @@ public class PayOnlineAction extends Action {
...
@@ -100,34 +88,44 @@ public class PayOnlineAction extends Action {
setActionResult
(
result
);
setActionResult
(
result
);
mPayCode
=
payCode
;
mPayCode
=
payCode
;
final
long
timeoutId
=
TimerHelper
.
INSTANCE
.
timeout
(
new
Runnable
()
{
mTimeoutId
=
TimerHelper
.
INSTANCE
.
loop
(
new
TimerHelper
.
LoopTask
()
{
@Override
@Override
public
void
run
()
{
public
void
run
(
long
id
,
boolean
isLastTime
)
{
setState
(
State
.
RESQUEST_TIMEOUT
,
"交易失败"
);
if
(
isLastTime
)
{
setState
(
State
.
TIMEOUT
,
"交易超时"
);
}
else
{
if
(
mActionRunnable
!=
null
)
{
mActionRunnable
.
run
();
}
}
},
10000
);
}
}
},
10000
,
4
,
10000
);
final
MainWebSocket
.
Response
response
=
new
MainWebSocket
.
Response
()
{
final
MainWebSocket
.
Response
response
=
new
MainWebSocket
.
Response
()
{
@Override
@Override
protected
void
onSuccess
(
JSONObject
data
,
String
message
)
{
protected
void
onSuccess
(
JSONObject
data
,
String
message
)
{
TimerHelper
.
INSTANCE
.
cancel
(
timeoutId
);
setState
(
State
.
RESQUEST_SUCCESS
,
message
);
setState
(
State
.
RESQUEST_SUCCESS
,
message
);
}
}
@Override
@Override
protected
void
onFail
(
JSONObject
data
,
String
message
,
String
code
)
{
protected
void
onFail
(
JSONObject
data
,
String
message
,
String
code
)
{
TimerHelper
.
INSTANCE
.
cancel
(
timeoutId
);
setState
(
State
.
RESQUEST_FAIL
,
message
);
setState
(
State
.
RESQUEST_FAIL
,
message
);
}
}
};
};
try
{
try
{
JSONObject
params
=
new
JSONObject
();
final
JSONObject
params
=
new
JSONObject
();
params
.
put
(
"equipmentNo"
,
App
.
Companion
.
getDeviceSN
());
params
.
put
(
"equipmentNo"
,
App
.
Companion
.
getDeviceSN
());
params
.
put
(
"payCode"
,
payCode
);
params
.
put
(
"payCode"
,
payCode
);
params
.
put
(
"terminalType"
,
payCodeType
);
params
.
put
(
"terminalType"
,
payCodeType
);
params
.
put
(
"time"
,
DateUtil
.
getCurrentTimestamp
());
params
.
put
(
"time"
,
DateUtil
.
getCurrentTimestamp
());
mActionRunnable
=
new
Runnable
()
{
@Override
public
void
run
()
{
setState
(
State
.
RESQUEST
,
""
);
setState
(
State
.
RESQUEST
,
""
);
MainWebSocket
.
action
(
getAction
(),
params
,
response
);
MainWebSocket
.
action
(
getAction
(),
params
,
response
);
}
};
mActionRunnable
.
run
();
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
...
@@ -140,6 +138,7 @@ public class PayOnlineAction extends Action {
...
@@ -140,6 +138,7 @@ public class PayOnlineAction extends Action {
String
payCode
=
data
.
optString
(
"payCode"
,
""
);
String
payCode
=
data
.
optString
(
"payCode"
,
""
);
if
(
payCode
.
equals
(
mPayCode
))
{
if
(
payCode
.
equals
(
mPayCode
))
{
setState
(
State
.
RESPONSE_SUCCESS
,
message
);
setState
(
State
.
RESPONSE_SUCCESS
,
message
);
MainWebSocket
.
response
(
data
.
optInt
(
"serialNumber"
,
-
1
),
"0"
,
"已接收"
);
}
}
}
}
@Override
@Override
...
@@ -148,6 +147,7 @@ public class PayOnlineAction extends Action {
...
@@ -148,6 +147,7 @@ public class PayOnlineAction extends Action {
String
payCode
=
data
.
optString
(
"payCode"
,
""
);
String
payCode
=
data
.
optString
(
"payCode"
,
""
);
if
(
payCode
.
equals
(
mPayCode
))
{
if
(
payCode
.
equals
(
mPayCode
))
{
setState
(
State
.
RESPONSE_FAIL
,
message
);
setState
(
State
.
RESPONSE_FAIL
,
message
);
MainWebSocket
.
response
(
data
.
optInt
(
"serialNumber"
,
-
1
),
"0"
,
"已接收"
);
}
}
}
}
};
};
...
...
app/src/main/java/com/bgycc/smartcanteen/server/websocket/MainWebSocket.java
View file @
d2bceb1b
...
@@ -110,7 +110,7 @@ public class MainWebSocket extends WebSocketClient {
...
@@ -110,7 +110,7 @@ public class MainWebSocket extends WebSocketClient {
return
list
.
remove
(
response
);
return
list
.
remove
(
response
);
}
}
p
rivate
static
void
response
(
int
sessionId
,
String
code
,
String
message
)
{
p
ublic
static
void
response
(
int
sessionId
,
String
code
,
String
message
)
{
try
{
try
{
JSONObject
json
=
new
JSONObject
();
JSONObject
json
=
new
JSONObject
();
json
.
put
(
FieldEnum
.
equipmentId
.
name
(),
sDeviceSN
);
json
.
put
(
FieldEnum
.
equipmentId
.
name
(),
sDeviceSN
);
...
...
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