Commit 02586e4a authored by zhang_z's avatar zhang_z

优化结构和流程;

parent cde96918
...@@ -67,11 +67,11 @@ public class C { ...@@ -67,11 +67,11 @@ public class C {
/** /**
* 渠道 * 渠道
*/ */
public static final class CHANNEL { public static final class HOST {
/** /**
* 惠尔丰平台的渠道编号 * 惠尔丰平台的渠道编号
*/ */
public final static int PAY_CHANNEL_PAX = 9; public final static int PAX = 10000;
} }
/** /**
......
...@@ -18,7 +18,6 @@ public class PayCenter { ...@@ -18,7 +18,6 @@ public class PayCenter {
return PayCenter.PayCenterHolder.INSTANCE; return PayCenter.PayCenterHolder.INSTANCE;
} }
/** /**
* 交易基本信息 * 交易基本信息
*/ */
...@@ -29,12 +28,34 @@ public class PayCenter { ...@@ -29,12 +28,34 @@ public class PayCenter {
return this; return this;
} }
/**
* 支付
*
* @param payChannel 支付渠道
* @param payCode 支付码
* @param orderAmt 金额
* @return 直接结果的Observable
*/
public Observable<Response> pay(int payChannel, String payCode, Long orderAmt) { public Observable<Response> pay(int payChannel, String payCode, Long orderAmt) {
switch (mShopppp.getHost().getHostMapId()) {
case C.HOST.PAX:
return Factory.pay(payChannel, payCode, Util.fenToYuan(orderAmt)); return Factory.pay(payChannel, payCode, Util.fenToYuan(orderAmt));
default:
return Observable.just(new Response(C.PAY_STATE.FAIL_CUSTOM, "未知渠道"));
} }
public Observable query() {
return Observable.just("");
} }
/**
* 查询
*
* @return 查询结果的Observable
*/
public Observable<Response> query() {
switch (mShopppp.getHost().getHostMapId()) {
case C.HOST.PAX:
return Factory.query();
default:
return Observable.just(new Response(C.PAY_STATE.FAIL_CUSTOM, "未知渠道"));
}
}
} }
...@@ -4,12 +4,24 @@ package com.xingdata.zxpay.api; ...@@ -4,12 +4,24 @@ package com.xingdata.zxpay.api;
* 和App主体交互的回应包 * 和App主体交互的回应包
*/ */
public class Response { public class Response {
public Response(String msg) {
public Response(int code, String msg) {
this.code = code;
this.msg = msg; this.msg = msg;
} }
private int code;
private String msg; private String msg;
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMsg() { public String getMsg() {
return msg; return msg;
} }
......
...@@ -26,10 +26,10 @@ public class Posppp { ...@@ -26,10 +26,10 @@ public class Posppp {
private Long casherId; private Long casherId;
private Integer hshopNo; private String hshopNo;
@Nullable @Nullable
private Integer hposNo; private String hposNo;
private Byte pppFlag; private Byte pppFlag;
...@@ -117,20 +117,20 @@ public class Posppp { ...@@ -117,20 +117,20 @@ public class Posppp {
this.casherId = casherId; this.casherId = casherId;
} }
public Integer getHshopNo() { public String getHshopNo() {
return hshopNo; return hshopNo;
} }
public void setHshopNo(Integer hshopNo) { public void setHshopNo(String hshopNo) {
this.hshopNo = hshopNo; this.hshopNo = hshopNo;
} }
@Nullable @Nullable
public Integer getHposNo() { public String getHposNo() {
return hposNo; return hposNo;
} }
public void setHposNo(@Nullable Integer hposNo) { public void setHposNo(@Nullable String hposNo) {
this.hposNo = hposNo; this.hposNo = hposNo;
} }
......
...@@ -25,7 +25,7 @@ public class Shopppp { ...@@ -25,7 +25,7 @@ public class Shopppp {
private String hshopNameabcn; private String hshopNameabcn;
@Nullable @Nullable
private Integer hshopNo; private String hshopNo;
private Byte pppFlag; private Byte pppFlag;
...@@ -118,11 +118,11 @@ public class Shopppp { ...@@ -118,11 +118,11 @@ public class Shopppp {
} }
@Nullable @Nullable
public Integer getHshopNo() { public String getHshopNo() {
return hshopNo; return hshopNo;
} }
public void setHshopNo(@Nullable Integer hshopNo) { public void setHshopNo(@Nullable String hshopNo) {
this.hshopNo = hshopNo; this.hshopNo = hshopNo;
} }
......
...@@ -10,6 +10,11 @@ class C { ...@@ -10,6 +10,11 @@ class C {
* 测试数据 * 测试数据
*/ */
class TEST { class TEST {
/**
* 测试URL
*/
final static String BASE_URL = "http://114.55.31.38:8008";
/** /**
* 机构号 * 机构号
*/ */
...@@ -33,8 +38,6 @@ class C { ...@@ -33,8 +38,6 @@ class C {
* 地址 * 地址
*/ */
class URL { class URL {
final static String BASE_URL = "http://114.55.31.38:8008";
final static String ACTION = "/tps/api/instrans"; final static String ACTION = "/tps/api/instrans";
} }
......
package com.xingdata.zxpay.pax; package com.xingdata.zxpay.pax;
import com.alibaba.fastjson.JSON; import android.util.SparseArray;
import com.blankj.utilcode.util.TimeUtils; import com.blankj.utilcode.util.TimeUtils;
import com.xingdata.zxpay.PayCenter; import com.xingdata.zxpay.PayCenter;
import com.xingdata.zxpay.api.Response;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Locale; import java.util.Locale;
...@@ -14,6 +14,7 @@ import io.reactivex.Observable; ...@@ -14,6 +14,7 @@ import io.reactivex.Observable;
public class Factory extends com.xingdata.zxpay.api.Factory { public class Factory extends com.xingdata.zxpay.api.Factory {
private static SimpleDateFormat format = new SimpleDateFormat("yyyymmddhhmmss", Locale.getDefault()); private static SimpleDateFormat format = new SimpleDateFormat("yyyymmddhhmmss", Locale.getDefault());
private static SparseArray<String> orderMap = new SparseArray<>();
/** /**
* 条码支付 * 条码支付
...@@ -42,17 +43,23 @@ public class Factory extends com.xingdata.zxpay.api.Factory { ...@@ -42,17 +43,23 @@ public class Factory extends com.xingdata.zxpay.api.Factory {
} }
request.sign(); request.sign();
return run(Api.getInstance().service.action(request)) return run(Api.getInstance().service.action(request))
.flatMap(response -> { .map(new ResultFilter())
return Observable.just(new Response(JSON.toJSONString(response))); .doFinally(() -> orderMap.put(request.getOutTransactionNo(), request.getTimeStart()));
});
} }
public static Observable query(String c, String d) { /**
* 查询
*
* @return 查询结果
*/
public static Observable<com.xingdata.zxpay.api.Response> query() {
Request request = Request.create(C.METHOD.QUERY); Request request = Request.create(C.METHOD.QUERY);
request.setAgentId(c); request.setOutTransactionNo(PayCenter.getInstance().mShopppp.getPosppp().getHposTrace());
request.setExpTime(d); request.setTimeStart(orderMap.get(request.getOutTransactionNo()));
return Api.getInstance().service.action(request); request.sign();
return run(Api.getInstance().service.action(request))
.map(new ResultFilter());
} }
......
...@@ -14,16 +14,9 @@ class Request { ...@@ -14,16 +14,9 @@ class Request {
this.signType = C.SIGN_TYPE.MD5; this.signType = C.SIGN_TYPE.MD5;
this.version = C.VERSION; this.version = C.VERSION;
// {//TODO 测试数据 this.agentId = PayCenter.getInstance().mShopppp.getHost().getHostAcqCode();
// this.agentId = C.TEST.AGENT_ID; this.mchId = PayCenter.getInstance().mShopppp.getPosppp().getHshopNo();
// this.mchId = C.TEST.MCH_ID; this.terId = PayCenter.getInstance().mShopppp.getPosppp().getHposNo();
// this.terId = C.TEST.TER_ID;
// }
{//TODO 正式数据
this.agentId = String.valueOf(PayCenter.getInstance().mShopppp.getHost().getHostAcqCode());
this.mchId = String.valueOf(PayCenter.getInstance().mShopppp.getHshopNo());
this.terId = String.valueOf(PayCenter.getInstance().mShopppp.getPosppp().getHposNo());
}
} }
/** /**
......
package com.xingdata.zxpay.pax;
import io.reactivex.functions.Function;
class ResultFilter implements Function<Response, com.xingdata.zxpay.api.Response> {
@Override
public com.xingdata.zxpay.api.Response apply(Response response) throws Exception {
switch (response.getCode()) {
case C.CODE.SUCCESS:
return new com.xingdata.zxpay.api.Response(com.xingdata.zxpay.C.PAY_STATE.SUCCESS, response.getMsg());
case C.CODE.USINGPAY:
case C.CODE.UNKONW:
return new com.xingdata.zxpay.api.Response(com.xingdata.zxpay.C.PAY_STATE.ING, response.getMsg());
default:
return new com.xingdata.zxpay.api.Response(com.xingdata.zxpay.C.PAY_STATE.FAIL, response.getMsg());
}
}
}
\ No newline at end of file
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