dianxin-guizhou-forward
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

CenterApplicationTests.java 8.3KB

vor 4 Jahren
vor 4 Jahren
vor 4 Jahren
vor 4 Jahren
vor 4 Jahren
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. package com.ssjl.zhaobiao.guizhou;
  2. import com.ssjl.zhaobiao.guizhou.entity.*;
  3. import com.ssjl.zhaobiao.guizhou.entity.GZMessage.GZLocation;
  4. import com.ssjl.zhaobiao.guizhou.entity.GZMessage.GZLocationCDMA;
  5. import com.ssjl.zhaobiao.guizhou.entity.GZMessage.GZLocationExtend;
  6. import com.ssjl.zhaobiao.guizhou.entity.GZMessage.GZLocationInterval;
  7. import com.ssjl.zhaobiao.guizhou.utils.ByteUtil;
  8. import com.ssjl.zhaobiao.guizhou.utils.GZUtil;
  9. import com.ssjl.zhaobiao.guizhou.utils.OkHttpUtil;
  10. import com.ssjl.zhaobiao.guizhou.utils.UnicodeUtil;
  11. import okhttp3.Headers;
  12. import okhttp3.internal.http2.Header;
  13. import org.junit.jupiter.api.Test;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.boot.test.context.SpringBootTest;
  16. import java.io.IOException;
  17. import java.time.LocalDateTime;
  18. import java.util.HashMap;
  19. import java.util.List;
  20. import java.util.Map;
  21. @SpringBootTest
  22. class CenterApplicationTests {
  23. //
  24. // @Test
  25. // void contextLoads() {
  26. // }
  27. // private String QUEUE_NAME = "TuoYuMq";
  28. // private static final String EXCHANGE_NAME = "TuoYu";
  29. //
  30. // @Autowired
  31. // TyMqManager mqManager;
  32. //
  33. // @Test
  34. // void TestMq() throws IOException {
  35. // QzhTemperatureData data = new QzhTemperatureData();
  36. // data.setClassId(1);
  37. // data.setDeviceId(333333);
  38. // data.setId(1234567890);
  39. // data.setSchId(333);
  40. // data.setStuId(111);
  41. // data.setTemperature(388);
  42. // data.setTime(new Date());
  43. // mqManager.sendData(data);
  44. //
  45. // int i = System.in.read();
  46. // }
  47. //
  48. // @Test
  49. // void SendToMq() throws IOException, TimeoutException {
  50. // // 创建连接工厂
  51. // ConnectionFactory factory = new ConnectionFactory();
  52. //// 设置RabbitMQ地址
  53. // factory.setHost("localhost");
  54. //// 创建一个新的连接
  55. // Connection connection = factory.newConnection();
  56. //// 创建一个频道
  57. // Channel channel = connection.createChannel();
  58. // channel.exchangeDeclare(EXCHANGE_NAME, "fanout");
  59. // // 声明队列需要持久化
  60. // boolean durable = true;
  61. //// 声明一个队列 -- 在RabbitMQ中,队列声明是幂等性的(一个幂等操作的特点是其任意多次执行所产生的影响均与一次执行的影响相同),也就是说,如果不存在,就创建,如果存在,不会对已经存在的队列产生任何影响。
  62. // channel.queueDeclare(QUEUE_NAME, durable, false, false, null);
  63. // // 绑定队列与交换器
  64. // channel.queueBind(QUEUE_NAME, EXCHANGE_NAME, "");
  65. // for (int i = 0; i < 50; i++) {
  66. // String message = "Hello World!" + i;
  67. // // 发送消息到队列中
  68. //// channel.basicPublish("", QUEUE_NAME, null, message.getBytes("UTF-8"));
  69. //// channel.basicPublish("", QUEUE_NAME,
  70. //// MessageProperties.PERSISTENT_TEXT_PLAIN,
  71. //// message.getBytes());
  72. // channel.basicPublish(EXCHANGE_NAME, "",
  73. // MessageProperties.PERSISTENT_TEXT_PLAIN,
  74. // message.getBytes());
  75. // System.out.println("P [x] Sent '" + message + "'");
  76. // }
  77. // // 关闭频道和连接
  78. // channel.close();
  79. // connection.close();
  80. // }
  81. // @Test
  82. // void receiveFromMq() throws IOException, TimeoutException {
  83. // mqReceive(1);
  84. // mqReceive(2);
  85. // mqReceive(3);
  86. // mqReceive(4);
  87. // int i = System.in.read();
  88. // System.out.println(i);
  89. // }
  90. //
  91. // private void mqReceive(int i) throws IOException, TimeoutException {
  92. // // 创建连接工厂
  93. // ConnectionFactory factory = new ConnectionFactory();
  94. //// 设置RabbitMQ地址
  95. // factory.setHost("localhost");
  96. //// 创建一个新的连接
  97. // final Connection connection = factory.newConnection();
  98. //// 创建一个频道
  99. // final Channel channel = connection.createChannel();
  100. //// 声明要关注的队列 -- 在RabbitMQ中,队列声明是幂等性的(一个幂等操作的特点是其任意多次执行所产生的影响均与一次执行的影响相同),也就是说,如果不存在,就创建,如果存在,不会对已经存在的队列产生任何影响。
  101. // channel.queueDeclare(QUEUE_NAME, true, false, false, null);
  102. // System.out.println("C [*] Waiting for messages. To exit press CTRL+C");
  103. //
  104. // // 每次从队列中获取数量
  105. // channel.basicQos(1);
  106. //
  107. //// DefaultConsumer类实现了Consumer接口,通过传入一个频道,告诉服务器我们需要那个频道的消息,如果频道中有消息,就会执行回调函数handleDelivery
  108. // final Consumer consumer = new DefaultConsumer(channel) {
  109. // @SneakyThrows
  110. // @Override
  111. // public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
  112. // String message = new String(body, "UTF-8");
  113. // System.out.println("C " + i + " [x] Received '" + message + "'");
  114. // try {
  115. // Thread.sleep(1000);
  116. // }finally {
  117. // // 消息处理完成确认
  118. // channel.basicAck(envelope.getDeliveryTag(), false);
  119. // }
  120. // }
  121. // };
  122. //// 自动回复队列应答 -- RabbitMQ中的消息确认机制,后面章节会详细讲解
  123. // channel.basicConsume(QUEUE_NAME, false, consumer);
  124. // }
  125. @Autowired
  126. OkHttpUtil httpUtil;
  127. @Test
  128. void test(){
  129. // String imei = "A12345678901234";
  130. // byte[] b = byteUtil.imeiToByte(imei);
  131. // System.out.println(byteUtil.bytesToHexString(b));
  132. // imei = "1330571234567890";
  133. // b = byteUtil.imeiToByte(imei);
  134. // System.out.println(byteUtil.bytesToHexString(b));
  135. // byte b = gzUtil.requestStatus(GZRequestStatus.RESPONSE_NO);
  136. // System.out.println(b);
  137. // b = gzUtil.requestStatus(GZRequestStatus.RESPONSE_ALL);
  138. // System.out.println(b);
  139. // b = gzUtil.requestStatus(GZRequestStatus.RESPONSE_ERROR);
  140. // System.out.println(b);
  141. // byte[] b = new byte[10];
  142. // b[0] = (byte)128;
  143. // b[1] = (byte)127;
  144. // b[2] = (byte)1;
  145. // b[3] = (byte)256;
  146. // b[4] = (byte)255;
  147. // System.out.println( gzUtil.check(b));
  148. GZRequest req = new GZRequest();
  149. req.setImei("862622050253671");
  150. req.setIndex(GZUtil.getMessageIndex());
  151. req.setStatus(GZRequestStatus.RESPONSE_NO);
  152. GZLocationCDMA cdma = new GZLocationCDMA();
  153. GZLocationExtend extend = new GZLocationExtend();
  154. extend.setNetType(GZNetType.CDMA);
  155. extend.setData1(cdma);
  156. byte[] bid = { 0x00, 0x02 };
  157. cdma.setBID(bid);
  158. byte[] sid = {0x22, 0x41};
  159. cdma.setSID(sid);
  160. byte[] nid = { 0x36, 0x14};
  161. cdma.setNID(nid);
  162. GZDeviceStatus deviceStatus = new GZDeviceStatus();
  163. // deviceStatus.setOpenFirst(true);
  164. GZDevicePower power = new GZDevicePower();
  165. power.setCharge(false);
  166. power.setPower(80);
  167. GZLocation location = new GZLocation(9, 11,11, 7,
  168. 13817426, 0, 67901974, 0, 5, 90,
  169. deviceStatus, power, 70, 3, false, extend);
  170. req.setContent(location);
  171. byte[] b = req.toByte();
  172. System.out.println(ByteUtil.bytesToHexString(b));
  173. //
  174. // Headers headers = new Headers.Builder().add("meid-id", "862622050253671").add("imsi-id", "18664272743").build();
  175. // try {
  176. // byte[] res = httpUtil.postBytes("http://202.105.147.30:24183", b, headers);
  177. // System.out.println(ByteUtil.bytesToHexString(res));
  178. // } catch (IOException e) {
  179. // e.printStackTrace();
  180. // }
  181. }
  182. @Test
  183. public void test2(){
  184. String str = "6572726f72206c656e";
  185. byte[] b = ByteUtil.hexToByteArray(str);
  186. System.out.println(new String(b));
  187. }
  188. @Test
  189. public void test3(){
  190. List<GZLocationInterval> interval = GZLocationInterval.build("1/0600220003,234567/0700160005");
  191. boolean in = GZLocationInterval.isIn(LocalDateTime.of(2021, 1 , 13, 23,22, 49), interval);
  192. System.out.println(in);
  193. }
  194. @Test
  195. public void test4(){
  196. Map<String, Integer> map = new HashMap<>();
  197. map.put("abc", 2);
  198. map.put("abc", 3);
  199. }
  200. }