12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709 |
- package com.bgy.autosale.payutil;
- import static com.hboxs.base_library.util.ToastUtil.showToast;
- import android.content.Context;
- import android.content.Intent;
- import android.media.AudioManager;
- import android.os.Bundle;
- import android.os.Handler;
- import android.text.TextUtils;
- import android.util.Log;
- import com.bgy.autosale.R;
- import com.example.spunsugar.http.bean.GetAdBean;
- import com.example.spunsugar.system.model.bean.PriceBean;
- import com.google.gson.Gson;
- import com.google.gson.reflect.TypeToken;
- import com.hboxs.base_library.base.BaseApplication;
- import com.hboxs.base_library.base.IView;
- import com.hboxs.base_library.beans.AlarmClock;
- import com.hboxs.base_library.constant.BaseConstant;
- import com.hboxs.base_library.constant.Global;
- import com.hboxs.base_library.constant.Heartbeat;
- import com.hboxs.base_library.constant.Name;
- import com.hboxs.base_library.constant.ProductAbout;
- import com.hboxs.base_library.event.ApiMessageEvent;
- import com.hboxs.base_library.event.Message;
- import com.hboxs.base_library.http.NoPayOrderApi;
- import com.hboxs.base_library.http.NoPayOrderStringApi;
- import com.hboxs.base_library.http.exception.BaseException;
- import com.hboxs.base_library.http.exception.ExceptionFactory;
- import com.hboxs.base_library.http.observer.HttpResultNotActivityObserver;
- import com.hboxs.base_library.http.response.HttpResult;
- import com.hboxs.base_library.http.response.HttpResultHandler;
- import com.hboxs.base_library.util.AlarmManagerUtil;
- import com.hboxs.base_library.util.FileUtil;
- import com.hboxs.base_library.util.LogUtil;
- import com.hboxs.base_library.util.LogUtils;
- import com.hboxs.base_library.util.SharedPreferencesUtils;
- import com.hboxs.base_library.util.TimeUtil;
- import com.hboxs.base_library.util.ToastUtil;
- import com.hboxs.base_library.util.UiUtil;
- import com.igexin.sdk.GTIntentService;
- import com.igexin.sdk.message.GTCmdMessage;
- import com.igexin.sdk.message.GTNotificationMessage;
- import com.igexin.sdk.message.GTTransmitMessage;
- import com.orhanobut.hawk.Hawk;
- import com.orhanobut.logger.Logger;
- import org.greenrobot.eventbus.EventBus;
- import org.greenrobot.eventbus.Subscribe;
- import org.greenrobot.eventbus.ThreadMode;
- import java.io.ByteArrayOutputStream;
- import java.io.DataInputStream;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.net.HttpURLConnection;
- import java.net.URL;
- import java.net.URLConnection;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.Timer;
- import java.util.TimerTask;
- import io.reactivex.Observable;
- import io.reactivex.android.schedulers.AndroidSchedulers;
- import io.reactivex.disposables.CompositeDisposable;
- import io.reactivex.observers.DisposableObserver;
- import io.reactivex.schedulers.Schedulers;
- /**
- * @author whw
- * @time 2019/3/27
- * @Description 继承 GTIntentService 接收来⾃个推的消息, 所有消息在线程中回调, 如果注册了该服务, 则务必要在 AndroidManifest中声明, 否则⽆法接
- * 受消息
- * onReceiveMessageData 处理透传消息
- * onReceiveClientId 接收 cid
- * onReceiveOnlineState cid 离线上线通知
- * onReceiveCommandResult 各种事件处理回执
- */
- public class MyIntentService extends GTIntentService {
- private File file = new File(FileUtil.FILEPATH + FileUtil.getFileName());
- private File fileMkdirs = new File(FileUtil.FILEPATH);
- private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- private String date = format.format(new Date(System.currentTimeMillis()));
- private FileOutputStream mFileOutputStream;
- private List<PriceBean> priceBeans;
- //当前下载的索引
- private static int currentIndex;
- //显示的数据
- private ArrayList<GetAdBean> getAdBeans;
- //下载失败索引 删除无用数据
- private List<String> downloadFailedIndex;
- // json名字时间转换 用于判断文件名的唯一 用于下载
- private ArrayList<GetAdBean> timeDatas;
- //要显示的棉花糖广告<index,name>
- private Map<Integer, GetAdBean> showSugar;
- //要显示的外接广告<index,name>
- private Map<Integer, GetAdBean> showOut;
- private int mOpen;
- @Override
- public void onCreate() {
- super.onCreate();
- Log.e(TAG, "onCreate: MyIntentService");
- EventBus.getDefault().register(this);
- getAdByEquipment();
- Log.e(TAG, "onCreate: MyIntentService2");
- }
- @Override
- public void onReceiveServicePid(Context context, int i) {
- }
- @Override
- public void onReceiveClientId(Context context, String clientid) {
- Log.e(TAG, "onReceiveClientId -> " + "clientid = " + clientid);
- Heartbeat.clientId = clientid;
- }
- @Override
- public void onReceiveMessageData(Context context, GTTransmitMessage gtTransmitMessage) {
- // 透传消息的处理,详看SDK demo
- String appid = gtTransmitMessage.getAppid();
- String taskid = gtTransmitMessage.getTaskId();
- String messageid = gtTransmitMessage.getMessageId();
- byte[] payload = gtTransmitMessage.getPayload();
- String pkg = gtTransmitMessage.getPkgName();
- String cid = gtTransmitMessage.getClientId();
- String data = new String(payload);
- Gson gson = new Gson();
- // Log.e(TAG, "onReceiveMessageData: " + ";appid" + appid + ";taskid" + taskid + ";messageid" + messageid + ";payload" + payload + ";pkg" + pkg + ";cid" + cid);
- Log.e(TAG, "onReceiveMessageData: data:" + data);
- String realData = data;
- Log.e(TAG, "onReceiveMessageData : realData=" + realData);
- BaseBean baseBean = gson.fromJson(realData, BaseBean.class);
- String kind = baseBean.getKind();
- Log.d(TAG, "onReceiveMessageData1: ");
- if (TextUtils.isEmpty(Heartbeat.managerId)) return;
- Log.d(TAG, "onReceiveMessageData2: ");
- switch (kind) {
- case "products":
- //保存价格到本地
- // savePriceData(gson, baseBean, kind);
- break;
- case "guestPwd":
- savePas(gson, baseBean, Name.GUEST);
- break;
- case "adminPwd":
- savePas(gson, baseBean, Name.ADMIN);
- break;
- case "pay_success":
- pay(gson, baseBean, kind);
- break;
- case "statusType":
- statusType(gson, baseBean, kind);
- break;
- case "payType":
- //支付方式
- // savaPayType(gson, baseBean, kind);
- break;
- case "push":
- //更新广告
- // String json = baseBean.getKind_data();
- // if (json.equals("更新广告")) {
- // saveAd();
- // }
- break;
- case "phone":
- //联系方式
- // saveContacts(gson, baseBean, kind);
- break;
- case "pushTimeRule":
- //广告规则
- // changeAdRules(gson, baseBean, kind);
- break;
- case "eqeStatus":
- //远程开关机
- // openOrClose(gson, baseBean, kind);
- break;
- case "block":
- //锁机
- // block(baseBean.getKind_data());
- break;
- case "is_sleep":
- // sleep(baseBean.getKind_data());
- break;
- case "Param":
- // UpdateAloneParam(baseBean.getKind_data());
- //write(baseBean.getKind_data());
- break;
- case "tuoji":
- //清除连接成功的数据
- SharedPreferencesUtils.setParam(Name.CONNECT_STATE, 0);
- Heartbeat.managerId = "";
- SharedPreferencesUtils.setParam(Name.SYSTEM_ID, Heartbeat.managerId);
- break;
- /* case "openDoor"://远程开关门
- // openDoor();MG320不进行远程开门
- break;*/
- case "log":
- LogUtil.d(TAG, "logdata" + baseBean.getKind_data());
- //远程上传日志文件
- uploadLogApi(baseBean.getKind_data());
- // postUpdates(baseBean.getKind_data());
- break;
- case "onoffstatus":
- Log.d(TAG, "onReceiveMessageData: onoffstatusonoffstatus");
- updateEqeStatus((Integer) SharedPreferencesUtils.getParam("open", 0));
- break;
- case "updateBootTime":
- LogUtil.d(TAG, "onReceiveMessageData: updateBootTime:" + baseBean.getKind_data());
- updateOfforBootTime(baseBean, "boot");
- // Global.temperatureGoUp = 0;
- break;
- case "updateOffTime":
- LogUtil.d(TAG, "onReceiveMessageData: updateOffTime:" + baseBean.getKind_data());
- updateOfforBootTime(baseBean, "off");
- // Global.temperatureGoUp = 1;
- break;
- case "pay_faile":
- //todo 反扫失败,我们需要提示支付失败,请重新提供码
- EventBus.getDefault().post(new ApiMessageEvent("pay_faile", null));
- break;
- /* case "plcVersion":
- LogUtil.d(TAG, "onReceiveMessageData: " + baseBean.getKind_data());
- //让进行修改。
- break;*/
- case "eliminate":
- //todo 消除报警,并且告知后台消除报警成功。
- // eliminateApi(gson, baseBean, kind);
- break;
- case "dosugar":
- //远程制作棉花糖
- LogUtil.d(TAG, "测测测测试 onReceiveMessageData: " + address);//set是启动,rst是不启动
- EventBus.getDefault().post(new ApiMessageEvent("dosugar", baseBean.getKind_data()));
- break;
- case "alarmClock":
- //远程星期调节闹钟
- parseWeekTime(gson, baseBean);
- EventBus.getDefault().post(new ApiMessageEvent("alarmClock", baseBean.getKind_data()));
- break;
- case "volume":
- String kind_data = baseBean.getKind_data();
- try {
- int i = Integer.parseInt(kind_data);
- if (i >= 0 && i <= 15) {
- AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
- am.setStreamVolume(AudioManager.STREAM_MUSIC, i, 0);
- LogUtils.logWrite("MQ1的音量:" + i);
- }
- } catch (Exception e) {
- }
- break;
- case "selfName"://客户自填地址
- PushToinform(Name.SELFNAME, baseBean.getKind_data());
- break;
- case "operational"://运营名字:联系电话。
- PushToinform(Name.OPERATIONAL, baseBean.getKind_data());
- break;
- case "qrCodeImgUrl"://公众号图片地址:http://47.112.127.131/img/qr.jpg
- qrCodeImgUrl(kind, baseBean.getKind_data());
- break;
- default:
- break;
- }
- }
- private void qrCodeImgUrl(String name, String kind_data) {
- String qrCodeImgUrl = Hawk.get(Name.QRCODEIMGURL, "");
- /* if (kind_data.equals(qrCodeImgUrl))//如果相等,直接结束
- return;*/
- ArrayList<GetAdBean> getAdBeans = new ArrayList<>();
- GetAdBean getAdBean = new GetAdBean();
- getAdBean.setUrl(kind_data);
- getAdBean.setScreenType(2);
- getAdBean.setName("qrcode");
- getAdBean.setId("qrcode");
- getAdBeans.add(getAdBean);
- EventBus.getDefault().post(new ApiMessageEvent(name, getAdBeans));
- }
- //推送
- private void PushToinform(String name, String kind_data) {
- Hawk.put(name, kind_data);
- //推送界面告知要修改。
- EventBus.getDefault().post(new ApiMessageEvent(name, kind_data));
- }
- // private void UpdateAloneParam(String kindData) {
- // String[] split = kindData.split(":");
- // //更新参数。
- // updataParam(kindData);
- // //通知到后台
- // HashMap<String, String> params = new HashMap<>();
- // if (Arrays.asList(ThreadGetParameterUpdate.getParaAddress2()).contains(split[0])) {
- // params.put("code", "1");
- // } else {
- // params.put("code", "0");
- // }
- // params.put("clientId", Heartbeat.deviceId);
- // params.put("name", split[0]);
- // params.put("val", split[1]);
- // addSubscriptionNew(NoPayOrderStringApi.api.updateAloneParam(params),String.class,
- // new HttpResultNotActivityObserver<String>(view, getApplicationContext()) {
- // @Override
- // public void onNext(String data) {
- // LogUtil.d(TAG, "成功了onNext: ");
- // }
- //
- // @Override
- // public void onError(Throwable t) {
- // super.onError(t);
- // LogUtil.d(TAG, "成功onError: ");
- //
- // }
- // });
- // }
- private void updataParam(String kindData) {
- String[] split = kindData.split(":");
- String address = split[0];
- String data = split[1];
- if (!TextUtils.isEmpty(address) || !TextUtils.isEmpty(data)) {
- char c = address.charAt(0);
- switch (c) {
- //复位和置位 0为启动,1为关闭。
- case 'M':
- if ("0".equals(data)) {
- EventBus.getDefault().post(new ApiMessageEvent("updataParamSet", address));
- } else {
- EventBus.getDefault().post(new ApiMessageEvent("updataParamRst", address));
- }
- break;
- //写入,写入后需要上传。
- case 'D':
- EventBus.getDefault().post(new ApiMessageEvent("updataParamWrite", split));
- break;
- }
- }
- }
- private void parseWeekTime(Gson gson, BaseBean baseBean) {
- new Thread(new Runnable() {
- @Override
- public void run() {
- LogUtil.d(TAG, "parseWeekTime: " + baseBean);
- String kindData = baseBean.getKind_data();//拿到数据
- AlarmClock alarmClock = gson.fromJson(kindData, AlarmClock.class);
- LogUtil.d(TAG, "parseWeekTime1: " + alarmClock);
- String type = alarmClock.getType();//是休眠,还是开关机
- ArrayList<String> weekTimes = alarmClock.getData();//获取字符串时间。
- LogUtil.d(TAG, "parseWeekTime2: " + type);
- LogUtil.d(TAG, "parseWeekTime3: " + weekTimes);
- if ("2".equals(type)) {
- Global.openSleepNumber = setAlarmClock(400, weekTimes, type, Global.openSleepNumber);
- } else if ("3".equals(type)) {
- Global.closeSleepNumber = setAlarmClock(500, weekTimes, type, Global.closeSleepNumber);
- } else if ("1".equals(type)) {
- Global.offTimeNumber = setAlarmClock(300, weekTimes, type, Global.offTimeNumber);
- } else if ("0".equals(type)) {
- Global.bootTimeNumber = setAlarmClock(200, weekTimes, type, Global.bootTimeNumber);
- }
- }
- }).start();
- }
- public int setAlarmClock(int number, ArrayList<String> weekTimes, String type, int alarmNumber) {
- Log.d(TAG, "AlarmClock2onNext alarmNumber:" + alarmNumber + ";setAlarmClock: " + (number));
- for (int i = number; i < alarmNumber; i++) {//清除所有的闹钟
- AlarmManagerUtil.cancelAlarm(BaseApplication.getContext(), AlarmManagerUtil.ALARM_ACTION, i);
- Log.d(TAG, "AlarmClock2onNext alarmNumber:" + alarmNumber + ";setAlarmClock: " + (i));
- }
- for (String weekTime : weekTimes) {
- String[] weekTimeArray = weekTime.split(",:");
- String[] weeks = weekTimeArray[0].split(",");//星期
- String[] times = weekTimeArray[1].split(":");//时间
- for (int i = 0; i < weeks.length; i++) {
- AlarmManagerUtil.setAlarm(BaseApplication.getContext(), 2, Integer.valueOf(times[0]), Integer.valueOf(times[1]), Integer.valueOf(times[2]), i + number, Integer.valueOf(weeks[i]), type);
- // AlarmManagerUtil.setAlarm(BaseApplication.getContext(),2,Integer.valueOf(times[0]),Integer.valueOf(times[1]),Integer.valueOf(times[2]),i + number,Integer.valueOf(weeks[i]),type);
- }
- number = number + weeks.length;//累积。
- }
- return number;
- }
- private void updateOfforBootTime(BaseBean baseBean, String offorboot) {
- String times = baseBean.getKind_data();
- LogUtil.d(TAG, "updateOfforBootTime: " + times + offorboot);
- if (!TextUtils.isEmpty(times)) {
- String[] Alltime = times.split("\\,");
- //如果之前的数据和现在的数据,数量相同,或者之前的数据小于现在的数据,,那么不清除直接替换。
- /**
- * 如果获取过来的时间
- * 1.少于:清空
- * 2.大于:什么都不做。
- * 3.等于:什么都不做。
- */
- if ("off".equals(offorboot)) {
- for (int i = 0; i < Global.offTimeAlarmNumber; i++) {
- LogUtil.d(TAG, "updateOfforBootTime: " + Global.offTimeAlarmNumber);
- AlarmManagerUtil.cancelAlarm(BaseApplication.getContext(), AlarmManagerUtil.ALARM_ACTION, i);
- }
- Global.offTimeAlarmNumber = Alltime.length;
- for (int i = 0; i < Alltime.length; i++) {
- String[] data = Alltime[i].split(":");
- for (String datum : data) {
- LogUtil.d(TAG, "onSuccesstime: " + datum);
- }
- //设置定时闹钟
- AlarmManagerUtil.setAlarm(BaseApplication.getContext(), 1, Integer.valueOf(data[0]), Integer.valueOf(data[1]), Integer.valueOf(data[2]), i, 0, offorboot);
- }
- } else if ("boot".equals(offorboot)) {
- Log.d(TAG, "bootTimeAlarmNumber: " + Global.bootTimeAlarmNumber + ",Alltime.length:" + Alltime.length);
- for (int i = 0; i < Global.bootTimeAlarmNumber; i++) {
- AlarmManagerUtil.cancelAlarm(BaseApplication.getContext(), AlarmManagerUtil.ALARM_ACTION, i + 10);
- }
- Global.bootTimeAlarmNumber = Alltime.length;
- for (int i = 0; i < Alltime.length; i++) {
- String[] data = Alltime[i].split(":");
- for (String datum : data) {
- LogUtil.d(TAG, "boottimeonSuccesstime: " + datum);
- }
- //设置定时闹钟
- AlarmManagerUtil.setAlarm(BaseApplication.getContext(), 1, Integer.valueOf(data[0]), Integer.valueOf(data[1]), Integer.valueOf(data[2]), i + 10, 0, offorboot);
- }
- }
- } else {
- if ("off".equals(offorboot)) {
- for (int i = 0; i < Global.offTimeAlarmNumber; i++) {
- LogUtil.d(TAG, "updateOfforBootTime: " + Global.offTimeAlarmNumber);
- AlarmManagerUtil.cancelAlarm(BaseApplication.getContext(), AlarmManagerUtil.ALARM_ACTION, i);
- }
- }
- if ("boot".equals(offorboot)) {
- for (int i = 0; i < Global.bootTimeAlarmNumber; i++) {
- AlarmManagerUtil.cancelAlarm(BaseApplication.getContext(), AlarmManagerUtil.ALARM_ACTION, i + 10);
- }
- }
- }
- }
- public void uploadLogApi(String kindData) {
- new Thread(new Runnable() {
- @Override
- public void run() {
- File file = new File("/storage/emulated/0/logdata/" + kindData + ".txt");
- LogUtil.d(TAG, "uploadLogApi: " + kindData);
- if (file.exists()) {
- if (file.isFile()) {
- DataInputStream in = null;
- OutputStream out = null;
- HttpURLConnection conn = null;
- InputStream ins = null;
- ByteArrayOutputStream outStream = null;
- try {
- URL url = new URL(BaseConstant.ONLINE_BASE_URL + "/api/app_equipment/index/sendLog.htm?fileName=" + kindData);
- conn = (HttpURLConnection) url.openConnection();
- // 发送POST请求必须设置如下两行
- conn.setDoOutput(true);
- conn.setUseCaches(false);
- conn.setRequestMethod("POST");
- conn.setRequestProperty("Content-Type", "text/html");
- conn.setRequestProperty("Cache-Control", "no-cache");
- conn.setRequestProperty("Charsert", "UTF-8");
- conn.connect();
- conn.setConnectTimeout(10000);
- out = conn.getOutputStream();
- // sb.append("Content-Disposition: form-data; fileName=\""
- // + file.getName() + "\"" + LINE_END);
- // sb.append("Content-Type: text/plain;");
- // sb.append(LINE_END);
- // out.write(sb.toString().getBytes());
- in = new DataInputStream(new FileInputStream(file));
- int bytes = 0;
- byte[] buffer = new byte[1024];
- while ((bytes = in.read(buffer)) != -1) {
- out.write(buffer, 0, bytes);
- }
- out.flush();
- // 返回流
- if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
- ins = conn.getInputStream();
- outStream = new ByteArrayOutputStream();
- byte[] data = new byte[1024];
- int count = -1;
- while ((count = ins.read(data, 0, 1024)) != -1) {
- outStream.write(data, 0, count);
- LogUtil.d(TAG, "uploadLogApi: " + new String(data));
- }
- } else {
- LogUtil.d(TAG, "uploadLogApi: " + conn.getResponseCode());
- }
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- if (in != null) {
- try {
- in.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- if (out != null) {
- try {
- out.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- if (ins != null) {
- try {
- ins.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- if (outStream != null) {
- try {
- outStream.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- if (conn != null) {
- conn.disconnect();
- }
- }
- }
- }
- }
- }).start();
- }
- private Timer timerOpenDoor;
- private TimerTask timerTaskOpenDoor;
- private Boolean isSetM300Success = true;
- // private void openDoor() {
- // LogUtil.d(TAG, "stopTimerSet: 开始置位/开始读取");
- // isSetM300Success = false;
- // //读取数据
- // timerOpenDoor = new Timer();
- // timerTaskOpenDoor = new TimerTask() {
- // @Override
- // public void run() {
- // if (!isSetM300Success) {
- //
- // SerialPortSendQueue.sendCommand(new SetCommandFrame("M301"), Address.ID_M300, "M301");
- // LogUtil.d(TAG, "run: " + "M301");
- // }
- // }
- // };
- // timerOpenDoor.schedule(timerTaskOpenDoor, 100, 500);
- //
- // }
- // /**
- // * 停止读取
- // */
- // private void stopTimerOpenDoor() {
- // LogUtil.d(TAG, "stopTimerSet: 停止置位/停止读取");
- // isSetM300Success = true;
- // TimerUtil.stopTimerAndTimerTask(timerOpenDoor, timerTaskOpenDoor);
- //
- // }
- // private void write(String kind_data) {
- // Log.e(TAG, "write: " + kind_data);
- // String[] split = kind_data.split(":");
- // String address = split[0].trim();
- // String data = split[1].trim();
- // long dec = Long.parseLong(data);
- // //不足四位补0
- // String hex = ByteUtils.decimal2fitHex(dec);
- // if (hex.length() % 4 != 0) {
- // int length = data.length();
- // for (int i = 0; i < 4 - length; i++) {
- // hex = "0" + hex;
- // }
- // }
- // String bin = HexUtils.hexStr2BinStr(hex);
- //// SerialPortSendQueue.clear();
- ////
- //// SerialPortSendQueue.sendCommand(new WriteCommandFrame(address,bin), 400, address);
- // isWreiteSuccess = false;
- // startTimerWtire(address, bin);
- // }
- // private void sleep(String baseBean) {
- // if (baseBean.equals("1")) {
- // //睡眠
- // Intent intent = new Intent(MyIntentService.this, LockActivity.class);
- // intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
- // startActivity(intent);
- // } else {
- // if (Name.WMDB.equals(Hawk.get(Name.NOTE_COMMUNICATION, Name.MDB))) {
- // WeaverUtil.billValidatorSetUp();
- // }else if (Name.ICT.equals(Hawk.get(Name.NOTE_COMMUNICATION,Name.MDB))) {
- // SerialPortUtil.getSerialPortUtil().sendSerialPort("3E");
- //
- // }
- // LogUtils.logWrite("开启:"+(Name.ICT.equals(Hawk.get(Name.NOTE_COMMUNICATION,Name.MDB))));
- ////唤醒
- // SharedPreferencesUtils.setParam("sleep", 1);
- // Intent intent = new Intent(MyIntentService.this, BuyActivity.class);
- // intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
- // startActivity(intent);
- //
- // HashMap<String, Object> params = new HashMap<>();
- // params.put("clientId", Heartbeat.deviceId);
- // params.put("is_sleep", false);
- // addSubscriptionNew(NoPayOrderStringApi.api.updateSleep(params),String.class,
- // new HttpResultNotActivityObserver<String>(view, getApplicationContext()) {
- // @Override
- // public void onNext(String data) {
- //
- // }
- //
- // @Override
- // public void onError(Throwable t) {
- // super.onError(t);
- //
- // }
- // });
- // }
- // // 如果没跳到锁机界面 上传锁机失败
- // new Handler().postDelayed(new Runnable() {
- // @Override
- // public void run() {
- // boolean isSuccess = (boolean) SharedPreferencesUtils.getParam("sleep_state", false);
- // if (isSuccess) {
- // //进行网络请求
- // LogUtil.d(TAG, "run: 睡眠状态上传false");
- // HashMap<String, Object> params = new HashMap<>();
- // params.put("clientId", Heartbeat.deviceId);
- // params.put("is_sleep", false);
- // addSubscriptionNew(NoPayOrderStringApi.api.UpdateBlockApi(params),String.class,
- // new HttpResultNotActivityObserver<String>(view, getApplicationContext()) {
- // @Override
- // public void onNext(String data) {
- //
- // }
- //
- // @Override
- // public void onError(Throwable t) {
- // super.onError(t);
- //
- // }
- // });
- // }
- // SharedPreferencesUtils.setParam("block_state", false);
- //
- // }
- // }, 1000 * 10);
- // }
- // private void block(String baseBean) {
- // if (baseBean.equals("0")) {
- // Intent intent = new Intent(MyIntentService.this, SleepActivity.class);
- // intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
- // startActivity(intent);
- // } else {
- // SharedPreferencesUtils.setParam("block", 1);
- // Intent intent = new Intent(MyIntentService.this, BuyActivity.class);
- // intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
- // startActivity(intent);
- //
- // HashMap<String, Object> params = new HashMap<>();
- // params.put("clientId", Heartbeat.deviceId);
- // params.put("block", false);
- // addSubscriptionNew(NoPayOrderStringApi.api.UpdateBlockApi(params),String.class,
- // new HttpResultNotActivityObserver<String>(view, getApplicationContext()) {
- // @Override
- // public void onNext(String data) {
- //
- // }
- //
- // @Override
- // public void onError(Throwable t) {
- // super.onError(t);
- //
- // }
- // });
- // }
- // // 如果没跳到锁机界面 上传锁机失败
- // new Handler().postDelayed(new Runnable() {
- // @Override
- // public void run() {
- // boolean isSuccess = (boolean) SharedPreferencesUtils.getParam("block_state", false);
- // if (isSuccess) {
- // //进行网络请求
- // LogUtil.d(TAG, "run: 锁机状态上传false");
- // HashMap<String, Object> params = new HashMap<>();
- // params.put("clientId", Heartbeat.deviceId);
- // params.put("block", false);
- // addSubscriptionNew(NoPayOrderStringApi.api.UpdateBlockApi(params),String.class,
- // new HttpResultNotActivityObserver<String>(view, getApplicationContext()) {
- // @Override
- // public void onNext(String data) {
- //
- // }
- //
- // @Override
- // public void onError(Throwable t) {
- // super.onError(t);
- //
- // }
- // });
- // }
- // SharedPreferencesUtils.setParam("block_state", false);
- //
- // }
- // }, 1000 * 10);
- // }
- // /**
- // * 改变广告规则
- // *
- // * @param gson
- // * @param baseBean
- // * @param kind
- // */
- // private void changeAdRules(Gson gson, BaseBean baseBean, String kind) {
- // String json = baseBean.getKind_data();
- // LogUtil.d(TAG, "changeAdRules: json=" + json);
- // saveAdRulesBefore(json);
- // }
- // //增加一个前置条件
- // private void saveAdRulesBefore(String id) {
- // //如果id为1,并且这里是全屏,那么就推送235的
- // if (Hawk.get(Name.DEFAULT_FULL_SCREEN, true) && "1".equals(id) && !Hawk.get(Name.PLAY_MODE, false)) {
- // saveAdRules("779");
- // } else {
- // saveAdRules(id);
- // }
- //
- // }
- /**
- * 保存联系人
- *
- * @param gson
- * @param baseBean
- * @param kind
- */
- private void saveContacts(Gson gson, BaseBean baseBean, String kind) {
- String json = baseBean.getKind_data();
- Log.e(TAG, "saveContacts:json= " + json);
- Log.e(TAG, "saveContacts: " + json.contains(":"));
- if (json.contains(":")) {
- //获取:后的数据(广告规则id)
- String contactsWay = json.substring(json.lastIndexOf(":") + 1, json.length());
- Log.e(TAG, "saveContacts: 联系方式=" + contactsWay);
- //去掉:的值
- String contactsName = json.substring(0, json.lastIndexOf(":"));
- Log.e(TAG, "saveContacts: 联系人=" + contactsName);
- SharedPreferencesUtils.setParam(Name.CONTACTS_NUM, contactsWay);
- SharedPreferencesUtils.setParam(Name.CONTACTS_NAME, contactsName);
- EventBus.getDefault().post(new ApiMessageEvent(kind, null));
- }
- }
- // /**
- // * 保存广告
- // */
- // private void saveAd() {
- //// getFilesDir();
- //// LogUtil.d(TAG, "initView: "+ getFilesDir().getName());
- //// addSubscription(GetAdApi.api.getAd().compose(HttpResultHandler.<String>transformer()),
- //// new HttpResultNotActivityObserver<String>(view, getApplicationContext()) {
- //// @Override
- //// public void onNext(String s) {
- //// Gson gson = new Gson();
- //// getAdBeans = gson.fromJson(s, new TypeToken<List<GetAdBean>>() {
- //// }.getType());
- ////
- //// showSugar = Hawk.get("show_sugar", new HashMap<Integer, GetAdBean>());
- //// showOut = Hawk.get("show_out", new HashMap<Integer, GetAdBean>());
- //// //1 获取本地的已下载数据
- //// ArrayList<File> allFile =new ArrayList<>();
- //// File[] allFiles = FileUtil.getAllFiles(BaseApplication.getContext().getExternalFilesDir("").getAbsolutePath() + "/Download", "");
- //// if (allFiles!=null&&allFiles.length>=0){
- ////
- //// for (int i=0;i<allFiles.length;i++){
- //// allFile.add(allFiles[i]);
- //// }
- //// //2 判断要下载的数据是否与本地相同
- //// timeDatas = new ArrayList<>();
- //// for (int i = 0; i < getAdBeans.size(); i++) {
- //// GetAdBean getAdBean = getAdBeans.get(i);
- //// long createDate = getAdBean.getCreateDate();
- //// String time = TimeUtil.getNoTime(createDate);
- //// String name = getAdBean.getName();
- //// String newName = time + name;
- //// getAdBean.setName(newName);
- //// timeDatas.add(getAdBean);
- //// }
- ////
- //// //全部默认显示 添加数据
- //// for (int i=0;i<timeDatas.size();i++){
- //// showSugar.put(i, timeDatas.get(i));
- //// showOut.put(i, timeDatas.get(i));
- //// }
- ////
- //// Hawk.put("show_sugar", showSugar);
- //// Hawk.put("show_out", showOut);
- ////
- //// }
- ////
- //// //备份一个list用于删除
- //// //另外一个用于显示
- //// //相同 不下载(删除一个实体) 不删除本地文件
- ////
- //// ArrayList<File> unDeleteFiles = new ArrayList<>();
- //// if (allFiles != null) {
- //// for (int i = 0; i < allFiles.length; i++) {
- //// File file = allFiles[i];
- //// String name = allFiles[i].getName();
- //// //时间,用于判断唯一
- //// if (name.length()<14){
- //// continue;
- //// }
- //// String substring = name.substring(0, 14);
- ////
- //// for (int j = 0; j < timeDatas.size(); j++) {
- //// GetAdBean getAdBean = timeDatas.get(j);
- //// String name1 = getAdBean.getName();
- //// String substring1 = name1.substring(0, 14);
- //// if (substring.equals(substring1)) {
- //// //相同的删除url 不下载
- //// Log.e(TAG, "onNext不下载的文件: " + name);
- //// timeDatas.remove(j);
- //// //记住不删除的文件
- //// unDeleteFiles.add(file);
- //// }
- //// }
- ////
- //// }
- ////
- //// for (int i=0;i<unDeleteFiles.size();i++){
- //// Log.e(TAG, "onNext: unDeleteFiles name="+unDeleteFiles.get(i).getName());
- //// }
- ////
- ////
- ////
- ////
- ////
- //// //不同的 删除本地文件
- //// //只剩下删除的文件
- //// allFile.removeAll(unDeleteFiles);
- //// for (int i=0;i<allFile.size();i++){
- //// File file = allFile.get(i);
- //// if (file!=null&&file.exists()){
- //// Log.e(TAG, "onNext:删除的文件 "+file.getName() );
- //// file.delete();
- ////
- //// }
- //// }
- ////
- //// }
- ////
- //// //3 下载数据
- //// if (timeDatas.size() <= 0) {
- //// LogUtil.d(TAG, "onNext: 推送过来的数据相同,不下载");
- //// Hawk.put("showAd",getAdBeans);
- //// return;
- //// }
- //// downLoadFile(currentIndex, "", timeDatas);
- ////
- ////
- //// //开始下载
- ////
- ////
- //// }
- ////
- //// @Override
- //// public void onError(Throwable t) {
- //// super.onError(t);
- //// BaseException exception = ExceptionFactory.create(t);
- //// }
- //// });
- //
- // //interService 不下 在service下
- // EventBus.getDefault().post(new ApiMessageEvent("DOWNKOADAD", null));
- // }
- // /**
- // * 修改支付方式
- // *
- // * @param gson
- // * @param baseBean
- // */
- // private void savaPayType(Gson gson, BaseBean baseBean, String kind) {
- // String json = baseBean.getKind_data();
- // Log.e(TAG, "savaPayType: json=" + json);
- // //判断有没有冒号
- // if (json.contains(":")) {
- // //获取:后的数据(广告规则id)
- // String id = json.substring(json.lastIndexOf(":") + 1, json.length());
- // saveAdRules(id);
- // //去掉:的值
- // json = json.substring(0, json.lastIndexOf(":"));
- //
- // }
- // String s = gson.fromJson(json, String.class);
- // switch (s) {
- // case "noPay":
- // //无需支付
- // SharedPreferencesUtils.setParam(Name.PAY_TYPE, 1);
- // break;
- // case "onlinePayment":
- // //线上支付
- // SharedPreferencesUtils.setParam(Name.PAY_TYPE, 2);
- // break;
- // case "offlinePayment":
- // //线下支付
- // SharedPreferencesUtils.setParam(Name.PAY_TYPE, 3);
- // break;
- // case "onOrOffPayment":
- // //线上线下支付
- // SharedPreferencesUtils.setParam(Name.PAY_TYPE, 4);
- // break;
- // default:
- // break;
- // }
- //
- //
- // EventBus.getDefault().post(new ApiMessageEvent(kind, null));
- //
- // SharedPreferencesUtils.setParam(Name.PAY_TYPE, 2);
- // }
- // /**
- // * 保存广告id
- // */
- // private void saveAdRules(String id) {
- // LogUtil.d(TAG, "ad_id ->" + id);
- // Long lid = Long.valueOf(id);
- // Map<String, Long> params = new HashMap<>();
- // params.put("id", lid);
- // addSubscriptionNew(NoPayOrderStringApi.api.getTimeRule(params),String.class,
- // new HttpResultNotActivityObserver<String>(view, getApplicationContext()) {
- //
- // @Override
- // public void onNext(String s) {
- // LogUtil.d(TAG, "ad_rules s ->" + s);
- // //保存广告规则json
- // // SharedPreferencesUtils.setParam("ad_time_rule",s);
- // //广告数据
- // ArrayList<GetAdBean> adBeans = Hawk.get("showAd", new ArrayList<GetAdBean>());
- // ArrayList<GetAdBean> showAdA = Hawk.get("showAdA", new ArrayList<GetAdBean>());
- //
- // Gson gson = new Gson();
- // List<TimeRuleBean> list = gson.fromJson(s, new TypeToken<List<TimeRuleBean>>() {
- // }.getType());
- // //每个id对应的时间数
- // Map<String, String> adRulesMap = new HashMap<>();
- // for (int i = 0; i < adBeans.size(); i++) {
- // GetAdBean getAdBean = adBeans.get(i);
- // StringBuilder sb = new StringBuilder();
- // for (int j = 0; j < list.size(); j++) {
- // //每个规则里对应的广告
- // List<String> ad = list.get(j).getAd();
- // for (int k = 0; k < ad.size(); k++) {
- // if (ad.get(k).equals(getAdBean.getId())) {
- //// if (j%2!=0){
- //// sb.append(list.get(j).getTime()+",");
- //// }else {
- // sb.append(list.get(j).getTime() + "、");
- // LogUtil.d(TAG, "ad_rules list get get" + list.get(j).getName());
- //// }
- //
- // }
- // }
- // }
- // if (sb.length() > 0) {
- // sb.deleteCharAt(sb.length() - 1);
- // }
- // Log.e(TAG, "ad_rules onNext: " + "ad_id=" + getAdBean.getId() + " rules=" + sb.toString());
- // adRulesMap.put(getAdBean.getId(), sb.toString());
- // }
- // /* for (int i = 0; i < showAdA.size(); i++) {
- // GetAdBean getAdBean = showAdA.get(i);
- // StringBuilder sb = new StringBuilder();
- // for (int j = 0; j < list.size(); j++) {
- // //每个规则里对应的广告
- // List<String> ad = list.get(j).getAd();
- // for (int k = 0; k < ad.size(); k++) {
- // if (ad.get(k).equals(getAdBean.getId())) {
- ////
- // sb.append(list.get(j).getTime() + "、");
- // LogUtil.d(TAG, "ad_rules list get get" + list.get(j).getName());
- //// }
- //
- // }
- // }
- // }
- // if (sb.length() > 0) {
- // sb.deleteCharAt(sb.length() - 1);
- // }
- // Log.e(TAG, "ad_rules onNext: " + "ad_id=" + getAdBean.getId() + " rules=" + sb.toString());
- // //会将右边的给覆盖掉。
- // adRulesMap.put(getAdBean.getId(), sb.toString());
- // }*/
- // Log.d(TAG, "adRulesMap onNext: " + adRulesMap.size());
- // //保存对应的id对应的广告规则
- // Hawk.put("ad_rules_map", adRulesMap);
- // EventBus.getDefault().post(new ApiMessageEvent("pushTimeRule", null));
- //
- // //发送设备id
- //// deviceIdPostApi();
- // getAdByEquipment();
- // LogUtil.d(TAG, "onNextgetAdByEquipment: ");
- // }
- //
- // @Override
- // public void onError(Throwable t) {
- // super.onError(t);
- // Log.d(TAG, "onError: ");
- // BaseException exception = ExceptionFactory.create(t);
- // }
- //
- // });
- //
- // }
- /**
- * 上传设备id
- */
- private void deviceIdPostApi() {
- Map<String, String> params = new HashMap<>();
- params.put("clientId", Heartbeat.deviceId + "");
- addSubscriptionNew(NoPayOrderApi.api.getAdNew(params),String.class,
- new HttpResultNotActivityObserver<String>(view, getApplicationContext()) {
- @Override
- public void onNext(String s) {
- EventBus.getDefault().post(new ApiMessageEvent("DOWNKOADADCID", s));
- LogUtil.d(TAG, "ad_rules saveAdRulesmy onNext: " + s);
- }
- @Override
- public void onError(Throwable t) {
- super.onError(t);
- BaseException exception = ExceptionFactory.create(t);
- LogUtil.d(TAG, "saveAdRulesmy onError: ");
- }
- });
- }
- /**
- * 上传设备id和型号
- */
- private void getAdByEquipment() {
- Map<String, String> params = new HashMap<>();
- params.put("clientId", Heartbeat.deviceId + "");
- String machineType = Hawk.get(Name.MACHINE_TYPE, Name.SI320);
- if (machineType.equals("SI320")) {
- if (Global.isVersions==2) {
- params.put("equipmentType", "320en");
- }else{
- params.put("equipmentType", "320");
- }
- }
- Log.d(TAG, "getAdByEquipment1: "+params.get("equipmentType"));
- addSubscription(NoPayOrderApi.api.getAdByEquipment(params).compose(HttpResultHandler.<String>transformer()),
- new HttpResultNotActivityObserver<String>(view, getApplicationContext()) {
- @Override
- public void onNext(String s) {
- EventBus.getDefault().post(new ApiMessageEvent("DOWNKOADADCID", s));
- LogUtil.d(TAG, "ad_rules saveAdRulesmy onNext: " + s);
- }
- @Override
- public void onError(Throwable t) {
- super.onError(t);
- BaseException exception = ExceptionFactory.create(t);
- LogUtil.d(TAG, "saveAdRulesmy onError: ");
- }
- });
- }
- // /**
- // * 上传服务器发送过来的报警id
- // */
- // private void eliminateApi(Gson gson, BaseBean baseBean, String kind) {
- // String json = baseBean.getKind_data();
- // EliminateBean eliminateApi = gson.fromJson(json, EliminateBean.class);
- // EventBus.getDefault().post(new ApiMessageEvent("eliminate", eliminateApi.getId()));
- // Map<String, String> params = new HashMap<>();
- // params.put("id", eliminateApi.getId());
- // addSubscriptionNew(NoPayOrderStringApi.api.eliminate(params),String.class,
- // new HttpResultNotActivityObserver<String>(view, getApplicationContext()) {
- // @Override
- // public void onNext(String s) {
- // LogUtil.d(TAG, "eliminateApionNext: " + s);
- // }
- //
- // @Override
- // public void onError(Throwable t) {
- // super.onError(t);
- // BaseException exception = ExceptionFactory.create(t);
- // LogUtil.d(TAG, "eliminateApi onError: ");
- // }
- // });
- // }
- /**
- * 初始化回调
- *
- * @param gson
- * @param baseBean
- * @param kind
- */
- private void statusType(Gson gson, BaseBean baseBean, String kind) {
- String json = baseBean.getKind_data();
- String s = gson.fromJson(json, String.class);
- Log.d(TAG, "statusType: "+s);
- if (s.equals("rejected")) {
- //拒绝
- showToast(UiUtil.getStringRes(R.string.rejected));
- SharedPreferencesUtils.setParam(Name.CONNECT_STATE, 0);
- Log.e(TAG, "statusType: 申请拒绝");
- } else if (s.equals("agreed")) {
- //申请通过
- showToast(UiUtil.getStringRes(R.string.rejected1));
- SharedPreferencesUtils.setParam(Name.CONNECT_STATE, 2);
- Log.e(TAG, "statusType: 申请通过");
- SharedPreferencesUtils.setParam(Name.SYSTEM_ID, Heartbeat.managerId);
- } else if (s.equals("agreed1")) {
- showToast("第二次");
- showToast(UiUtil.getStringRes(R.string.rejected1));
- SharedPreferencesUtils.setParam(Name.CONNECT_STATE, 2);
- Log.e(TAG, "statusType: 申请通过");
- SharedPreferencesUtils.setParam(Name.SYSTEM_ID, Heartbeat.managerId);
- // interService 不能弹出弹窗 在 service中弹出
- EventBus.getDefault().post(new ApiMessageEvent(kind + "1", null));
- }
- EventBus.getDefault().post(new ApiMessageEvent(kind, null));
- }
- // /**
- // * 支付成功
- // *
- // * @param gson
- // * @param baseBean
- // * @param kind
- // */
- private void pay(Gson gson, BaseBean baseBean, String kind) {
- SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- String content = formatter.format(new Date(System.currentTimeMillis())) + "第一步:存儲信息,支付成功" + "\r\n";
- //支付成功
- String json = baseBean.getKind_data();
- PaySucessBean paySucessBean = gson.fromJson(json, PaySucessBean.class);
- PaySuccessConstant.sn = paySucessBean.getSn();
- PaySuccessConstant.productName = paySucessBean.getProductName();
- try {
- if (!fileMkdirs.exists()) {
- fileMkdirs.mkdirs();
- }
- if (!file.exists()) {
- file.createNewFile();
- }
- mFileOutputStream = new FileOutputStream(file, true);
- LogUtil.d("支付成功", "第二部:存儲信息");
- mFileOutputStream.write(content.getBytes());
- mFileOutputStream.close();
- } catch (Exception e) {
- }
- EventBus.getDefault().post(new ApiMessageEvent(kind, null));
- }
- /**
- * 保存管理员密码
- *
- * @param gson
- * @param baseBean
- * @param type 管理员类型
- */
- private void savePas(Gson gson, BaseBean baseBean, String type) {
- String json = baseBean.getKind_data();
- String s = gson.fromJson(json, String.class);
- SharedPreferencesUtils.setParam(type, s);
- }
- // /**
- // * 保存价格到本地
- // *
- // * @param gson
- // * @param baseBean
- // * @param kind
- // */
- // private void savePriceData(Gson gson, BaseBean baseBean, String kind) {
- // if (kind.equals("products")) {
- // priceBeans = new ArrayList<>();
- // String kind_data = baseBean.getKind_data();
- // ArrayList<ProductBean> list = gson.fromJson(kind_data, new TypeToken<List<ProductBean>>() {
- // }.getType());
- // for (int i = 0; i < list.size(); i++) {
- // ProductBean productBean = list.get(i);
- // PriceBean priceBean = new PriceBean();
- // priceBean.setMoney(productBean.getRmbPrice());
- // priceBean.setCoin(productBean.getCodePrice());
- // priceBean.setName(ProductAbout.getChineseNameMQGTR()[i]);
- // priceBean.setChineseName(ProductAbout.getChineseNameMQGTR()[i]);
- // priceBeans.add(priceBean);
- //
- // }
- // //保存价格到本地
- // Hawk.put("PRICEBEAN", priceBeans);
- // //通知刷新界面
- // EventBus.getDefault().post(new ApiMessageEvent(kind, null));
- // }
- // }
- @Override
- public void onReceiveOnlineState(Context context, boolean b) {
- Log.e(TAG, "onReceiveOnlineState: " + b);
- }
- @Override
- public void onReceiveCommandResult(Context context, GTCmdMessage gtCmdMessage) {
- Log.e(TAG, "onReceiveCommandResult: ");
- }
- @Override
- public void onNotificationMessageArrived(Context context, GTNotificationMessage gtNotificationMessage) {
- Log.e(TAG, "onNotificationMessageArrived: ");
- }
- @Override
- public void onNotificationMessageClicked(Context context, GTNotificationMessage gtNotificationMessage) {
- Log.e(TAG, "onNotificationMessageClicked: ");
- }
- // @Subscribe(threadMode = ThreadMode.MAIN)
- // public void event(DownLoadMessageEvent messageEvent) {
- // switch (messageEvent.getType()) {
- // case success:
- // //下载成功
- // // ToastUtil.showToast("下载成功");
- // LogUtil.d(TAG, "event: 下载成功" + messageEvent.getData());
- // if (currentIndex == timeDatas.size() - 1) {
- // //最后一个下载完 保存数据
- // currentIndex = 0;
- // Hawk.put("showAd",getAdBeans);
- // saveShowAdData();
- //
- // LogUtil.d(TAG, "event: 保存完成广告数据1:"+getAdBeans);
- // //ui
- // EventBus.getDefault().post(new DownLoadMessageEvent(DownLoadMessageEvent.Type.downloadAll,""));
- // return;
- // }
- // if (currentIndex < timeDatas.size()) {
- // currentIndex++;
- // downLoadFile(currentIndex, timeDatas.get(currentIndex).getAdType(), timeDatas);
- //
- // }
- // break;
- // case failed:
- // //下载失败
- // ToastUtil.showToast("下载失败" + messageEvent.getData());
- // LogUtil.d(TAG, "event: 下载失败" + messageEvent.getData());
- // if (currentIndex < timeDatas.size()) {
- // if (currentIndex >= timeDatas.size()) {
- // return;
- // }
- // //添加下载失败的数据
- // downloadFailedIndex.add(timeDatas.get(currentIndex).getUrl());
- //
- // if (currentIndex == timeDatas.size() - 1) {
- // //最后一个下载完
- // //mPresenter.getLocalData();
- // currentIndex = 0;
- // //保存数据
- // Hawk.put("showAd",getAdBeans);
- // saveShowAdData();
- // LogUtil.d(TAG, "event: 保存完成的广告数据2:"+getAdBeans);
- // EventBus.getDefault().post(new DownLoadMessageEvent(DownLoadMessageEvent.Type.downloadAll,""));
- // return;
- // }
- // currentIndex++;
- // downLoadFile(currentIndex, timeDatas.get(currentIndex).getAdType(), timeDatas);
- //
- // }
- // break;
- // default:
- // break;
- //
- // }
- // }
- // /**
- // * 下载完成 广告界面默认显示全部
- // */
- // private void saveShowAdData() {
- // //填充改变名字的
- // timeDatas=new ArrayList<>();
- //
- // for (int i=0;i<getAdBeans.size();i++){
- // GetAdBean getAdBean = getAdBeans.get(i);
- // long createDate = getAdBean.getCreateDate();
- // String time = TimeUtil.getNoTime(createDate);
- // String name = getAdBean.getName();
- // getAdBean.setName(name);
- // timeDatas.add(getAdBean);
- // }
- // //下载完成 全部默认显示
- // for (int i=0;i<timeDatas.size();i++){
- // showSugar.put(i, timeDatas.get(i));
- // showOut.put(i, timeDatas.get(i));
- // }
- // }
- private CompositeDisposable mDisposables;
- private IView view;
- protected void addSubscription(Observable observable, DisposableObserver observer) {
- if (mDisposables == null) {
- mDisposables = new CompositeDisposable();
- }
- observable
- .unsubscribeOn(Schedulers.io())
- .subscribeOn(Schedulers.io())
- .observeOn(AndroidSchedulers.mainThread())
- .subscribe(observer);
- mDisposables.add(observer);
- }
- protected void addSubscriptionNew(Observable observable,Class clazz, DisposableObserver observer) {
- if (mDisposables == null) {
- mDisposables = new CompositeDisposable();
- }
- if (clazz == HttpResult.class) {
- observable = observable.compose(HttpResultHandler.<String>transformer());
- }
- observable
- .unsubscribeOn(Schedulers.io())
- .subscribeOn(Schedulers.io())
- .observeOn(AndroidSchedulers.mainThread())
- .subscribe(observer);
- mDisposables.add(observer);
- }
- // /**
- // * 下载文件
- // *
- // * @param index 下载索引 第几个
- // * @param type 没有
- // * @param datas 要下载数据列表
- // */
- // private void downLoadFile(int index, String type, ArrayList<GetAdBean> datas) {
- // //开始下载
- // Intent downloadApkIntent = new Intent(getApplicationContext(), DownServer.class);
- // Bundle bundle = new Bundle();
- // GetAdBean getAdBean = datas.get(index);
- // String url = getAdBean.getUrl();
- // String type1 = url.substring(url.lastIndexOf(".") + 1);
- // bundle.putString("downloadUrl", url);
- // String time = TimeUtil.getNoTime(getAdBean.getCreateDate());
- // LogUtil.d(TAG, "downLoadFile: time=" + time);
- // bundle.putString("title", getAdBean.getName());
- // bundle.putString("downloadtype", type1);
- // downloadApkIntent.putExtra("download", bundle);
- // getApplicationContext().startService(downloadApkIntent);
- // }
- @Override
- public void onDestroy() {
- super.onDestroy();
- EventBus.getDefault().unregister(this);
- }
- //---------------plc开关机-------------------
- private void openOrClose(Gson gson, BaseBean baseBean, String kind) {
- String kind_data = baseBean.getKind_data();
- Log.d(TAG, "openOrClose: " + baseBean);
- isSetSuccess = false;
- isRstSuccess = false;
- if ((int) SharedPreferencesUtils.getParam(Name.toComplete, 0) == 1) {
- Global.isSave = true;
- }
- if (kind_data.equals("0")) {
- EventBus.getDefault().post(new ApiMessageEvent(Name.OFFTIME, "关机"));
- // Global.temperatureGoUp = 1;
- //关机
- // startTimerSet("M25");
- } else if (kind_data.equals("1")) {
- //开机
- // startTimerSet("M3");
- EventBus.getDefault().post(new ApiMessageEvent(Name.BOOTIME, "开机"));
- // Global.temperatureGoUp = 0;
- }
- }
- private Timer timerSet;
- private TimerTask timerTaskSet;
- //是否置为成功
- private boolean isSetSuccess = false;
- private Timer timerRst;
- private TimerTask timerTaskRst;
- //是否复位成功
- private boolean isRstSuccess = false;
- // private void startTimerSet(final String address) {
- // SerialPortSendQueue.clear();
- // timerSet = new Timer();
- // timerTaskSet = new TimerTask() {
- // @Override
- // public void run() {
- // if (!isSetSuccess) {
- //
- // SerialPortSendQueue.sendCommand(new SetCommandFrame(address), Address.ID_M8, "MM" + address);
- // LogUtil.d(TAG, "run: " + "MM" + address);
- // }
- // }
- // };
- // timerSet.schedule(timerTaskSet, 0, 500);
- // }
- // private void stopTimerSet() {
- // SerialPortSendQueue.clear();
- // if (timerSet != null) {
- // timerTaskSet.cancel();
- // timerSet.cancel();
- // timerSet = null;
- // }
- // }
- // private void startTimerRst(final String address) {
- // SerialPortSendQueue.clear();
- // timerRst = new Timer();
- // timerTaskRst = new TimerTask() {
- // @Override
- // public void run() {
- // if (!isRstSuccess) {
- //
- // SerialPortSendQueue.sendCommand(new RstCommandFrame(address), Address.ID_M8, "MMM" + address);
- // LogUtil.d(TAG, "run: " + "MMM" + address);
- // }
- //
- // }
- // };
- // timerRst.schedule(timerTaskRst, 0, 500);
- // }
- // private void stopTimerRst() {
- // SerialPortSendQueue.clear();
- // if (timerRst != null) {
- // timerTaskRst.cancel();
- // timerRst.cancel();
- // timerRst = null;
- // }
- // }
- @Subscribe(threadMode = ThreadMode.MAIN)
- public void event(ApiMessageEvent messageEvent) {
- // mOpen = (Integer) SharedPreferencesUtils.getParam("open", 1);
- // LogUtil.d(TAG, "eventtime: "+mOpen);
- // switch (messageEvent.getName()) {
- // case Name.OFFTIME:
- // LogUtil.d(TAG, "event: offtime:" + mOpen);
- // if (mOpen != 0) {
- // openOrClose("off");
- // }
- // break;
- // case Name.BOOTIME:
- // LogUtil.d(TAG, "event: boottime:" + mOpen);
- // openOrClose("boot");
- // break;
- // }
- }
- // private void openOrClose(String data) {
- // isSetSuccess = false;
- // isRstSuccess = false;
- // if ((int) SharedPreferencesUtils.getParam(Name.toComplete, 0) == 1) {
- // Global.isSave = true;
- // }
- // if (data.equals("off")) {
- // //关机
- // startTimerSet("M25");
- // } else if (data.equals("boot")) {
- // //开机
- // startTimerSet("M3");
- // }
- // }
- @Subscribe(threadMode = ThreadMode.MAIN)
- public void event(Message messageEvent) {
- switch (messageEvent.getType()) {
- case connected:
- Logger.d("connected");
- case sendError:
- Logger.d("sendError");
- case ack:
- Log.w(TAG, TAG + "写入event: ack:id=" + messageEvent.getId() + " name=" + messageEvent.getName());
- int id = messageEvent.getId();
- String name = messageEvent.getName();
- //名字相等,写入成功
- // stopTimerSet();
- // stopTimerRst();
- // stopTimerOpenDoor();
- /* if (name.equals("MMM25")) {
- //shut down success
- //stopTimerSet();
- isSetSuccess = true;
- stopTimerSet();
- ToastUtil.showToast("shutdown success ");
- Log.e(TAG, "event: 关机成功");
- //保存开关机状态
- SharedPreferencesUtils.setParam("open", 0);
- updateEqeStatus((Integer) SharedPreferencesUtils.getParam("open", 0));
- updateEqeStatus(0);
- // try {
- // Thread.sleep(100*5);
- // } catch (InterruptedException e) {
- // e.printStackTrace();
- // }
- // SerialPortSendQueue.clear();
- // SerialPortSendQueue.sendCommand(new RstCommandFrame("M25"), Address.ID_M8, "MM25");
- // startTimerRst("M25");
- } else if (name.equals("MMM3")) {
- //open success
- //stopTimerRst();
- // showLoading();
- isSetSuccess = true;
- stopTimerSet();
- LogUtil.d(TAG, "event11: ");
- SharedPreferencesUtils.setParam("open", 1);
- SharedPreferencesUtils.setParam("isOpenReadWarring", true);
- updateEqeStatus((Integer) SharedPreferencesUtils.getParam("open", 0));
- ToastUtil.showToast("open success");
- updateEqeStatus(1);
- // try {
- // Thread.sleep(3*1000);
- // } catch (InterruptedException e) {
- // e.printStackTrace();
- // }
- LogUtil.d(TAG, "event22: ");
- // startTimerRst("M3");
- // SerialPortSendQueue.clear();
- // SerialPortSendQueue.sendCommand(new RstCommandFrame("M3"), Address.ID_M8, "MM3");
- } else if (name.equals("MMMM25")) {
- isRstSuccess = true;
- stopTimerRst();
- // ToastUtil.showToast("shutdown success ");
- // Log.e(TAG, "event: 关机成功");
- // //保存开关机状态
- // SharedPreferencesUtils.setParam("open",0);
- // updateEqeStatus(0);
- } else if (name.equals("MMMM3")) {
- // if (loadingDialog!=null){
- // loadingDialog.dismiss();
- // }
- isRstSuccess = true;
- Log.e(TAG, "event: 开机成功");
- stopTimerRst();
- // SharedPreferencesUtils.setParam("open",1);
- // ToastUtil.showToast("open success");
- // updateEqeStatus(1);
- } else*/
- if (name.equals(address)) {
- isWreiteSuccess = true;
- stopTimerWrite();
- }
- break;
- case nak:
- Logger.d("nak");
- case disconnected:
- Logger.d("disconnected");
- showToast(messageEvent.getContent().toString());
- break;
- case response:
- break;
- }
- }
- public void updateEqeStatus(int type) {
- new Thread(new Runnable() {
- @Override
- public void run() {
- URL url = null;// 取得资源对象bai
- try {
- url = new URL("http://time.tianqi.com/");
- URLConnection uc = url.openConnection();// 生成连接du对象
- uc.connect(); // 发出连接
- long ld = uc.getDate(); // 取得网站日期时间
- Log.d(TAG, "执行updateEqeStatus: " + ld);
- Map<String, Object> map = new HashMap<>();
- map.put("clientId", Heartbeat.deviceId);
- map.put("eqeStatus", type);
- map.put("netTime", ld + "");
- addSubscriptionNew(NoPayOrderStringApi.api.updateEqeStatusNew(map),String.class,
- new HttpResultNotActivityObserver<String>(view, getApplicationContext()) {
- @Override
- public void onNext(String o) {
- LogUtil.d(TAG, "开关机状态上传成功onError: ");
- }
- @Override
- public void onError(Throwable t) {
- super.onError(t);
- BaseException exception = ExceptionFactory.create(t);
- showToast(exception.getErrorText());
- LogUtil.d(TAG, "上传错误onError: ");
- }
- });
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }).start();
- }
- //---------------plc开关机-------------------
- //---------------写-------------------
- private Timer timerWrite;
- private TimerTask timerTaskWrite;
- private boolean isWreiteSuccess;
- private String address;
- // private void startTimerWtire(final String address, final String bin) {
- // this.address = address;
- // timerWrite = new Timer();
- // SerialPortSendQueue.clear();
- // timerTaskWrite = new TimerTask() {
- // @Override
- // public void run() {
- // if (!isWreiteSuccess) {
- // SerialPortSendQueue.sendCommand(new WriteCommandFrame(address, bin), 400, address);
- // }
- // }
- // };
- // timerWrite.schedule(timerTaskWrite, 0, 1000);
- // }
- private void stopTimerWrite() {
- if (timerWrite != null) {
- timerTaskWrite.cancel();
- timerWrite.cancel();
- timerTaskWrite = null;
- timerWrite = null;
- }
- }
- }
- /*
- {"adType":"视频","createDate":1586508896000,"duration":1,"id":94,"locationType":"外接广告","mediaPreview":"http://.png","name":"MG320棉花糖小孩篇","order":1,"screenType":1,"url":"http://.mp4"},
- {"adType":"视频","createDate":1586509052000,"duration":1,"id":95,"locationType":"外接广告","mediaPreview":"http://.png","name":"MG320棉花糖情侣篇","order":1,"screenType":1,"url":"http://.mp4"},
- {"adType":"视频","createDate":1599721965000,"duration":1,"id":102,"locationType":"棉花糖宣传广告","mediaPreview":"http://4.png","name":"MG320videonew","order":1,"screenType":0,"url":"http://.mp4"},
- {"adType":"视频","createDate":1599722000000,"duration":1,"id":103,"locationType":"外接广告","mediaPreview":"http://.png","name":"MG320videonew2","order":1,"screenType":1,"url":"http:/.mp4"}]
- */
- /*
- 現在我的需求就是,我希望棉花糖宣传广告也可以进行规则的限制,可以不限制实现,但是必须显示播放的视频。
- */
|