feat():车辆网关:fluxmq通过rabbitmq发送vin
parent
43c74b9978
commit
9185f33c0c
|
@ -0,0 +1,50 @@
|
||||||
|
package com.muyu.car;
|
||||||
|
|
||||||
|
import org.eclipse.paho.client.mqttv3.*;
|
||||||
|
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
|
||||||
|
|
||||||
|
public class MqttPublishSample {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
String topic = "vehicle";
|
||||||
|
String content = "Message from MqttPublishSample";
|
||||||
|
int qos = 2;
|
||||||
|
String broker = "tcp://120.55.62.0:1883";
|
||||||
|
String clientId = "JavaSample";
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 第三个参数为空,默认持久化策略
|
||||||
|
MqttClient sampleClient = new MqttClient(broker, clientId);
|
||||||
|
MqttConnectOptions connOpts = new MqttConnectOptions();
|
||||||
|
connOpts.setCleanSession(true);
|
||||||
|
System.out.println("Connecting to broker: "+broker);
|
||||||
|
sampleClient.connect(connOpts);
|
||||||
|
sampleClient.subscribe(topic,0);
|
||||||
|
sampleClient.setCallback(new MqttCallback() {
|
||||||
|
// 连接丢失
|
||||||
|
@Override
|
||||||
|
public void connectionLost(Throwable throwable) {
|
||||||
|
|
||||||
|
}
|
||||||
|
// 连接成功
|
||||||
|
@Override
|
||||||
|
public void messageArrived(String s, MqttMessage mqttMessage) throws Exception {
|
||||||
|
System.out.println(new String(mqttMessage.getPayload()));
|
||||||
|
}
|
||||||
|
// 接收信息
|
||||||
|
@Override
|
||||||
|
public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch(MqttException me) {
|
||||||
|
System.out.println("reason "+me.getReasonCode());
|
||||||
|
System.out.println("msg "+me.getMessage());
|
||||||
|
System.out.println("loc "+me.getLocalizedMessage());
|
||||||
|
System.out.println("cause "+me.getCause());
|
||||||
|
System.out.println("excep "+me);
|
||||||
|
me.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
package com.muyu.car.domain.api.req;
|
package com.muyu.car.domain.api.req;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.annotation.JSONField;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
@ -31,7 +32,8 @@ public class VehicleConnectionReq {
|
||||||
/**
|
/**
|
||||||
* vin
|
* vin
|
||||||
*/
|
*/
|
||||||
private String vin;
|
@JSONField(name = "vehicleVin")
|
||||||
|
private String vehicleVin;
|
||||||
/**
|
/**
|
||||||
* 时间戳
|
* 时间戳
|
||||||
*/
|
*/
|
||||||
|
@ -39,10 +41,15 @@ public class VehicleConnectionReq {
|
||||||
/**
|
/**
|
||||||
* 用户名
|
* 用户名
|
||||||
*/
|
*/
|
||||||
private String userName;
|
@JSONField(name = "username")
|
||||||
|
private String username;
|
||||||
/**
|
/**
|
||||||
* 随机字符串
|
* 随机字符串
|
||||||
*/
|
*/
|
||||||
private String nonce;
|
private String nonce;
|
||||||
|
/**
|
||||||
|
* 密码
|
||||||
|
*/
|
||||||
|
private String password;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
package com.muyu.car.domain.model;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:蓬叁
|
||||||
|
* @Package:com.muyu.car.domain.model
|
||||||
|
* @Project:cloud-server-8
|
||||||
|
* @name:MqttServerModel
|
||||||
|
* @Date:2024/10/7 下午6:40
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class MqttServerModel {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MQTT服务节点
|
||||||
|
*/
|
||||||
|
private String broker;
|
||||||
|
/**
|
||||||
|
* MQTT订阅主题
|
||||||
|
*/
|
||||||
|
private String topic;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,86 @@
|
||||||
|
package com.muyu.car.domain.model;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:蓬叁
|
||||||
|
* @Package:com.muyu.car.domain.model
|
||||||
|
* @Project:cloud-server-8
|
||||||
|
* @name:Vehicle
|
||||||
|
* @Date:2024/10/6 上午10:33
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class VehicleInformation {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 车辆ID
|
||||||
|
*/
|
||||||
|
private String carInformationId ;
|
||||||
|
/**
|
||||||
|
* 车辆唯一VIN
|
||||||
|
*/
|
||||||
|
private String carInformationVIN ;
|
||||||
|
/**
|
||||||
|
* 车牌号
|
||||||
|
*/
|
||||||
|
private String carInformationLicensePlate ;
|
||||||
|
/**
|
||||||
|
* 车辆品牌
|
||||||
|
*/
|
||||||
|
private String carInformationBrand ;
|
||||||
|
/**
|
||||||
|
* 车辆颜色
|
||||||
|
*/
|
||||||
|
private String carInformationColor ;
|
||||||
|
/**
|
||||||
|
* 车辆驾驶员
|
||||||
|
*/
|
||||||
|
private String carInformationDriver ;
|
||||||
|
/**
|
||||||
|
* 车检到期日期
|
||||||
|
*/
|
||||||
|
private String carInformationExamineEnddata ;
|
||||||
|
/**
|
||||||
|
* 车辆电机厂商
|
||||||
|
*/
|
||||||
|
private String carInformationMotorManufacturer ;
|
||||||
|
/**
|
||||||
|
* 车辆电机型号
|
||||||
|
*/
|
||||||
|
private String carInformationMotorModel ;
|
||||||
|
/**
|
||||||
|
* 车辆电池厂商
|
||||||
|
*/
|
||||||
|
private String carInformationBatteryManufacturer ;
|
||||||
|
/**
|
||||||
|
* 车辆电池型号
|
||||||
|
*/
|
||||||
|
private String carInformationBatteryModel ;
|
||||||
|
/**
|
||||||
|
* 车辆电子围栏外键ID
|
||||||
|
*/
|
||||||
|
private String carInformationFence ;
|
||||||
|
/**
|
||||||
|
* 车辆类型外键ID
|
||||||
|
*/
|
||||||
|
private String carInformationType ;
|
||||||
|
/**
|
||||||
|
* 是否重点车辆 (0否默认 1是 )
|
||||||
|
*/
|
||||||
|
private String carInformationFocus ;
|
||||||
|
/**
|
||||||
|
* 车辆策略id
|
||||||
|
*/
|
||||||
|
private String carStrategyId ;
|
||||||
|
/**
|
||||||
|
* 启用状态(1.在线 2.离线 3.已断开 4.待连接 5.维修中)
|
||||||
|
*/
|
||||||
|
private String carInformationState ;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,51 @@
|
||||||
|
package com.muyu.car.domain.model.properties;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:蓬叁
|
||||||
|
* @Package:com.muyu.car.domain.model.properties
|
||||||
|
* @Project:cloud-server-8
|
||||||
|
* @name:MqttProperties
|
||||||
|
* @Date:2024/10/6 下午8:24
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class MqttProperties {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 节点
|
||||||
|
*/
|
||||||
|
private String broker;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主题
|
||||||
|
*/
|
||||||
|
private String topic;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户名
|
||||||
|
*/
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密码
|
||||||
|
*/
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 节点ID
|
||||||
|
*/
|
||||||
|
private String clientId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上报级别
|
||||||
|
*/
|
||||||
|
private int qos = 0;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
package com.muyu.car.domain.model.properties;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:蓬叁
|
||||||
|
* @Package:com.muyu.car.domain.model.properties
|
||||||
|
* @Project:cloud-server-8
|
||||||
|
* @name:MqttServerModel
|
||||||
|
* @Date:2024/10/6 下午8:25
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class MqttServerModel {
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(MqttServerModel.class);
|
||||||
|
/**
|
||||||
|
* MQTT服务节点
|
||||||
|
*/
|
||||||
|
private String broker;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MQTT订阅主题
|
||||||
|
*/
|
||||||
|
private String topic;
|
||||||
|
|
||||||
|
public String getBroker () {
|
||||||
|
log.info("broker: {}", broker);
|
||||||
|
return broker.contains("tcp://") ? broker : "tcp://" + broker + ":1883";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,21 +0,0 @@
|
||||||
package com.muyu.car.gateway.controller;
|
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 车辆信息接口
|
|
||||||
* @Author:蓬叁
|
|
||||||
* @Package:com.muyu.car.gateway.controller
|
|
||||||
* @Project:cloud-server-8
|
|
||||||
* @name:VehicleInformation
|
|
||||||
* @Date:2024/10/4 上午9:40
|
|
||||||
*/
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/vehicle")
|
|
||||||
public class VehicleInformation {
|
|
||||||
|
|
||||||
// @PostMapping("/")
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
package com.muyu.car.gateway.controller;
|
||||||
|
|
||||||
|
import com.muyu.car.domain.api.req.VehicleConnectionReq;
|
||||||
|
import com.muyu.car.domain.model.MqttServerModel;
|
||||||
|
import com.muyu.car.domain.model.VehicleInformation;
|
||||||
|
import com.muyu.car.gateway.service.VehicleInformationService;
|
||||||
|
import com.muyu.common.core.domain.Result;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 车辆获取信息
|
||||||
|
* @Author:蓬叁
|
||||||
|
* @Package:com.muyu.car.gateway.controller
|
||||||
|
* @Project:cloud-server-8
|
||||||
|
* @name:VehicleInformationController
|
||||||
|
* @Date:2024/10/6 下午2:39
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/verify")
|
||||||
|
public class VehicleInformationController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private VehicleInformationService vehicleInformationService;
|
||||||
|
|
||||||
|
@PostMapping("/vehicleConnection")
|
||||||
|
public Result<MqttServerModel> getVehicleData(
|
||||||
|
@Validated @RequestBody VehicleConnectionReq vehicleConnectionReq
|
||||||
|
) {
|
||||||
|
|
||||||
|
return Result.success(vehicleInformationService.getVehicleData(vehicleConnectionReq));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.muyu.car.gateway.controller;
|
||||||
|
|
||||||
|
import com.muyu.car.domain.model.VehicleInformation;
|
||||||
|
import com.muyu.car.gateway.service.VehicleInstanceService;
|
||||||
|
import com.muyu.common.core.domain.Result;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 车辆实例控制层
|
||||||
|
* @Author:蓬叁
|
||||||
|
* @Package:com.muyu.car.gateway.controller
|
||||||
|
* @Project:cloud-server-8
|
||||||
|
* @name:VehicleInformation
|
||||||
|
* @Date:2024/10/4 上午9:40
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/vehicle")
|
||||||
|
public class VehicleInstanceController {
|
||||||
|
|
||||||
|
@Autowired private VehicleInstanceService vehicleInstanceService;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,53 @@
|
||||||
|
package com.muyu.car.gateway.mq;
|
||||||
|
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.amqp.core.*;
|
||||||
|
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||||
|
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.ApplicationArguments;
|
||||||
|
import org.springframework.boot.ApplicationRunner;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:蓬叁
|
||||||
|
* @Package:com.muyu.car.gateway.mq
|
||||||
|
* @Project:cloud-server-8
|
||||||
|
* @name:CreateExchange
|
||||||
|
* @Date:2024/10/7 下午8:53
|
||||||
|
*/
|
||||||
|
@Log4j2
|
||||||
|
@Component
|
||||||
|
public class CreateExchange implements ApplicationRunner {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ConnectionFactory connectionFactory;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(ApplicationArguments args) {
|
||||||
|
log.info("=====>开始创建交换机");
|
||||||
|
|
||||||
|
try {
|
||||||
|
RabbitAdmin rabbitAdmin = new RabbitAdmin(connectionFactory);
|
||||||
|
|
||||||
|
// 创建Fanout类型的交换机
|
||||||
|
FanoutExchange exchange = new FanoutExchange("ONLINE_EXCHANGE", true, false);
|
||||||
|
|
||||||
|
rabbitAdmin.declareExchange(exchange);
|
||||||
|
|
||||||
|
// 创建队列
|
||||||
|
Queue queue = new Queue("GO_ONLINE", true, false, false);
|
||||||
|
|
||||||
|
rabbitAdmin.declareQueue(queue);
|
||||||
|
|
||||||
|
// Fanout交换机绑定
|
||||||
|
rabbitAdmin.declareBinding(BindingBuilder.bind(queue).to(exchange));
|
||||||
|
|
||||||
|
log.info("=====>交换机创建成功");
|
||||||
|
log.info("=====>队列创建成功并绑定到交换机");
|
||||||
|
}catch (Exception e) {
|
||||||
|
log.info(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.muyu.car.gateway.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.muyu.car.domain.api.req.VehicleConnectionReq;
|
||||||
|
import com.muyu.car.domain.model.MqttServerModel;
|
||||||
|
import com.muyu.car.domain.model.VehicleInformation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:蓬叁
|
||||||
|
* @Package:com.muyu.car.gateway.service
|
||||||
|
* @Project:cloud-server-8
|
||||||
|
* @name:VehicleInformationService
|
||||||
|
* @Date:2024/10/6 下午2:40
|
||||||
|
*/
|
||||||
|
public interface VehicleInformationService{
|
||||||
|
MqttServerModel getVehicleData(VehicleConnectionReq vehicleConnectionReq);
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
package com.muyu.car.gateway.service;
|
||||||
|
|
||||||
|
import com.muyu.car.domain.model.VehicleInformation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:蓬叁
|
||||||
|
* @Package:com.muyu.car.gateway.service
|
||||||
|
* @Project:cloud-server-8
|
||||||
|
* @name:VehicleInstanceService
|
||||||
|
* @Date:2024/10/6 上午10:05
|
||||||
|
*/
|
||||||
|
public interface VehicleInstanceService {
|
||||||
|
}
|
|
@ -0,0 +1,44 @@
|
||||||
|
package com.muyu.car.gateway.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.muyu.car.domain.api.req.VehicleConnectionReq;
|
||||||
|
import com.muyu.car.domain.model.MqttServerModel;
|
||||||
|
import com.muyu.car.domain.model.VehicleInformation;
|
||||||
|
import com.muyu.car.gateway.service.VehicleInformationService;
|
||||||
|
import com.muyu.car.mapper.VehicleInformationMapper;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:蓬叁
|
||||||
|
* @Package:com.muyu.car.gateway.service.impl
|
||||||
|
* @Project:cloud-server-8
|
||||||
|
* @name:VehicleInformationServiceImpl
|
||||||
|
* @Date:2024/10/6 下午2:41
|
||||||
|
*/
|
||||||
|
@Log4j2
|
||||||
|
@Service
|
||||||
|
public class VehicleInformationServiceImpl implements VehicleInformationService{
|
||||||
|
|
||||||
|
@Autowired private VehicleInformationMapper vehicleInformationMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MqttServerModel getVehicleData(VehicleConnectionReq vehicleConnectionReq) {
|
||||||
|
log.info("车辆连接请求:[{}]",vehicleConnectionReq);
|
||||||
|
vehicleConnectionReq.setPassword(vehicleConnectionReq.getVehicleVin()+vehicleConnectionReq.getTimestamp()+vehicleConnectionReq.getNonce());
|
||||||
|
|
||||||
|
List<String> selectVehicle =vehicleInformationMapper.selectVehicleVin(vehicleConnectionReq.getVehicleVin());
|
||||||
|
if(selectVehicle.isEmpty()) {
|
||||||
|
vehicleInformationMapper.addVehicleConnection(vehicleConnectionReq);
|
||||||
|
log.info("车辆预上线成功");
|
||||||
|
}else {
|
||||||
|
log.info("车辆无法重复预上线");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new MqttServerModel("tcp://121.199.172.3:1883","vehicle");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.muyu.car.gateway.service.impl;
|
||||||
|
|
||||||
|
import com.muyu.car.domain.model.VehicleInformation;
|
||||||
|
import com.muyu.car.gateway.service.VehicleInstanceService;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:蓬叁
|
||||||
|
* @Package:com.muyu.car.gateway.service.impl
|
||||||
|
* @Project:cloud-server-8
|
||||||
|
* @name:VehicleInstanceServceImpl
|
||||||
|
* @Date:2024/10/6 上午10:06
|
||||||
|
*/
|
||||||
|
@Log4j2
|
||||||
|
@Service
|
||||||
|
public class VehicleInstanceServiceImpl implements VehicleInstanceService {
|
||||||
|
}
|
|
@ -45,7 +45,7 @@ public class GenerateInstance implements ApplicationRunner {
|
||||||
// 设置地域ID
|
// 设置地域ID
|
||||||
.setRegionId("cn-hangzhou")
|
.setRegionId("cn-hangzhou")
|
||||||
// 设置镜像ID
|
// 设置镜像ID
|
||||||
.setImageId("m-bp10rcc4nsihqfoz0w7s")
|
.setImageId("m-bp1hkxfctk751s62jqhq")
|
||||||
// 设置实例类型
|
// 设置实例类型
|
||||||
.setInstanceType("ecs.t6-c1m1.large")
|
.setInstanceType("ecs.t6-c1m1.large")
|
||||||
// 设置安全组ID
|
// 设置安全组ID
|
||||||
|
@ -65,7 +65,7 @@ public class GenerateInstance implements ApplicationRunner {
|
||||||
// 设置实例密码
|
// 设置实例密码
|
||||||
.setPassword("EightGroup123.")
|
.setPassword("EightGroup123.")
|
||||||
// 设置创建实例的数量
|
// 设置创建实例的数量
|
||||||
.setAmount(2);
|
.setAmount(1);
|
||||||
|
|
||||||
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
|
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -28,7 +28,6 @@ public class QueryInstance {
|
||||||
.setInstanceIds(JSON.toJSONString(instanceIds))
|
.setInstanceIds(JSON.toJSONString(instanceIds))
|
||||||
.setRegionId("cn-hangzhou");
|
.setRegionId("cn-hangzhou");
|
||||||
|
|
||||||
|
|
||||||
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
|
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
package com.muyu.car.mapper;
|
||||||
|
|
||||||
|
import com.muyu.car.domain.api.req.VehicleConnectionReq;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:蓬叁
|
||||||
|
* @Package:com.muyu.car.mapper
|
||||||
|
* @Project:cloud-server-8
|
||||||
|
* @name:VehicleInformationMapper
|
||||||
|
* @Date:2024/10/6 下午2:19
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface VehicleInformationMapper {
|
||||||
|
void addVehicleConnection(VehicleConnectionReq vehicleConnectionReq);
|
||||||
|
|
||||||
|
List<String> selectVehicleVin(@Param("vehicleVin") String vehicleVin);
|
||||||
|
}
|
|
@ -0,0 +1,71 @@
|
||||||
|
package com.muyu.car.util;
|
||||||
|
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
import java.security.SecureRandom;
|
||||||
|
|
||||||
|
@Log4j2
|
||||||
|
public class MD5Util {
|
||||||
|
|
||||||
|
private static final Integer SALT_LENGTH = 12;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将指定byte数组转换成16进制字符串
|
||||||
|
* @param b 字节数组
|
||||||
|
* @return 返回结果字符串
|
||||||
|
*/
|
||||||
|
public static String byteToHexString(byte[] b) {
|
||||||
|
StringBuilder hexString = new StringBuilder();
|
||||||
|
for (byte value : b) {
|
||||||
|
String hex = Integer.toHexString(value & 0xFF);
|
||||||
|
if (hex.length() == 1) {
|
||||||
|
hex = '0' + hex;
|
||||||
|
}
|
||||||
|
hexString.append(hex.toUpperCase());
|
||||||
|
}
|
||||||
|
return hexString.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得加密后的口令
|
||||||
|
* @param str 需要加密的字符串
|
||||||
|
* @return 加密后的字符串
|
||||||
|
*/
|
||||||
|
public static String encrypted (String str) {
|
||||||
|
try {
|
||||||
|
// 声明加密后的口令数组变量
|
||||||
|
byte[] pwd = null;
|
||||||
|
// 随机数生成器
|
||||||
|
SecureRandom random = new SecureRandom();
|
||||||
|
// 声明盐数组变量
|
||||||
|
byte[] salt = new byte[SALT_LENGTH];
|
||||||
|
// 将随机数放入盐变量中
|
||||||
|
random.nextBytes(salt);
|
||||||
|
|
||||||
|
// 声明消息摘要对象
|
||||||
|
MessageDigest md = null;
|
||||||
|
// 创建消息摘要
|
||||||
|
md = MessageDigest.getInstance("MD5");
|
||||||
|
// 将盐数据传入消息摘要对象
|
||||||
|
md.update(salt);
|
||||||
|
// 将口令的数据传给消息摘要对象
|
||||||
|
md.update(str.getBytes(StandardCharsets.UTF_8));
|
||||||
|
// 获得消息摘要的字节数组
|
||||||
|
byte[] digest = md.digest();
|
||||||
|
|
||||||
|
// 因为要在口令的字节数组中存放盐,所以加上盐的字节长度
|
||||||
|
pwd = new byte[digest.length + SALT_LENGTH];
|
||||||
|
// 将盐的字节拷贝到生成的加密口令字节数组的前12个字节,以便在验证口令时取出盐
|
||||||
|
System.arraycopy(salt, 0, pwd, 0, SALT_LENGTH);
|
||||||
|
// 将消息摘要拷贝到加密口令字节数组从第13个字节开始的字节
|
||||||
|
System.arraycopy(digest, 0, pwd, SALT_LENGTH, digest.length);
|
||||||
|
// 将字节数组格式加密后的口令转化为16进制字符串格式的口令
|
||||||
|
return byteToHexString(pwd);
|
||||||
|
}catch (Exception exception){
|
||||||
|
log.info("md5加密失败:[{}]", str, exception);
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.@//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.muyu.car.mapper.VehicleInformationMapper">
|
||||||
|
<insert id="addVehicleConnection">
|
||||||
|
INSERT INTO `vehicle_connection` (`vin`, `timestamp`, `username`, `nonce`,`password`) VALUES (#{vehicleVin}, #{timestamp}, #{username}, #{nonce},#{password});
|
||||||
|
</insert>
|
||||||
|
<select id="selectVehicleVin" resultType="java.lang.String">
|
||||||
|
select
|
||||||
|
`vin`, `timestamp`, `username`, `nonce`,`password`
|
||||||
|
from
|
||||||
|
`vehicle_connection`
|
||||||
|
where `vin` = #{vehicleVin}
|
||||||
|
</select>
|
||||||
|
</mapper>
|
Loading…
Reference in New Issue