| | |
| | | package com.dayu.recharge; |
| | | |
| | | import android.app.Application; |
| | | import android.nfc.Tag; |
| | | import android.os.Handler; |
| | | import android.os.Message; |
| | | import android.text.TextUtils; |
| | |
| | | import com.dayu.recharge.dao.BaseDaoSingleton; |
| | | import com.dayu.recharge.dbBean.DeviceNumber; |
| | | import com.dayu.recharge.dbBean.IpBean; |
| | | import com.dayu.recharge.utils.DeviceNumberUtils; |
| | | import com.dayu.recharge.utils.ToastUtil; |
| | | import com.easysocket.EasySocket; |
| | | import com.easysocket.config.EasySocketOptions; |
| | |
| | | import java.util.TimerTask; |
| | | |
| | | public class MyApplication extends Application { |
| | | |
| | | public static String TAG = "MyApplication"; |
| | | public static MyApplication myApplication; |
| | | private String address; |
| | | |
| | |
| | | myApplication = this; |
| | | isAidl = true; |
| | | AidlUtil.getInstance().connectPrinterService(this); |
| | | initEasySocket(false, null); |
| | | |
| | | // initEasySocket(false, null); |
| | | |
| | | CrashReport.initCrashReport(getApplicationContext(), "45551598b8", true); |
| | | } |
| | |
| | | if (!TextUtils.isEmpty(ip) |
| | | && !TextUtils.isEmpty(String.valueOf(port)) |
| | | && !TextUtils.isEmpty(addressCode)) { |
| | | |
| | | Log.i("initMachineRequestBean", "开始注册设备"); |
| | | if (EasySocket.getInstance().getDefconnection() != null) { |
| | | isDoInitMachine = true; |
| | | InitMachineRequestBean initMachineRequestBean = new InitMachineRequestBean(); |
| | |
| | | initMachineRequestBean.setAddress(addressCode); |
| | | initMachineRequestBean.setXuLie(SocketUtil.getXuLie(this)); |
| | | initMachineRequestBean.setAFN("91"); |
| | | // |
| | | Log.i("Socket", "注册报文"); |
| | | SocketNet.getInstance().sendTestMessage(initMachineRequestBean.pack(), new SocketCallBack() { |
| | | @Override |
| | | public void onSocketResponse(SocketData readData) { |
| | |
| | | if (CRC8.isCRC8(readData.getOriginDataBytes())) { |
| | | //校验CRC成功 |
| | | InitMachineBackBean initMachineBackBean = new InitMachineBackBean(); |
| | | |
| | | String initCode = HexUtil.bytesToHex(Arrays.copyOfRange(readData.getBodyBytes(), 2, 18)); |
| | | //确认收到注册号报文 |
| | | ConfirmMachineRequestBean confirmMachineRequestBean = new ConfirmMachineRequestBean(); |
| | |
| | | //BCD码00成功01失败(注册号不是服务器返回信息) |
| | | if (state.equalsIgnoreCase("00")) { |
| | | //保存设备注册号 |
| | | DeviceNumber deviceNumber = BaseDaoSingleton.getInstance(MyApplication.myApplication).deviceNumberDao().findFirst(); |
| | | if (deviceNumber != null) { |
| | | deviceNumber.setDeviceRegistrationNumber(initCode); |
| | | } else { |
| | | deviceNumber = new DeviceNumber(); |
| | | deviceNumber.setDeviceRegistrationNumber(initCode); |
| | | if (!TextUtils.isEmpty(initCode)){ |
| | | DeviceNumberUtils.setDeviceNumber(initCode); |
| | | } |
| | | BaseDaoSingleton.getInstance(MyApplication.myApplication).deviceNumberDao().insert(deviceNumber); |
| | | |
| | | Log.i(TAG, "onSuccess: 设备注册号:" + initCode); |
| | | // WSHelper.getInstance(MyApplication.this).put("initCode", initCode); |
| | | ToastUtil.show("充值管理注册报文获取成功"); |
| | | } else { |
| | |
| | | }); |
| | | |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | private void createSocket(String ip, int port) { |