Commit 992b09bd authored by zhang_z's avatar zhang_z

支付module结构优化;

parent 57b9dc33
...@@ -3,7 +3,6 @@ package com.xingdata.zxpay.api; ...@@ -3,7 +3,6 @@ package com.xingdata.zxpay.api;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import com.xingdata.zxpay.C; import com.xingdata.zxpay.C;
import com.xingdata.zxpay.PayCenter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
...@@ -18,7 +17,7 @@ import okhttp3.logging.HttpLoggingInterceptor; ...@@ -18,7 +17,7 @@ import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit; import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
public class Api { public abstract class Api {
protected Retrofit retrofit; protected Retrofit retrofit;
protected Api() { protected Api() {
...@@ -61,8 +60,9 @@ public class Api { ...@@ -61,8 +60,9 @@ public class Api {
.client(okHttpClient) .client(okHttpClient)
.addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(ConverterFactory.create()) .addConverterFactory(ConverterFactory.create())
.baseUrl(PayCenter.getInstance().mShopppp.getHshopKeyUnipay()) .baseUrl(getBaseUrl())
.build(); .build();
} }
protected abstract String getBaseUrl();
} }
package com.xingdata.zxpay.api;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
public class Factory {
protected static <T> Observable<T> run(Observable<T> observable) {
return observable.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
}
...@@ -17,4 +17,9 @@ public class Api extends com.xingdata.zxpay.api.Api { ...@@ -17,4 +17,9 @@ public class Api extends com.xingdata.zxpay.api.Api {
super(); super();
service = retrofit.create(Service.class); service = retrofit.create(Service.class);
} }
@Override
protected String getBaseUrl() {
return C.BASE_URL;
}
} }
...@@ -2,7 +2,9 @@ package com.xingdata.zxpay.pax; ...@@ -2,7 +2,9 @@ package com.xingdata.zxpay.pax;
class C { class C {
final static String URL = "/tps/api/instrans"; final static String BASE_URL = "http://114.55.31.38:8008";
final static String ACTION = "/tps/api/instrans";
/** /**
* 当前交易成功 * 当前交易成功
......
...@@ -5,16 +5,15 @@ import com.alibaba.fastjson.JSON; ...@@ -5,16 +5,15 @@ import com.alibaba.fastjson.JSON;
import com.xingdata.zxpay.api.Response; import com.xingdata.zxpay.api.Response;
import io.reactivex.Observable; import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
public class Factory { public class Factory extends com.xingdata.zxpay.api.Factory {
public static Observable<com.xingdata.zxpay.api.Response> pay(String a, String b) { public static Observable<com.xingdata.zxpay.api.Response> pay(String a, String b) {
Request request = new Request(); Request request = new Request();
request.setReserved(a); request.setReserved(a);
request.setMethod(b); request.setMethod(b);
return run(Api.getInstance().service.query(request))
return run(Api.getInstance().service.action(request))
.flatMap(response -> Observable.just(new Response(JSON.toJSONString(response)))); .flatMap(response -> Observable.just(new Response(JSON.toJSONString(response))));
} }
...@@ -22,13 +21,8 @@ public class Factory { ...@@ -22,13 +21,8 @@ public class Factory {
Request request = new Request(); Request request = new Request();
request.setAgentId(c); request.setAgentId(c);
request.setExpTime(d); request.setExpTime(d);
return Api.getInstance().service.query(request); return Api.getInstance().service.action(request);
} }
static <T> Observable<T> run(Observable<T> observable) {
return observable.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
} }
...@@ -6,6 +6,6 @@ import retrofit2.http.POST; ...@@ -6,6 +6,6 @@ import retrofit2.http.POST;
public interface Service { public interface Service {
@POST(C.URL) @POST(C.ACTION)
Observable<Response> query(@Body com.xingdata.zxpay.pax.Request request); Observable<Response> action(@Body com.xingdata.zxpay.pax.Request request);
} }
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