Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
TangKuPos
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
王海
TangKuPos
Commits
4426ab65
Commit
4426ab65
authored
Apr 10, 2018
by
王海
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
提交百富支付
parent
151b12fa
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
210 additions
and
60 deletions
+210
-60
app/src/main/java/com/xingdata/zzdpos/C.java
app/src/main/java/com/xingdata/zzdpos/C.java
+2
-1
app/src/main/java/com/xingdata/zzdpos/base/BaseActivity.java
app/src/main/java/com/xingdata/zzdpos/base/BaseActivity.java
+26
-2
app/src/main/java/com/xingdata/zzdpos/base/BaseDialog.java
app/src/main/java/com/xingdata/zzdpos/base/BaseDialog.java
+3
-2
neptune/src/main/java/com/xingdata/pay/neptune/NeptuneCenter.java
...src/main/java/com/xingdata/pay/neptune/NeptuneCenter.java
+23
-0
neptune/src/main/java/com/xingdata/pay/neptune/ipc/C.java
neptune/src/main/java/com/xingdata/pay/neptune/ipc/C.java
+6
-2
neptune/src/main/java/com/xingdata/pay/neptune/ipc/Factory.java
...e/src/main/java/com/xingdata/pay/neptune/ipc/Factory.java
+101
-51
neptune/src/main/java/com/xingdata/pay/neptune/ipc/IRequest.java
.../src/main/java/com/xingdata/pay/neptune/ipc/IRequest.java
+41
-1
neptune/src/main/java/com/xingdata/pay/neptune/ipc/ResultFilter.java
.../main/java/com/xingdata/pay/neptune/ipc/ResultFilter.java
+8
-1
No files found.
app/src/main/java/com/xingdata/zzdpos/C.java
View file @
4426ab65
...
...
@@ -646,8 +646,9 @@ public class C {
public
static
final
String
SUCC
=
"0000"
;
}
public
final
class
SYSTEM
{
public
static
final
class
SYSTEM
{
public
static
final
String
DIALOGISDISMISS
=
"DIALOGISDISMISS"
;
public
static
boolean
mStateEnable
=
false
;
}
public
final
class
TRULE_STATUS
{
...
...
app/src/main/java/com/xingdata/zzdpos/base/BaseActivity.java
View file @
4426ab65
...
...
@@ -4,6 +4,7 @@ import android.content.Context;
import
android.databinding.DataBindingUtil
;
import
android.databinding.ViewDataBinding
;
import
android.os.Bundle
;
import
android.os.PersistableBundle
;
import
android.support.annotation.Nullable
;
import
android.support.v7.app.AppCompatDelegate
;
import
android.view.KeyEvent
;
...
...
@@ -63,10 +64,12 @@ public abstract class BaseActivity<P extends BasePresenter, B extends ViewDataBi
if
(!(
this
instanceof
BaseView
))
{
throw
new
RuntimeException
(
getClass
().
getSimpleName
()
+
"需要实现继承自BaseView的行为接口"
);
}
if
(!(
this
.
getClass
().
getGenericSuperclass
()
instanceof
ParameterizedType
&&
((
ParameterizedType
)
(
this
.
getClass
().
getGenericSuperclass
())).
getActualTypeArguments
().
length
>
0
))
{
if
(!(
this
.
getClass
().
getGenericSuperclass
()
instanceof
ParameterizedType
&&
((
ParameterizedType
)
(
this
.
getClass
()
.
getGenericSuperclass
())).
getActualTypeArguments
().
length
>
0
))
{
throw
new
RuntimeException
(
getClass
().
getSimpleName
()
+
"在继承时,需要注明泛型类"
);
}
Class
mPresenterClass
=
(
Class
)
((
ParameterizedType
)
(
this
.
getClass
().
getGenericSuperclass
())).
getActualTypeArguments
()[
0
];
Class
mPresenterClass
=
(
Class
)
((
ParameterizedType
)
(
this
.
getClass
().
getGenericSuperclass
())).
getActualTypeArguments
()
[
0
];
mPresenter
=
InstanceUtil
.
getInstance
(
mPresenterClass
);
mPresenter
.
setIntent
(
getIntent
()).
setView
(
this
).
build
();
}
...
...
@@ -76,6 +79,8 @@ public abstract class BaseActivity<P extends BasePresenter, B extends ViewDataBi
super
.
onDestroy
();
RxBus
.
get
().
unregister
(
mContext
);
if
(
mPresenter
!=
null
)
mPresenter
.
onDetached
();
// 注销服务
// com.xingdata.pay.neptune.ipc.Factory.unBindService(this);
}
public
abstract
void
initView
();
...
...
@@ -121,14 +126,33 @@ public abstract class BaseActivity<P extends BasePresenter, B extends ViewDataBi
}
}
@Override
protected
void
onStart
()
{
C
.
SYSTEM
.
mStateEnable
=
true
;
super
.
onStart
();
}
@Override
protected
void
onResume
()
{
C
.
SYSTEM
.
mStateEnable
=
true
;
if
(
SPUtils
.
getInstance
().
getBoolean
(
C
.
SYSTEM
.
DIALOGISDISMISS
))
{
mLoadingDialog
.
dismiss
();
}
super
.
onResume
();
}
@Override
public
void
onSaveInstanceState
(
Bundle
outState
,
PersistableBundle
outPersistentState
)
{
C
.
SYSTEM
.
mStateEnable
=
false
;
super
.
onSaveInstanceState
(
outState
,
outPersistentState
);
}
@Override
protected
void
onStop
()
{
C
.
SYSTEM
.
mStateEnable
=
false
;
super
.
onStop
();
}
@Override
public
void
pop
()
{
if
(
getSupportFragmentManager
().
getFragments
().
size
()
>
1
)
{
...
...
app/src/main/java/com/xingdata/zzdpos/base/BaseDialog.java
View file @
4426ab65
...
...
@@ -233,7 +233,7 @@ public abstract class BaseDialog<P extends BasePresenter, B extends ViewDataBind
* @param mRecLen 自动关闭的时间
*/
public
void
show
(
BaseActivity
activity
,
int
mRecLen
)
{
if
(
AppUtils
.
isAppForeground
())
{
if
(
AppUtils
.
isAppForeground
()
&&
C
.
SYSTEM
.
mStateEnable
)
{
if
(!
isShowing
)
{
this
.
recLen
=
mRecLen
;
this
.
shutDown
=
true
;
...
...
@@ -283,7 +283,7 @@ public abstract class BaseDialog<P extends BasePresenter, B extends ViewDataBind
* 关闭
*/
public
void
dismiss
()
{
if
(
AppUtils
.
isAppForeground
())
{
if
(
AppUtils
.
isAppForeground
()
&&
C
.
SYSTEM
.
mStateEnable
)
{
if
(
isShowing
)
{
isShowing
=
false
;
if
(
getBaseActivity
()
!=
null
&&
getBaseActivity
().
mDialogs
!=
null
)
{
...
...
@@ -351,4 +351,5 @@ public abstract class BaseDialog<P extends BasePresenter, B extends ViewDataBind
mBaseBinding
.
btnConfirm
.
setText
(
OK
);
return
this
;
}
}
\ No newline at end of file
neptune/src/main/java/com/xingdata/pay/neptune/NeptuneCenter.java
View file @
4426ab65
...
...
@@ -41,6 +41,29 @@ public class NeptuneCenter {
public
Observable
<
Response
>
pay
(
int
payChannel
,
Long
orderAmt
)
{
return
Factory
.
pay
(
payChannel
,
orderAmt
);
}
/**
* 退款
*
* @param payChannel 支付渠道
* @param orderAmt 金额
* @return 支付结果的Observable
*/
public
Observable
<
Response
>
refund
(
int
payChannel
,
Long
orderAmt
)
{
return
Factory
.
refund
(
payChannel
,
orderAmt
);
}
/**
* 交易状态
*
* @param orderAmt 原交易金额,为null则不参与查询
* @param origOrderNo 原订单号
* @param transUniqueId 原交易流水号, 为null则不参与查询
* @return
*/
public
Observable
<
Response
>
query
(
Long
orderAmt
,
String
origOrderNo
,
String
transUniqueId
)
{
return
Factory
.
query
(
orderAmt
,
origOrderNo
,
transUniqueId
);
}
}
...
...
neptune/src/main/java/com/xingdata/pay/neptune/ipc/C.java
View file @
4426ab65
...
...
@@ -2,8 +2,8 @@ package com.xingdata.pay.neptune.ipc;
public
class
C
{
static
String
APP_ID
=
""
;
static
String
APP_NAME
=
""
;
static
String
APP_ID
=
"
com.xingdata.zzdpos
"
;
static
String
APP_NAME
=
"
TangKuPos
"
;
/**
* 重试次数
...
...
@@ -101,5 +101,9 @@ public class C {
* 预授权完成请求撤销
*/
final
static
String
AUTH_CM_VOID
=
"AUTH_CM_VOID"
;
/**
* 交易状态查询
*/
public
static
final
String
TRANS_STAUS_QUERY
=
"ONLINE_QUERY"
;
}
}
neptune/src/main/java/com/xingdata/pay/neptune/ipc/Factory.java
View file @
4426ab65
package
com
.
xingdata
.
pay
.
neptune
.
ipc
;
import
android.app.Service
;
import
android.content.ComponentName
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.ServiceConnection
;
import
android.content.pm.PackageManager
;
import
android.content.pm.ResolveInfo
;
import
android.os.IBinder
;
import
android.os.RemoteException
;
import
com.alibaba.fastjson.JSON
;
import
com.blankj.utilcode.util.LogUtils
;
import
com.blankj.utilcode.util.ToastUtils
;
import
com.pax.pay.service.aidl.PayService
;
import
com.xingdata.pay.neptune.NeptuneCenter
;
import
com.xingdata.pay.neptune.Response
;
import
java.util.List
;
import
io.reactivex.Observable
;
import
io.reactivex.android.schedulers.AndroidSchedulers
;
import
io.reactivex.schedulers.Schedulers
;
public
class
Factory
{
private
static
PayService
mPayService
;
private
static
ServiceConnection
serviceConnection
;
private
static
class
FactoryHolder
{
private
static
final
Factory
INSTANCE
=
new
Factory
();
...
...
@@ -37,23 +32,101 @@ public class Factory {
}
public
void
init
(
Context
context
)
{
LogUtils
.
e
(
"开始初始化"
);
ServiceConnection
conn
=
new
ServiceConnection
()
{
@Override
public
void
onServiceConnected
(
ComponentName
componentName
,
IBinder
iBinder
)
{
LogUtils
.
e
(
"Service Connected!"
);
mPayService
=
PayService
.
Stub
.
asInterface
(
iBinder
);
if
(
mPayService
==
null
)
{
Intent
intent
=
new
Intent
(
"com.pax.cashier.SERVICE"
);
serviceConnection
=
new
ServiceConnection
()
{
@Override
public
void
onServiceConnected
(
ComponentName
name
,
IBinder
service
)
{
mPayService
=
PayService
.
Stub
.
asInterface
(
service
);
ToastUtils
.
showLong
(
"bind service success"
);
}
@Override
public
void
onServiceDisconnected
(
ComponentName
name
)
{
}
};
context
.
bindService
(
intent
,
serviceConnection
,
context
.
BIND_AUTO_CREATE
);
}
}
/**
* 交易状态查询
*
* @param orderAmt 交易金额
* @param origOrderNo
* @param transUniqueId
* @return
*/
public
static
Observable
<
Response
>
query
(
Long
orderAmt
,
String
origOrderNo
,
String
transUniqueId
)
{
IRequest
iRequest
=
IRequest
.
create
();
iRequest
.
setOrderNo
(
String
.
valueOf
(
NeptuneCenter
.
getInstance
().
mShopppp
.
getPosppp
().
getHposTrace
()));
if
(
orderAmt
>
0
)
{
iRequest
.
setTransAmount
(
orderAmt
+
""
);
}
if
(!
transUniqueId
.
equals
(
""
))
{
iRequest
.
setOrigTransUniqueID
(
transUniqueId
);
}
iRequest
.
setOrigOrderNo
(
origOrderNo
);
iRequest
.
setTransType
(
C
.
TRANS_TYPE
.
TRANS_STAUS_QUERY
);
return
run
(
Observable
.
just
(
iRequest
).
flatMap
(
iRequest1
->
{
while
(
mPayService
==
null
)
{
LogUtils
.
e
(
"PayService获取失败,"
+
C
.
RETRY_DELAY_TIME
+
"ms后尝试重连"
);
if
(
mRetry
<
C
.
RETRY_COUNT
)
{
Thread
.
sleep
(
C
.
RETRY_DELAY_TIME
);
}
else
{
return
Observable
.
just
(
new
IResponse
(
C
.
CODE
.
FAIL_CUSTOM
,
"初始化失败"
));
}
}
IResponse
iResponse
;
String
str
=
mPayService
.
doTrans
(
JSON
.
toJSONString
(
iRequest1
));
try
{
iResponse
=
JSON
.
parseObject
(
str
,
IResponse
.
class
);
}
catch
(
Exception
e
)
{
iResponse
=
new
IResponse
();
}
return
Observable
.
just
(
iResponse
);
}).
map
(
new
ResultFilter
()));
}
@Override
public
void
onServiceDisconnected
(
ComponentName
componentName
)
{
LogUtils
.
e
(
"Service Disconnected!"
);
/**
* 退款
*
* @param payChannel 支付渠道
* @param orderAmt 支付金额
* @return 交易结果
*/
public
static
Observable
<
Response
>
refund
(
int
payChannel
,
Long
orderAmt
)
{
IRequest
iRequest
=
IRequest
.
create
();
iRequest
.
setOrderNo
(
String
.
valueOf
(
NeptuneCenter
.
getInstance
().
mShopppp
.
getPosppp
().
getHposTrace
()));
iRequest
.
setTransType
(
C
.
TRANS_TYPE
.
REFUND
);
iRequest
.
setTransAmount
(
orderAmt
+
""
);
if
(
payChannel
==
com
.
xingdata
.
pay
.
neptune
.
C
.
PAY_CHANNEL
.
BANK
)
{
//银行卡退款
iRequest
.
setPayMode
(
com
.
xingdata
.
pay
.
neptune
.
ipc
.
C
.
PAY_MODE
.
UNIONPAY
);
}
else
{
//微信支付宝退款
iRequest
.
setPayMode
(
com
.
xingdata
.
pay
.
neptune
.
ipc
.
C
.
PAY_MODE
.
WECHAT
);
}
return
run
(
Observable
.
just
(
iRequest
).
flatMap
(
iRequest1
->
{
while
(
mPayService
==
null
)
{
LogUtils
.
e
(
"PayService获取失败,"
+
C
.
RETRY_DELAY_TIME
+
"ms后尝试重连"
);
if
(
mRetry
<
C
.
RETRY_COUNT
)
{
Thread
.
sleep
(
C
.
RETRY_DELAY_TIME
);
}
else
{
return
Observable
.
just
(
new
IResponse
(
C
.
CODE
.
FAIL_CUSTOM
,
"初始化失败"
));
}
}
IResponse
iResponse
;
String
str
=
mPayService
.
doTrans
(
JSON
.
toJSONString
(
iRequest1
));
try
{
iResponse
=
JSON
.
parseObject
(
str
,
IResponse
.
class
);
}
catch
(
Exception
e
)
{
iResponse
=
new
IResponse
();
}
};
final
Intent
i
=
new
Intent
();
i
.
setAction
(
"com.pax.cashier.PayService"
);
Intent
intent
=
new
Intent
(
createExplicitFromImplicitIntent
(
conqueryAndSputext
,
i
));
context
.
bindService
(
intent
,
conn
,
Service
.
BIND_AUTO_CREATE
);
return
Observable
.
just
(
iResponse
);
}).
map
(
new
ResultFilter
()));
}
/**
...
...
@@ -63,18 +136,18 @@ public class Factory {
*/
public
static
Observable
<
Response
>
pay
(
int
payChannel
,
Long
orderAmt
)
{
IRequest
iRequest
=
IRequest
.
create
();
iRequest
.
setTransType
(
C
.
TRANS_TYPE
.
SALE
);
iRequest
.
setOrderNo
(
String
.
valueOf
(
NeptuneCenter
.
getInstance
().
mShopppp
.
getPosppp
().
getHposTrace
()));
iRequest
.
setTransType
(
com
.
xingdata
.
pay
.
neptune
.
ipc
.
C
.
TRANS_TYPE
.
SALE
);
switch
(
payChannel
)
{
case
com
.
xingdata
.
pay
.
neptune
.
C
.
PAY_CHANNEL
.
ALI
:
iRequest
.
setPayMode
(
C
.
PAY_MODE
.
ALIPAY
);
//
iRequest.setPayMode(C.PAY_MODE.ALIPAY);
break
;
case
com
.
xingdata
.
pay
.
neptune
.
C
.
PAY_CHANNEL
.
WECHAT
:
iRequest
.
setPayMode
(
C
.
PAY_MODE
.
WECHAT
);
//
iRequest.setPayMode(C.PAY_MODE.WECHAT);
break
;
}
iRequest
.
setTransAmount
(
String
.
valueOf
(
orderAmt
));
iRequest
.
setOrderInfo
(
"测试信息,扫码消费"
+
String
.
valueOf
(
orderAmt
)
+
"分"
);
return
run
(
Observable
.
just
(
iRequest
).
flatMap
(
iRequest1
->
{
while
(
mPayService
==
null
)
{
LogUtils
.
e
(
"PayService获取失败,"
+
C
.
RETRY_DELAY_TIME
+
"ms后尝试重连"
);
...
...
@@ -85,9 +158,10 @@ public class Factory {
}
}
IResponse
iResponse
;
String
str
=
mPayService
.
doTrans
(
JSON
.
toJSONString
(
iRequest1
));
try
{
iResponse
=
JSON
.
parseObject
(
mPayService
.
doTrans
(
JSON
.
toJSONString
(
iRequest1
))
,
IResponse
.
class
);
}
catch
(
Remote
Exception
e
)
{
iResponse
=
JSON
.
parseObject
(
str
,
IResponse
.
class
);
}
catch
(
Exception
e
)
{
iResponse
=
new
IResponse
();
}
return
Observable
.
just
(
iResponse
);
...
...
@@ -100,29 +174,5 @@ public class Factory {
.
observeOn
(
AndroidSchedulers
.
mainThread
());
}
public
static
Intent
createExplicitFromImplicitIntent
(
Context
context
,
Intent
implicitIntent
)
{
// Retrieve all services that can match the given intent
PackageManager
pm
=
context
.
getPackageManager
();
List
<
ResolveInfo
>
resolveInfo
=
pm
.
queryIntentServices
(
implicitIntent
,
0
);
// Make sure only one match was found
if
(
resolveInfo
==
null
||
resolveInfo
.
size
()
!=
1
)
{
return
null
;
}
// Get component info and create ComponentName
ResolveInfo
serviceInfo
=
resolveInfo
.
get
(
0
);
String
packageName
=
serviceInfo
.
serviceInfo
.
packageName
;
String
className
=
serviceInfo
.
serviceInfo
.
name
;
ComponentName
component
=
new
ComponentName
(
packageName
,
className
);
// Create a new intent. Use the old one for extras and such reuse
Intent
explicitIntent
=
new
Intent
(
implicitIntent
);
// Set the component to be explicit
explicitIntent
.
setComponent
(
component
);
return
explicitIntent
;
}
}
neptune/src/main/java/com/xingdata/pay/neptune/ipc/IRequest.java
View file @
4426ab65
...
...
@@ -21,7 +21,7 @@ class IRequest {
*/
private
String
appName
;
/**
*
交易类型
*
收银台应用名称
*/
private
String
transType
;
/**
...
...
@@ -40,6 +40,14 @@ class IRequest {
* 原交易唯一标识
*/
private
String
transUniqueIDString
;
/**
* 原收银台交易唯一标识
*/
private
String
origTransUniqueID
;
private
String
orderInfo
;
private
String
origOrderNo
;
private
String
origOrderInfo
;
public
String
getAppId
()
{
return
appId
;
...
...
@@ -96,4 +104,36 @@ class IRequest {
public
void
setTransUniqueIDString
(
String
transUniqueIDString
)
{
this
.
transUniqueIDString
=
transUniqueIDString
;
}
public
String
getOrderInfo
()
{
return
orderInfo
;
}
public
void
setOrderInfo
(
String
orderInfo
)
{
this
.
orderInfo
=
orderInfo
;
}
public
String
getOrigOrderNo
()
{
return
origOrderNo
;
}
public
void
setOrigOrderNo
(
String
origOrderNo
)
{
this
.
origOrderNo
=
origOrderNo
;
}
public
String
getOrigOrderInfo
()
{
return
origOrderInfo
;
}
public
void
setOrigOrderInfo
(
String
origOrderInfo
)
{
this
.
origOrderInfo
=
origOrderInfo
;
}
public
String
getOrigTransUniqueID
()
{
return
origTransUniqueID
;
}
public
void
setOrigTransUniqueID
(
String
origTransUniqueID
)
{
this
.
origTransUniqueID
=
origTransUniqueID
;
}
}
neptune/src/main/java/com/xingdata/pay/neptune/ipc/ResultFilter.java
View file @
4426ab65
...
...
@@ -8,6 +8,13 @@ import io.reactivex.functions.Function;
class
ResultFilter
implements
Function
<
IResponse
,
Response
>
{
@Override
public
Response
apply
(
IResponse
iResponse
)
throws
Exception
{
return
null
;
int
code
;
if
(
iResponse
.
getRspCode
().
equals
(
"0"
))
{
code
=
1
;
}
else
{
code
=
Integer
.
parseInt
(
iResponse
.
getRspCode
());
}
Response
response
=
new
Response
(
code
,
iResponse
.
getRspMsg
());
return
response
;
}
}
\ No newline at end of file
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