Commit 4eae0d7d authored by zhang_z's avatar zhang_z

Merge branch 'master' of 192.168.254.154:w525721508/TangKuPos

parents 06a9cf74 267a1186
...@@ -79,7 +79,7 @@ public class C { ...@@ -79,7 +79,7 @@ public class C {
/** /**
* 地址 * 地址
*/ */
public static final String BASE_URL = URL_DEMO; public static final String BASE_URL = URL_TEST;
private static final String PKG = "/tk/"; private static final String PKG = "/tk/";
......
...@@ -3,10 +3,8 @@ package com.xingdata.pay.neptune; ...@@ -3,10 +3,8 @@ package com.xingdata.pay.neptune;
import android.content.Context; import android.content.Context;
import com.alibaba.fastjson.JSON;
import com.blankj.utilcode.util.LogUtils; import com.blankj.utilcode.util.LogUtils;
import com.xingdata.pay.neptune.ipc.Factory; import com.xingdata.pay.neptune.ipc.Factory;
import com.xingdata.pay.neptune.model.Shopppp;
import io.reactivex.Observable; import io.reactivex.Observable;
...@@ -18,28 +16,27 @@ public class NeptuneCenter { ...@@ -18,28 +16,27 @@ public class NeptuneCenter {
/** /**
* 交易基本信息 * 交易基本信息
*/ */
public Shopppp mShopppp;
public static NeptuneCenter getInstance() { public static NeptuneCenter getInstance() {
return NeptuneCenter.NeptuneCenterHolder.INSTANCE; return NeptuneCenter.NeptuneCenterHolder.INSTANCE;
} }
public NeptuneCenter init(Context context, String json) { public NeptuneCenter init(Context context) {
LogUtils.e("初始化NeptuneCenter"); LogUtils.e("初始化NeptuneCenter");
Factory.getInstance().init(context); Factory.getInstance().init(context);
mShopppp = JSON.parseObject(json, Shopppp.class);
return this; return this;
} }
/** /**
* 支付 * 支付
* *
* @param orderNo 订单号
* @param payChannel 支付渠道 * @param payChannel 支付渠道
* @param orderAmt 金额 * @param orderAmt 金额
* @return 支付结果的Observable * @return 支付结果的Observable
*/ */
public Observable<Response> pay(int payChannel, Long orderAmt) { public Observable<Response> pay(String orderNo, int payChannel, Long orderAmt) {
return Factory.pay(payChannel, orderAmt); return Factory.pay(orderNo, payChannel, orderAmt);
} }
/** /**
...@@ -47,10 +44,10 @@ public class NeptuneCenter { ...@@ -47,10 +44,10 @@ public class NeptuneCenter {
* *
* @param payChannel 支付渠道 * @param payChannel 支付渠道
* @param orderAmt 金额 * @param orderAmt 金额
* @return 支付结果的Observable * @return 退款结果的Observable
*/ */
public Observable<Response> refund(int payChannel, Long orderAmt) { public Observable<Response> refund(String orderNo, int payChannel, Long orderAmt) {
return Factory.refund(payChannel, orderAmt); return Factory.refund(orderNo, payChannel, orderAmt);
} }
/** /**
...@@ -59,10 +56,10 @@ public class NeptuneCenter { ...@@ -59,10 +56,10 @@ public class NeptuneCenter {
* @param orderAmt 原交易金额,为null则不参与查询 * @param orderAmt 原交易金额,为null则不参与查询
* @param origOrderNo 原订单号 * @param origOrderNo 原订单号
* @param transUniqueId 原交易流水号, 为null则不参与查询 * @param transUniqueId 原交易流水号, 为null则不参与查询
* @return * @return 查询结果的Observable
*/ */
public Observable<Response> query(Long orderAmt, String origOrderNo, String transUniqueId) { public Observable<Response> query(String orderNo, Long orderAmt, String origOrderNo, String transUniqueId) {
return Factory.query(orderAmt, origOrderNo, transUniqueId); return Factory.query(orderNo, orderAmt, origOrderNo, transUniqueId);
} }
} }
......
...@@ -34,7 +34,7 @@ public class C { ...@@ -34,7 +34,7 @@ public class C {
/** /**
* 银联支付 * 银联支付
*/ */
final static String UNIONPAY = "UNIONPAY"; final static String UNIONPAY = "CHANPAY";
/** /**
* 微信支付 * 微信支付
*/ */
......
...@@ -5,12 +5,12 @@ import android.content.Context; ...@@ -5,12 +5,12 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.ServiceConnection; import android.content.ServiceConnection;
import android.os.IBinder; import android.os.IBinder;
import android.os.RemoteException;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.blankj.utilcode.util.LogUtils; import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.ToastUtils; import com.blankj.utilcode.util.ToastUtils;
import com.pax.pay.service.aidl.PayService; import com.pax.pay.service.aidl.PayService;
import com.xingdata.pay.neptune.NeptuneCenter;
import com.xingdata.pay.neptune.Response; import com.xingdata.pay.neptune.Response;
import io.reactivex.Observable; import io.reactivex.Observable;
...@@ -19,14 +19,12 @@ import io.reactivex.schedulers.Schedulers; ...@@ -19,14 +19,12 @@ import io.reactivex.schedulers.Schedulers;
public class Factory { public class Factory {
private static PayService mPayService; private static PayService mPayService;
private static ServiceConnection serviceConnection; private static int mRetry;
private static class FactoryHolder { private static class FactoryHolder {
private static final Factory INSTANCE = new Factory(); private static final Factory INSTANCE = new Factory();
} }
private static int mRetry;
public static Factory getInstance() { public static Factory getInstance() {
return Factory.FactoryHolder.INSTANCE; return Factory.FactoryHolder.INSTANCE;
} }
...@@ -34,7 +32,7 @@ public class Factory { ...@@ -34,7 +32,7 @@ public class Factory {
public void init(Context context) { public void init(Context context) {
if (mPayService == null) { if (mPayService == null) {
Intent intent = new Intent("com.pax.cashier.SERVICE"); Intent intent = new Intent("com.pax.cashier.SERVICE");
serviceConnection = new ServiceConnection() { ServiceConnection serviceConnection = new ServiceConnection() {
@Override @Override
public void onServiceConnected(ComponentName name, IBinder service) { public void onServiceConnected(ComponentName name, IBinder service) {
mPayService = PayService.Stub.asInterface(service); mPayService = PayService.Stub.asInterface(service);
...@@ -46,7 +44,7 @@ public class Factory { ...@@ -46,7 +44,7 @@ public class Factory {
} }
}; };
context.bindService(intent, serviceConnection, context.BIND_AUTO_CREATE); context.bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
} }
} }
...@@ -54,13 +52,14 @@ public class Factory { ...@@ -54,13 +52,14 @@ public class Factory {
* 交易状态查询 * 交易状态查询
* *
* @param orderAmt 交易金额 * @param orderAmt 交易金额
* @param origOrderNo * @param origOrderNo 原订单号
* @param transUniqueId * @param transUniqueId
* @return * @return 查询结果
*/ */
public static Observable<Response> query(Long orderAmt, String origOrderNo, String transUniqueId) { public static Observable<Response> query(String orderNo, Long orderAmt, String origOrderNo, String transUniqueId) {
mRetry = 0;
IRequest iRequest = IRequest.create(); IRequest iRequest = IRequest.create();
iRequest.setOrderNo(String.valueOf(NeptuneCenter.getInstance().mShopppp.getPosppp().getHposTrace())); iRequest.setOrderNo(orderNo);
if (orderAmt > 0) { if (orderAmt > 0) {
iRequest.setTransAmount(orderAmt + ""); iRequest.setTransAmount(orderAmt + "");
} }
...@@ -97,18 +96,102 @@ public class Factory { ...@@ -97,18 +96,102 @@ public class Factory {
* @return 交易结果 * @return 交易结果
*/ */
public static Observable<Response> refund(int payChannel, Long orderAmt) { // public static Observable<Response> refund(String orderNo, int payChannel, Long orderAmt) {
// mRetry = 0;
// IRequest iRequest = IRequest.create();
// orderNo="180418192206048340";
// iRequest.setOrderNo(orderNo);
// 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 if (payChannel == com.xingdata.pay.neptune.C.PAY_CHANNEL.WECHAT) {
// //微信退款
// iRequest.setPayMode(com.xingdata.pay.neptune.ipc.C.PAY_MODE.WECHAT);
// } else if (payChannel == com.xingdata.pay.neptune.C.PAY_CHANNEL.ALI) {
// //支付宝退款
// iRequest.setPayMode(com.xingdata.pay.neptune.ipc.C.PAY_MODE.ALIPAY);
// }
// 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()));
// }
/**
* @param payChannel 支付渠道
* @param orderAmt 支付金额
* @return 交易结果
*/
public static Observable<Response> refund(String orderNo, int payChannel, Long orderAmt) {
mRetry = 0;
IRequest iRequest = IRequest.create(); IRequest iRequest = IRequest.create();
iRequest.setOrderNo(String.valueOf(NeptuneCenter.getInstance().mShopppp.getPosppp().getHposTrace())); orderNo = "180418192206048340";
iRequest.setOrderNo(orderNo);
iRequest.setTransType(C.TRANS_TYPE.REFUND); iRequest.setTransType(C.TRANS_TYPE.REFUND);
iRequest.setTransAmount(orderAmt + ""); iRequest.setTransAmount(String.valueOf(orderAmt));
if (payChannel == com.xingdata.pay.neptune.C.PAY_CHANNEL.BANK) { iRequest.setOrderInfo("测试信息,扫码消费" + String.valueOf(orderAmt) + "分");
//银行卡退款
iRequest.setPayMode(com.xingdata.pay.neptune.ipc.C.PAY_MODE.UNIONPAY);
} else { switch (payChannel) {
//微信支付宝退款 case com.xingdata.pay.neptune.C.PAY_CHANNEL.ALI: {
iRequest.setPayMode(com.xingdata.pay.neptune.ipc.C.PAY_MODE.WECHAT); iRequest.setPayMode(com.xingdata.pay.neptune.ipc.C.PAY_MODE.ALIPAY);
}
break;
case com.xingdata.pay.neptune.C.PAY_CHANNEL.WECHAT: {
iRequest.setPayMode(com.xingdata.pay.neptune.ipc.C.PAY_MODE.WECHAT);
}
break;
case com.xingdata.pay.neptune.C.PAY_CHANNEL.BANK: {
iRequest.setPayMode(com.xingdata.pay.neptune.ipc.C.PAY_MODE.UNIONPAY);
}
break;
} }
new Thread(new Runnable() {
@Override
public void run() {
while (mPayService == null) {
LogUtils.e("PayService获取失败," + C.RETRY_DELAY_TIME + "ms后尝试重连");
if (mRetry < C.RETRY_COUNT) {
try {
Thread.sleep(C.RETRY_DELAY_TIME);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
IResponse iResponse;
String str = null;
try {
str = mPayService.doTrans(JSON.toJSONString(iRequest));
} catch (RemoteException e) {
e.printStackTrace();
}
try {
iResponse = JSON.parseObject(str, IResponse.class);
} catch (Exception e) {
iResponse = new IResponse();
}
}
}).start();
return run(Observable.just(iRequest).flatMap(iRequest1 -> { return run(Observable.just(iRequest).flatMap(iRequest1 -> {
while (mPayService == null) { while (mPayService == null) {
LogUtils.e("PayService获取失败," + C.RETRY_DELAY_TIME + "ms后尝试重连"); LogUtils.e("PayService获取失败," + C.RETRY_DELAY_TIME + "ms后尝试重连");
...@@ -129,25 +212,36 @@ public class Factory { ...@@ -129,25 +212,36 @@ public class Factory {
}).map(new ResultFilter())); }).map(new ResultFilter()));
} }
/** /**
* @param payChannel 支付渠道 * @param payChannel 支付渠道
* @param orderAmt 支付金额 * @param orderAmt 支付金额
* @return 交易结果 * @return 交易结果
*/ */
public static Observable<Response> pay(int payChannel, Long orderAmt) { public static Observable<Response> pay(String orderNo, int payChannel, Long orderAmt) {
mRetry = 0;
IRequest iRequest = IRequest.create(); IRequest iRequest = IRequest.create();
iRequest.setOrderNo(String.valueOf(NeptuneCenter.getInstance().mShopppp.getPosppp().getHposTrace())); iRequest.setOrderNo(orderNo);
iRequest.setTransType(com.xingdata.pay.neptune.ipc.C.TRANS_TYPE.SALE); 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);
break;
case com.xingdata.pay.neptune.C.PAY_CHANNEL.WECHAT:
// iRequest.setPayMode(C.PAY_MODE.WECHAT);
break;
}
iRequest.setTransAmount(String.valueOf(orderAmt)); iRequest.setTransAmount(String.valueOf(orderAmt));
iRequest.setOrderInfo("测试信息,扫码消费" + String.valueOf(orderAmt) + "分"); iRequest.setOrderInfo("测试信息,扫码消费" + String.valueOf(orderAmt) + "分");
switch (payChannel) {
case com.xingdata.pay.neptune.C.PAY_CHANNEL.ALI: {
iRequest.setPayMode(com.xingdata.pay.neptune.ipc.C.PAY_MODE.ALIPAY);
}
break;
case com.xingdata.pay.neptune.C.PAY_CHANNEL.WECHAT: {
iRequest.setPayMode(com.xingdata.pay.neptune.ipc.C.PAY_MODE.WECHAT);
}
break;
case com.xingdata.pay.neptune.C.PAY_CHANNEL.BANK: {
iRequest.setPayMode(com.xingdata.pay.neptune.ipc.C.PAY_MODE.UNIONPAY);
}
break;
}
return run(Observable.just(iRequest).flatMap(iRequest1 -> { return run(Observable.just(iRequest).flatMap(iRequest1 -> {
while (mPayService == null) { while (mPayService == null) {
LogUtils.e("PayService获取失败," + C.RETRY_DELAY_TIME + "ms后尝试重连"); LogUtils.e("PayService获取失败," + C.RETRY_DELAY_TIME + "ms后尝试重连");
...@@ -169,7 +263,7 @@ public class Factory { ...@@ -169,7 +263,7 @@ public class Factory {
} }
public static <T> Observable<T> run(Observable<T> observable) { private static <T> Observable<T> run(Observable<T> observable) {
return observable.subscribeOn(Schedulers.io()) return observable.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()); .observeOn(AndroidSchedulers.mainThread());
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment