HttpTool.java 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. package http.client;
  2. import android.net.Uri;
  3. import android.util.Log;
  4. import com.blankj.utilcode.util.AppUtils;
  5. import com.blankj.utilcode.util.GsonUtils;
  6. import com.blankj.utilcode.util.LogUtils;
  7. import com.blankj.utilcode.util.ShellUtils;
  8. import com.hikvision.dmb.EthernetConfig;
  9. import com.hikvision.dmb.network.InfoNetworkApi;
  10. import com.hikvision.dmb.system.InfoSystemApi;
  11. import com.hikvision.dmb.util.InfoUtilApi;
  12. import http.OkHttpUtils;
  13. import http.vo.request.TerminalAuthReq;
  14. import org.json.JSONException;
  15. import org.json.JSONObject;
  16. import java.io.BufferedReader;
  17. import java.io.ByteArrayInputStream;
  18. import java.io.IOException;
  19. import java.io.InputStreamReader;
  20. import okhttp3.Response;
  21. import xn.xxp.app.LabApp;
  22. import xn.xxp.home.auth.AuthType;
  23. import xn.xxp.room.RoomTool;
  24. import xn.xxp.room.bean.DeviceConfig;
  25. import xn.xxp.room.bean.LabConfig;
  26. import xn.xxp.utils.Tool;
  27. public final class HttpTool {
  28. public static Response terminalAuth(String devId) throws IOException {
  29. TerminalAuthReq terminalAuthReq = new TerminalAuthReq();
  30. terminalAuthReq.setDeviceCode(devId);
  31. terminalAuthReq.setCode("aio_infobord");
  32. DeviceConfig deviceConfig = RoomTool.getInstance().deviceConfigDao().getDeviceConfig();
  33. return OkHttpUtils.postSync(deviceConfig.getBaseUrl() + "terminal/authorize", GsonUtils.toJson(terminalAuthReq));
  34. }
  35. public static Response queryLabConfig(String devId) throws IOException {
  36. DeviceConfig deviceConfig = RoomTool.getInstance().deviceConfigDao().getDeviceConfig();
  37. return OkHttpUtils.getSync(deviceConfig.getBaseUrl() + "terminal/lab/getSubjectIdByNum/" + devId);
  38. }
  39. public static String checkUrl(String url) {
  40. try {
  41. String uriStr = url;
  42. if (!url.matches("https?://.*") && !url.matches("http?://.*")) {
  43. DeviceConfig deviceConfig = RoomTool.getInstance().deviceConfigDao().getDeviceConfig();
  44. uriStr = Uri.parse(deviceConfig.getBaseUrl() + url).toString();
  45. }
  46. return uriStr;
  47. } catch (Exception e) {
  48. LogUtils.e(Log.getStackTraceString(e));
  49. return url;
  50. }
  51. }
  52. /**
  53. * 拉取人脸特征值(人员资料 + 特征值二进制)。
  54. */
  55. public static Response getLabFaceFeatureList() {
  56. try {
  57. DeviceConfig deviceConfig = RoomTool.getInstance().deviceConfigDao().getDeviceConfig();
  58. LabConfig labConfig = RoomTool.getInstance().labConfigDao().getLabConfig();
  59. JSONObject jsonObject = new JSONObject();
  60. jsonObject.put("subId", labConfig.getLabId());
  61. return OkHttpUtils.postSync(deviceConfig.getBaseUrl() + "terminal/sys/face/data/subFeature", jsonObject.toString(), 300000);
  62. } catch (Exception e) {
  63. LogUtils.e(Log.getStackTraceString(e));
  64. }
  65. return null;
  66. }
  67. public static Response getRectifyAdviceNoteView(String noticeId) throws IOException {
  68. DeviceConfig deviceConfig = RoomTool.getInstance().deviceConfigDao().getDeviceConfig();
  69. return OkHttpUtils.getSync(deviceConfig.getBaseUrl() + "terminal/sec/getRectifyAdviceNoteView?noticeId=" + noticeId);
  70. }
  71. public static Response getLabStatusById(String labId, String userId) throws IOException {
  72. DeviceConfig deviceConfig = RoomTool.getInstance().deviceConfigDao().getDeviceConfig();
  73. return OkHttpUtils.getSync(deviceConfig.getBaseUrl() + "terminal/lab/getLabStatusById?labId=" + labId + "&userId=" + userId);
  74. }
  75. public static Response heartbeat(String devId) throws IOException {
  76. DeviceConfig deviceConfig = RoomTool.getInstance().deviceConfigDao().getDeviceConfig();
  77. return OkHttpUtils.getSync(deviceConfig.getBaseUrl() + "terminal/device/aio/heartbeat?deviceNo=" + devId);
  78. }
  79. public static Response bigDevSignIn(String labId, String userId) throws IOException {
  80. DeviceConfig deviceConfig = RoomTool.getInstance().deviceConfigDao().getDeviceConfig();
  81. return OkHttpUtils.getSync(deviceConfig.getBaseUrl() + "terminal/lab/onemachine/daYiSignIn?labId=" + labId + "&userId=" + userId);
  82. }
  83. /**
  84. * 设备状态
  85. *
  86. * @param metrics json字符串 记录设备状态
  87. */
  88. public static Response deviceStatus(String devId, String metrics) {
  89. try {
  90. JSONObject jsonObject = new JSONObject();
  91. jsonObject.put("deviceNo", devId);
  92. jsonObject.put("metrics", metrics);
  93. DeviceConfig deviceConfig = RoomTool.getInstance().deviceConfigDao().getDeviceConfig();
  94. return OkHttpUtils.postSync(deviceConfig.getBaseUrl() + "terminal/device/aio/upload/status", jsonObject.toString());
  95. } catch (Exception e) {
  96. LogUtils.e(Log.getStackTraceString(e));
  97. }
  98. return null;
  99. }
  100. /**
  101. * 远程开锁发送状态
  102. */
  103. public static Response remoteUnlock(long messageId) {
  104. try {
  105. JSONObject jsonObject = new JSONObject();
  106. jsonObject.put("messageId", messageId);
  107. jsonObject.put("status", 1);
  108. DeviceConfig deviceConfig = RoomTool.getInstance().deviceConfigDao().getDeviceConfig();
  109. return OkHttpUtils.postSync(deviceConfig.getBaseUrl() + "terminal/lock/callback", jsonObject.toString());
  110. } catch (Exception e) {
  111. LogUtils.e(Log.getStackTraceString(e));
  112. }
  113. return null;
  114. }
  115. /**
  116. * 进出记录和授权记录配置
  117. *
  118. * @param openType 开门类型
  119. * @return
  120. */
  121. public static Response updateRecord(String userId, AuthType openType) {
  122. try {
  123. JSONObject jsonObject = new JSONObject();
  124. LabConfig labConfig = RoomTool.getInstance().labConfigDao().getLabConfig();
  125. jsonObject.put("subId", labConfig.getLabId());
  126. jsonObject.put("userId", userId);
  127. jsonObject.put("openType", openType.getType());
  128. DeviceConfig deviceConfig = RoomTool.getInstance().deviceConfigDao().getDeviceConfig();
  129. String json = jsonObject.toString();
  130. LogUtils.d("updateRecord", json);
  131. return OkHttpUtils.postSync(deviceConfig.getBaseUrl() + "laboratory/app/board/updateRecord", jsonObject.toString());
  132. } catch (Exception e) {
  133. LogUtils.e("updateRecord", Log.getStackTraceString(e));
  134. }
  135. return null;
  136. }
  137. /**
  138. * 查询二维码登录状态
  139. *
  140. * @param code 时间
  141. */
  142. public static Response infoBordLogin(String devId, String code) throws IOException {
  143. DeviceConfig deviceConfig = RoomTool.getInstance().deviceConfigDao().getDeviceConfig();
  144. return OkHttpUtils.getSync(deviceConfig.getBaseUrl() + "terminal/lab/infobordLogin?macId=" + devId + "&code=" + code);
  145. }
  146. public static Response heartbeat() throws JSONException, IOException {
  147. DeviceConfig deviceConfig = RoomTool.getInstance().deviceConfigDao().getDeviceConfig();
  148. JSONObject jsonObject = new JSONObject();
  149. ShellUtils.CommandResult commandResult = ShellUtils.execCmd("dumpsys activity activities", true);
  150. BufferedReader reader = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(commandResult.successMsg.getBytes())));
  151. String line;
  152. boolean isShow = false;
  153. while ((line = reader.readLine()) != null) {
  154. if (line.contains("mResumedActivity") || line.contains("mCurrentFocus")) {
  155. String[] itemArray = line.split(" ", -1);
  156. for (String item : itemArray) {
  157. if (item.contains("/")) {
  158. String packageName = item.substring(0, item.indexOf("/"));
  159. isShow = AppUtils.getAppPackageName().equals(packageName);
  160. break;
  161. }
  162. }
  163. break;
  164. }
  165. }
  166. boolean adbEnabled = (1 == InfoSystemApi.getAdbStatus());
  167. EthernetConfig ethernetConfig = InfoNetworkApi.getEthernetConfig();
  168. // Ip
  169. String ip = ethernetConfig.getIpAddress();
  170. jsonObject.put("deviceNo", "EBOARD_" + InfoSystemApi.getSerialNumber());
  171. jsonObject.put("versionName", AppUtils.getAppVersionName());
  172. jsonObject.put("packageName", AppUtils.getAppPackageName());
  173. jsonObject.put("isShow", isShow);
  174. jsonObject.put("adbEnabled", adbEnabled);
  175. jsonObject.put("ip", ip);
  176. String json = jsonObject.toString();
  177. LogUtils.d(json);
  178. return OkHttpUtils.postSync(deviceConfig.getBaseUrl() + "terminal/machine/heartbeat", json);
  179. }
  180. }