package com.hanghui.senic.model; import android.util.Log; import com.hanghui.senic.MyAppliction; import com.hanghui.senic.R; import com.hanghui.senic.bean.AlipayUserInfoBean; import com.hanghui.senic.bean.DecryptBean; import com.hanghui.senic.common.AppHandler; import com.hanghui.senic.common.EncryptionAndDecryptionUtil; import com.hanghui.senic.common.ThreadPoolManager; import com.hanghui.senic.network.Url; import com.hanghui.senic.network.retorfit.AnonymousRetrofitUtil; import com.hanghui.senic.network.retorfit.FederatedPlatformsRetrofitUtil; import com.hanghui.senic.network.retorfit.FederatedPlatformsVerifyRetrofitUtil; import com.hanghui.senic.network.retorfit.MerchantPlatformRetrofitUtil; import com.hanghui.senic.network.retorfit.SpecialCodeTradeThreeElementsRetrofitUtil; import com.hanghui.senic.service.usbserialdemo.utile.ConfigManager; import com.hanghui.senic.bean.AuthenticationBean; import com.hanghui.senic.bean.FederatedPlatformsRequestBean; import com.hanghui.senic.service.usbserialdemo.utile.BeanMapUtilByJson; import com.hanghui.senic.network.retorfit.RetrofitUtil; import com.hanghui.senic.service.usbserialdemo.utile.loacat.AppLogUtils; import com.hanghui.senic.service.usbserialdemo.utile.Api; import java.util.Map; import cn.hutool.http.Header; import cn.hutool.http.HttpRequest; import okhttp3.ResponseBody; import rx.Subscriber; import rx.android.schedulers.AndroidSchedulers; import rx.schedulers.Schedulers; /** * 作者:今夕何夕 * 时间:${data} * Description:这个是注释 */ public class MyModel { //认证信息 public void Authentication(Map map, MyCallback callBreak) { Api api = RetrofitUtil.getUtil().gets(Api.class); String url = MyAppliction.getContext().getResources().getString(R.string.url_test_default) + MyAppliction.getContext().getResources().getString(R.string.url_HHLocalConfig); api.Post(MyAppliction.getContext().getResources().getString(R.string.url_HHLocalConfig), map) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Subscriber() { @Override public void onCompleted() { } @Override public void onError(Throwable e) { try { AuthenticationBean bean = new AuthenticationBean(); bean.setCode(500); callBreak.doAfterResponse(bean); } catch (Exception exception) { exception.printStackTrace(); } } @Override public void onNext(ResponseBody responseBody) { try { String json = responseBody.string(); AuthenticationBean bean = ConfigManager.getGson().fromJson(json, AuthenticationBean.class); callBreak.doAfterResponse(bean); } catch (Exception e) { AppLogUtils.e(true, " 认证信息接口 - Authentication", "打印错误信息 " + e.toString()); AuthenticationBean bean = new AuthenticationBean(); bean.setCode(500); callBreak.doAfterResponse(bean); e.printStackTrace(); } } }); } //请求商户平台去申请三要素 public void getThirdPartyPlatforms(Map map, MyCallback callBreak) { Api api = MerchantPlatformRetrofitUtil.getUtil().gets(Api.class); api.Post1(Url.URL_ACQUISITIONTHREEELEMENTS, map) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Subscriber() { @Override public void onCompleted() { } @Override public void onError(Throwable e) { AppLogUtils.e(true, " 换取三要素接口 - getThirdPartyPlatforms", e.toString()); AlipayUserInfoBean alipayUserInfoBean = new AlipayUserInfoBean(); alipayUserInfoBean.setErrcode("500"); if (e.toString().contains("returned null")) { alipayUserInfoBean.setErrmsg(ConfigManager.getAuthenticationBean().getData().get(0).getTenantTimeoutTips()); alipayUserInfoBean.setOpenVoiceMsg(ConfigManager.getAuthenticationBean().getData().get(0).getTenantTimeoutTips()); } else { alipayUserInfoBean.setErrmsg(ConfigManager.getAuthenticationBean().getData().get(0).getTenantFailedTips()); alipayUserInfoBean.setOpenVoiceMsg(ConfigManager.getAuthenticationBean().getData().get(0).getTenantFailedTips()); } callBreak.doAfterResponse(ConfigManager.getGson().toJson(alipayUserInfoBean)); } @Override public void onNext(ResponseBody responseBody) { try { String json = responseBody.string(); callBreak.doAfterResponse(json); } catch (Exception e) { AppLogUtils.e(true, " 换取三要素接口 - getThirdPartyPlatforms", "打印错误信息 " + e.toString()); AlipayUserInfoBean alipayUserInfoBean = new AlipayUserInfoBean(); alipayUserInfoBean.setErrcode("500"); alipayUserInfoBean.setErrmsg(ConfigManager.getAuthenticationBean().getData().get(0).getTenantFailedTips()); alipayUserInfoBean.setOpenVoiceMsg(ConfigManager.getAuthenticationBean().getData().get(0).getTenantFailedTips()); callBreak.doAfterResponse(ConfigManager.getGson().toJson(alipayUserInfoBean)); e.printStackTrace(); } } }); } //最终结果返回 public void getFederatedPlatforms(Map map, MyCallback callBreak) { Api api = FederatedPlatformsRetrofitUtil.getUtil().gets(Api.class); api.federatedPlatformsPost(Url.URL_FEDERATEDPLATFORMS, map) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Subscriber() { @Override public void onCompleted() { } @Override public void onError(Throwable e) { AppLogUtils.w(true, "通用模式核验接口返回错误", "报错内容:" + e.toString()); String data = ""; if (e.toString().contains("returned null")) { data = "{\"code\":500,\"msg\":\"" + ConfigManager.getAuthenticationBean().getData().get(0).getCheckVerifyTimeoutTips() + "\",\"data\":null}"; } else { //可能是核验接口地址配置错误导致请求发不出去,也可能是网络错误导致请求发不出去 // boolean networkStatus = ConfigManager.isNetworkConnected(MyAppliction.getContext()); // if (!networkStatus) { // data = "{\"code\":500,\"msg\":\"网络异常\",\"data\":null}"; // } else { // data = "{\"code\":500,\"msg\":\"核验接口请求失败\",\"data\":null}"; // } data = "{\"code\":500,\"msg\":\"" + ConfigManager.getAuthenticationBean().getData().get(0).getCheckVerifyFailedTips() + "\",\"data\":null}"; } callBreak.doAfterResponse(data); } @Override public void onNext(ResponseBody responseBody) { try { String json = responseBody.string(); callBreak.doAfterResponse(json); } catch (Exception e) { AppLogUtils.w(true, " 通用模式核验接口返回 - getFederatedPlatforms", "打印错误信息 " + e.toString()); String data = "{\"code\":500,\"msg\":\"" + ConfigManager.getAuthenticationBean().getData().get(0).getCheckVerifyFailedTips() + "\",\"data\":null}"; callBreak.doAfterResponse(data); e.printStackTrace(); } } }); } //最终结果返回 public void getFederatedPlatformsCheck(Map map, MyCallback callBreak) { Api api = FederatedPlatformsRetrofitUtil.getUtil().gets(Api.class); api.federatedPlatformsPost(Url.URL_FEDERATEDPLATFORMS, map) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Subscriber() { @Override public void onCompleted() { } @Override public void onError(Throwable e) { AppLogUtils.w(true, "预检查核验接口返回错误", "报错内容:" + e.toString()); String data = ""; if (e.toString().contains("returned null")) { data = "{\"code\":500,\"msg\":\"" + ConfigManager.getAuthenticationBean().getData().get(0).getCheckVerifyTimeoutTips() + "\",\"data\":null}"; } else { //可能是核验接口地址配置错误导致请求发不出去,也可能是网络错误导致请求发不出去 // boolean networkStatus = ConfigManager.isNetworkConnected(MyAppliction.getContext()); // if (!networkStatus) { // data = "{\"code\":500,\"msg\":\"网络异常\",\"data\":null}"; // } else { // data = "{\"code\":500,\"msg\":\"核验接口请求失败\",\"data\":null}"; // } data = "{\"code\":500,\"msg\":\"" + ConfigManager.getAuthenticationBean().getData().get(0).getCheckVerifyFailedTips() + "\",\"data\":null}"; } callBreak.doAfterResponse(data); } @Override public void onNext(ResponseBody responseBody) { try { String json = responseBody.string(); callBreak.doAfterResponse(json); } catch (Exception e) { AppLogUtils.w(true, " 核验接口返回 - getFederatedPlatforms", "打印错误信息 " + e.toString()); String data = "{\"code\":500,\"msg\":\"" + ConfigManager.getAuthenticationBean().getData().get(0).getCheckVerifyFailedTips() + "\",\"data\":null}"; callBreak.doAfterResponse(data); e.printStackTrace(); } } }); } public void getFederatedPlatformsVerify(Map map, MyCallback callBreak) { Api api = FederatedPlatformsVerifyRetrofitUtil.getUtil().gets(Api.class); api.federatedPlatformsPost(Url.URL_FEDERATEDPLATFORMS, map) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Subscriber() { @Override public void onCompleted() { } @Override public void onError(Throwable e) { AppLogUtils.w(true, "", "请求超时" + e.toString()); String data = ""; if (e.toString().contains("returned null")) { data = "{\"code\":500,\"msg\":\"" + ConfigManager.getAuthenticationBean().getData().get(0).getCheckVerifyTimeoutTips() + "\",\"data\":null}"; } else { //可能是核验接口地址配置错误导致请求发不出去,也可能是网络错误导致请求发不出去 // boolean networkStatus = ConfigManager.isNetworkConnected(MyAppliction.getContext()); // if (!networkStatus) { // data = "{\"code\":500,\"msg\":\"网络异常\",\"data\":null}"; // } else { // data = "{\"code\":500,\"msg\":\"核验接口请求失败\",\"data\":null}"; // } data = "{\"code\":500,\"msg\":\"" + ConfigManager.getAuthenticationBean().getData().get(0).getCheckVerifyFailedTips() + "\",\"data\":null}"; } callBreak.doAfterResponse(data); } @Override public void onNext(ResponseBody responseBody) { try { String json = responseBody.string(); callBreak.doAfterResponse(json); } catch (Exception e) { AppLogUtils.w(true, " 核验接口返回 - getFederatedPlatforms", "打印错误信息 " + e.toString()); String data = "{\"code\":500,\"msg\":\"" + ConfigManager.getAuthenticationBean().getData().get(0).getCheckVerifyFailedTips() + "\",\"data\":null}"; callBreak.doAfterResponse(data); e.printStackTrace(); } } }); } //参数配置 public void SetParameterConfiguration(Map map, String url, MyCallback callBreak) { Api api = RetrofitUtil.getUtil().gets(Api.class); url = url + MyAppliction.getContext().getResources().getString(R.string.url_config_path); api.Post1(url, map) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Subscriber() { @Override public void onCompleted() { } @Override public void onError(Throwable e) { String json = "ConfigError"; callBreak.doAfterResponse(json); } @Override public void onNext(ResponseBody responseBody) { try { String json = responseBody.string(); callBreak.doAfterResponse(json); } catch (Exception e) { AppLogUtils.w(true, " 参数配置接口 - SetParameterConfiguration", "打印错误信息 " + e.toString()); String json = "ConfigError"; callBreak.doAfterResponse(json); e.printStackTrace(); } } }); } //设备记录上报 public void SetEventRecords(Map map, String Url, MyCallback callBreak) { Api api = RetrofitUtil.getUtil().gets(Api.class); api.Post1(Url, map) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Subscriber() { @Override public void onCompleted() { } @Override public void onError(Throwable e) { // LogUtils.e(e.toString()); AppLogUtils.w(true, " 设备记录上报接口 - SetEventRecords", "打印错误信息 " + e.toString()); } @Override public void onNext(ResponseBody responseBody) { try { String json = responseBody.string(); callBreak.doAfterResponse(json); } catch (Exception e) { AppLogUtils.w(true, " 设备记录上报接口 - SetEventRecords", "打印错误信息 " + e.toString()); e.printStackTrace(); } } }); } //设备状态上报 public void SetDeviceStateReport(Map map, String Url, MyCallback callBreak) { Api api = RetrofitUtil.getUtil().gets(Api.class); api.Post1(Url, map) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Subscriber() { @Override public void onCompleted() { } @Override public void onError(Throwable e) { // LogUtils.e(e.toString()); AppLogUtils.e(false, " 设备状态上报接口 - SetDeviceStateReport", "打印错误信息 " + e.toString()); } @Override public void onNext(ResponseBody responseBody) { MyAppliction.setAppHeartbeatTime(System.currentTimeMillis()); try { String json = responseBody.string(); callBreak.doAfterResponse(json); } catch (Exception e) { AppLogUtils.w(true, " 设备状态上报接口 - SetDeviceStateReport", "打印错误信息 " + e.toString()); e.printStackTrace(); } } }); } //日志上传 public void PPushDoorSignal(Map map, String Url, MyCallback callBreak) { Api api = RetrofitUtil.getUtil().gets(Api.class); api.Post1(Url, map) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Subscriber() { @Override public void onCompleted() { } @Override public void onError(Throwable e) { // LogUtils.e(e.toString()); } @Override public void onNext(ResponseBody responseBody) { try { String json = responseBody.string(); callBreak.doAfterResponse(json); } catch (Exception e) { Log.e("打印错误信息 ", e.toString()); e.printStackTrace(); } } }); } //用户入库 public void PUserwithftoken(Map map, String Url, MyCallback callBreak) { Api api = AnonymousRetrofitUtil.getUtil().gets(Api.class); api.Post1(Url, map) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Subscriber() { @Override public void onCompleted() { } @Override public void onError(Throwable e) { // LogUtils.e(e.toString()); } @Override public void onNext(ResponseBody responseBody) { try { String json = responseBody.string(); callBreak.doAfterResponse(json); } catch (Exception e) { Log.e("打印错误信息 ", e.toString()); e.printStackTrace(); } } }); } //常口换取三要素 public void PThreeElements(Map map, String Url, MyCallback callBreak) { Api api = RetrofitUtil.getUtil().gets(Api.class); api.Post1(Url, map) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Subscriber() { @Override public void onCompleted() { } @Override public void onError(Throwable e) { // LogUtils.e(e.toString()); } @Override public void onNext(ResponseBody responseBody) { try { String json = responseBody.string(); callBreak.doAfterResponse(json); } catch (Exception e) { Log.e("打印错误信息 ", e.toString()); e.printStackTrace(); } } }); } //推送门磁信号 public void SetPushDoorSignal(Map map, String Url, MyCallback callBreak) { Api api = RetrofitUtil.getUtil().gets(Api.class); api.Post1(Url, map) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Subscriber() { @Override public void onCompleted() { } @Override public void onError(Throwable e) { // LogUtils.e(e.toString()); } @Override public void onNext(ResponseBody responseBody) { try { String json = responseBody.string(); callBreak.doAfterResponse(json); } catch (Exception e) { AppLogUtils.w(true, "SetPushDoorSignal打印错误信息 ", e.toString()); e.printStackTrace(); } } }); } //特殊码换取三要素 public void setSpecialCodeTradeThreeElements(Map map, String Url, MyCallback callBreak) { Api api = SpecialCodeTradeThreeElementsRetrofitUtil.getUtil().gets(Api.class); api.federatedPlatformsPost(Url, map) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Subscriber() { @Override public void onCompleted() { } @Override public void onError(Throwable e) { AppLogUtils.w(true, "", "请求超时" + e.toString()); String data = ""; if (e.toString().contains("returned null")) { data = "{\"code\":500,\"msg\":\"" + ConfigManager.getAuthenticationBean().getData().get(0).getSpecialCodeTimeoutTips() + "\",\"data\":null}"; } else { //可能是特殊码换取三要素地址配置错误导致请求发不出去,也可能是网络错误导致请求发不出去 data = "{\"code\":500,\"msg\":\"" + ConfigManager.getAuthenticationBean().getData().get(0).getSpecialCodeFailedTips() + "\",\"data\":null}"; } callBreak.doAfterResponse(data); } @Override public void onNext(ResponseBody responseBody) { try { String json = responseBody.string(); callBreak.doAfterResponse(json); } catch (Exception e) { AppLogUtils.w(true, " 特殊码换取三要素 - setSpecialCodeTradeThreeElements", "打印错误信息 " + e.toString()); String data = "{\"code\":500,\"msg\":\"" + ConfigManager.getAuthenticationBean().getData().get(0).getSpecialCodeFailedTips() + "\",\"data\":null}"; callBreak.doAfterResponse(data); e.printStackTrace(); } } }); } //本地黑名单配置 public void setLocalBlacklistConfig(Map map,String url ,MyCallback callBreak) { Api api = RetrofitUtil.getUtil().gets(Api.class); api.federatedPlatformsPost(url, map) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Subscriber() { @Override public void onCompleted() { } @Override public void onError(Throwable e) { AppLogUtils.w(true, "", "请求超时" + e.toString()); String data = ""; if (e.toString().contains("returned null")) { data = "{\"code\":500,\"msg\":\"黑名单配置获取失败\",\"data\":null}"; } else { //可能是特殊码换取三要素地址配置错误导致请求发不出去,也可能是网络错误导致请求发不出去 data = "{\"code\":500,\"msg\":\"黑名单配置获取失败\",\"data\":null}"; } callBreak.doAfterResponse(data); } @Override public void onNext(ResponseBody responseBody) { try { String json = responseBody.string(); callBreak.doAfterResponse(json); } catch (Exception e) { AppLogUtils.w(true, " 本地黑名单配置获取失败 - setLocalBlacklistConfig", "打印错误信息 " + e.toString()); String data = "{\"code\":500,\"msg\":\"黑名单配置获取失败\",\"data\":null}"; callBreak.doAfterResponse(data); e.printStackTrace(); } } }); } //设置接口 public interface MyCallback { void doAfterResponse(Object o); } }