|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- package com.ssjl.zhaobiao.guizhou;
-
- import com.ssjl.zhaobiao.guizhou.entity.*;
- import com.ssjl.zhaobiao.guizhou.entity.GZMessage.GZLocation;
- import com.ssjl.zhaobiao.guizhou.entity.GZMessage.GZLocationCDMA;
- import com.ssjl.zhaobiao.guizhou.entity.GZMessage.GZLocationExtend;
- import com.ssjl.zhaobiao.guizhou.entity.GZMessage.GZLocationInterval;
- import com.ssjl.zhaobiao.guizhou.utils.ByteUtil;
- import com.ssjl.zhaobiao.guizhou.utils.GZUtil;
- import com.ssjl.zhaobiao.guizhou.utils.OkHttpUtil;
- import com.ssjl.zhaobiao.guizhou.utils.UnicodeUtil;
- import okhttp3.Headers;
- import okhttp3.internal.http2.Header;
- import org.junit.jupiter.api.Test;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.boot.test.context.SpringBootTest;
-
- import java.io.IOException;
- import java.time.LocalDateTime;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
-
- @SpringBootTest
- class CenterApplicationTests {
-
- //
- // @Test
- // void contextLoads() {
- // }
- // private String QUEUE_NAME = "TuoYuMq";
- // private static final String EXCHANGE_NAME = "TuoYu";
- //
- // @Autowired
- // TyMqManager mqManager;
- //
- // @Test
- // void TestMq() throws IOException {
- // QzhTemperatureData data = new QzhTemperatureData();
- // data.setClassId(1);
- // data.setDeviceId(333333);
- // data.setId(1234567890);
- // data.setSchId(333);
- // data.setStuId(111);
- // data.setTemperature(388);
- // data.setTime(new Date());
- // mqManager.sendData(data);
- //
- // int i = System.in.read();
- // }
- //
- // @Test
- // void SendToMq() throws IOException, TimeoutException {
- // // 创建连接工厂
- // ConnectionFactory factory = new ConnectionFactory();
- //// 设置RabbitMQ地址
- // factory.setHost("localhost");
- //// 创建一个新的连接
- // Connection connection = factory.newConnection();
- //// 创建一个频道
- // Channel channel = connection.createChannel();
- // channel.exchangeDeclare(EXCHANGE_NAME, "fanout");
- // // 声明队列需要持久化
- // boolean durable = true;
- //// 声明一个队列 -- 在RabbitMQ中,队列声明是幂等性的(一个幂等操作的特点是其任意多次执行所产生的影响均与一次执行的影响相同),也就是说,如果不存在,就创建,如果存在,不会对已经存在的队列产生任何影响。
- // channel.queueDeclare(QUEUE_NAME, durable, false, false, null);
- // // 绑定队列与交换器
- // channel.queueBind(QUEUE_NAME, EXCHANGE_NAME, "");
- // for (int i = 0; i < 50; i++) {
- // String message = "Hello World!" + i;
- // // 发送消息到队列中
- //// channel.basicPublish("", QUEUE_NAME, null, message.getBytes("UTF-8"));
- //// channel.basicPublish("", QUEUE_NAME,
- //// MessageProperties.PERSISTENT_TEXT_PLAIN,
- //// message.getBytes());
- // channel.basicPublish(EXCHANGE_NAME, "",
- // MessageProperties.PERSISTENT_TEXT_PLAIN,
- // message.getBytes());
- // System.out.println("P [x] Sent '" + message + "'");
- // }
- // // 关闭频道和连接
- // channel.close();
- // connection.close();
- // }
- // @Test
- // void receiveFromMq() throws IOException, TimeoutException {
- // mqReceive(1);
- // mqReceive(2);
- // mqReceive(3);
- // mqReceive(4);
- // int i = System.in.read();
- // System.out.println(i);
- // }
- //
- // private void mqReceive(int i) throws IOException, TimeoutException {
- // // 创建连接工厂
- // ConnectionFactory factory = new ConnectionFactory();
- //// 设置RabbitMQ地址
- // factory.setHost("localhost");
- //// 创建一个新的连接
- // final Connection connection = factory.newConnection();
- //// 创建一个频道
- // final Channel channel = connection.createChannel();
- //// 声明要关注的队列 -- 在RabbitMQ中,队列声明是幂等性的(一个幂等操作的特点是其任意多次执行所产生的影响均与一次执行的影响相同),也就是说,如果不存在,就创建,如果存在,不会对已经存在的队列产生任何影响。
- // channel.queueDeclare(QUEUE_NAME, true, false, false, null);
- // System.out.println("C [*] Waiting for messages. To exit press CTRL+C");
- //
- // // 每次从队列中获取数量
- // channel.basicQos(1);
- //
- //// DefaultConsumer类实现了Consumer接口,通过传入一个频道,告诉服务器我们需要那个频道的消息,如果频道中有消息,就会执行回调函数handleDelivery
- // final Consumer consumer = new DefaultConsumer(channel) {
- // @SneakyThrows
- // @Override
- // public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
- // String message = new String(body, "UTF-8");
- // System.out.println("C " + i + " [x] Received '" + message + "'");
- // try {
- // Thread.sleep(1000);
- // }finally {
- // // 消息处理完成确认
- // channel.basicAck(envelope.getDeliveryTag(), false);
- // }
- // }
- // };
- //// 自动回复队列应答 -- RabbitMQ中的消息确认机制,后面章节会详细讲解
- // channel.basicConsume(QUEUE_NAME, false, consumer);
- // }
-
- @Autowired
- OkHttpUtil httpUtil;
- @Test
- void test(){
- // String imei = "A12345678901234";
- // byte[] b = byteUtil.imeiToByte(imei);
- // System.out.println(byteUtil.bytesToHexString(b));
- // imei = "1330571234567890";
- // b = byteUtil.imeiToByte(imei);
- // System.out.println(byteUtil.bytesToHexString(b));
- // byte b = gzUtil.requestStatus(GZRequestStatus.RESPONSE_NO);
- // System.out.println(b);
- // b = gzUtil.requestStatus(GZRequestStatus.RESPONSE_ALL);
- // System.out.println(b);
- // b = gzUtil.requestStatus(GZRequestStatus.RESPONSE_ERROR);
- // System.out.println(b);
- // byte[] b = new byte[10];
- // b[0] = (byte)128;
- // b[1] = (byte)127;
- // b[2] = (byte)1;
- // b[3] = (byte)256;
- // b[4] = (byte)255;
- // System.out.println( gzUtil.check(b));
- GZRequest req = new GZRequest();
- req.setImei("862622050253671");
- req.setIndex(GZUtil.getMessageIndex());
- req.setStatus(GZRequestStatus.RESPONSE_NO);
- GZLocationCDMA cdma = new GZLocationCDMA();
- GZLocationExtend extend = new GZLocationExtend();
- extend.setNetType(GZNetType.CDMA);
- extend.setData1(cdma);
- byte[] bid = { 0x00, 0x02 };
- cdma.setBID(bid);
- byte[] sid = {0x22, 0x41};
- cdma.setSID(sid);
- byte[] nid = { 0x36, 0x14};
- cdma.setNID(nid);
- GZDeviceStatus deviceStatus = new GZDeviceStatus();
- // deviceStatus.setOpenFirst(true);
- GZDevicePower power = new GZDevicePower();
- power.setCharge(false);
- power.setPower(80);
- GZLocation location = new GZLocation(9, 11,11, 7,
- 13817426, 0, 67901974, 0, 5, 90,
- deviceStatus, power, 70, 3, false, extend);
- req.setContent(location);
- byte[] b = req.toByte();
- System.out.println(ByteUtil.bytesToHexString(b));
- //
- // Headers headers = new Headers.Builder().add("meid-id", "862622050253671").add("imsi-id", "18664272743").build();
- // try {
- // byte[] res = httpUtil.postBytes("http://202.105.147.30:24183", b, headers);
- // System.out.println(ByteUtil.bytesToHexString(res));
- // } catch (IOException e) {
- // e.printStackTrace();
- // }
-
- }
- @Test
- public void test2(){
- String str = "6572726f72206c656e";
- byte[] b = ByteUtil.hexToByteArray(str);
- System.out.println(new String(b));
- }
-
- @Test
- public void test3(){
- List<GZLocationInterval> interval = GZLocationInterval.build("1/0600220003,234567/0700160005");
- boolean in = GZLocationInterval.isIn(LocalDateTime.of(2021, 1 , 13, 23,22, 49), interval);
- System.out.println(in);
- }
-
- @Test
- public void test4(){
- Map<String, Integer> map = new HashMap<>();
- map.put("abc", 2);
- map.put("abc", 3);
- }
-
- }
|