登录区分虚拟服务器
这个提交包含在:
父节点
e9995af5f2
当前提交
9331387b37
99
pom.xml
99
pom.xml
@ -1,45 +1,64 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.0.6</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>cn.org.bjca.trust.java</groupId>
|
||||
<artifactId>ImServer</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>ImServer</name>
|
||||
<description>ImServer</description>
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<!--引入热部署依赖-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-devtools</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.0.6</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>cn.org.bjca.trust.java</groupId>
|
||||
<artifactId>ImServer</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>ImServer</name>
|
||||
<description>ImServer</description>
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<!--引入热部署依赖-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-devtools</artifactId>
|
||||
</dependency>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<!-- 数据库 -->
|
||||
<!-- Spring Data JPA 依赖(重要) -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
<!-- MySQL 驱动(重要) -->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>8.0.24</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
|
||||
@ -2,7 +2,9 @@ package cn.org.bjca.trust.java.imserver;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
|
||||
|
||||
@EnableJpaAuditing
|
||||
@SpringBootApplication
|
||||
public class ImServerApplication {
|
||||
|
||||
|
||||
@ -1,5 +1,11 @@
|
||||
package cn.org.bjca.trust.java.imserver.controller;
|
||||
|
||||
import cn.org.bjca.trust.java.imserver.entitys.Message;
|
||||
import cn.org.bjca.trust.java.imserver.entitys.UserInfo;
|
||||
import cn.org.bjca.trust.java.imserver.entitys.message.TextMessage;
|
||||
import cn.org.bjca.trust.java.imserver.repository.MessageRepository;
|
||||
import cn.org.bjca.trust.java.imserver.repository.UserRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@ -8,9 +14,18 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@RestController
|
||||
@RequestMapping("hello")
|
||||
public class HelloController {
|
||||
@Autowired
|
||||
private MessageRepository messageRepository;
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public String getById(@PathVariable String id) throws Exception {
|
||||
System.out.println("id ==> " + id);
|
||||
Message message = new Message();
|
||||
message.setType("111");
|
||||
TextMessage textMessage = new TextMessage();
|
||||
textMessage.setText("ssss");
|
||||
message.setTextMessage(textMessage);
|
||||
messageRepository.save(message);
|
||||
return "{\"msg\":\"qdxorigin\",\"code\":200,\"data\":\"Sbfuiaefhaikufhcsauik\"}";
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
package cn.org.bjca.trust.java.imserver.controller.user.v1;
|
||||
|
||||
|
||||
import cn.org.bjca.trust.java.imserver.entitys.DeviceEntity;
|
||||
|
||||
public class LoginBean {
|
||||
private String userId;
|
||||
private String userSig;
|
||||
|
||||
@ -4,16 +4,16 @@ public class LoginData {
|
||||
private String host;
|
||||
private String port;
|
||||
private String clientId;
|
||||
private String sign;
|
||||
private String token;
|
||||
|
||||
public LoginData() {
|
||||
}
|
||||
|
||||
public LoginData(String host, String port, String clientId, String sign) {
|
||||
public LoginData(String host, String port, String clientId, String token) {
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
this.clientId = clientId;
|
||||
this.sign = sign;
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
public String getHost() {
|
||||
@ -40,11 +40,11 @@ public class LoginData {
|
||||
this.clientId = clientId;
|
||||
}
|
||||
|
||||
public String getSign() {
|
||||
return sign;
|
||||
public String getToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
public void setSign(String sign) {
|
||||
this.sign = sign;
|
||||
public void setToken(String token) {
|
||||
this.token = token;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,23 +1,83 @@
|
||||
package cn.org.bjca.trust.java.imserver.controller.user.v1;
|
||||
|
||||
import cn.org.bjca.trust.java.imserver.HttpResult;
|
||||
import cn.org.bjca.trust.java.imserver.entitys.UserInfo;
|
||||
import cn.org.bjca.trust.java.imserver.repository.UserRepository;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.UUID;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("user/v1")
|
||||
public class UserV1Controller {
|
||||
|
||||
@Autowired
|
||||
private HttpServletRequest request;
|
||||
@Autowired
|
||||
private UserRepository userRepository;
|
||||
|
||||
@PostMapping("/login")
|
||||
public HttpResult<LoginData> getById(@RequestBody LoginBean user, @RequestHeader HttpHeaders headers) throws Exception {
|
||||
System.out.println(headers.toString());
|
||||
System.out.println(headers.getFirst("appid"));
|
||||
String appid = headers.getFirst("appid");
|
||||
String userid = headers.getFirst("userid");
|
||||
String ostype = headers.getFirst("ostype");
|
||||
requestByGetAndParams("http://114.115.203.60:15672/api/vhosts/"+appid, "");
|
||||
if (null != appid && null != userid && null != ostype) {
|
||||
UserInfo userInfo = userRepository.findUserInfoByUserIdAndOsTypeAndAppId(userid, ostype, appid);
|
||||
if (null == userInfo) {
|
||||
System.out.println("-----------------用户不存在------------------");
|
||||
userInfo = new UserInfo();
|
||||
userInfo.setUserId(userid);
|
||||
userInfo.setUserName(UUID.randomUUID().toString());
|
||||
userInfo.setAppId(appid);
|
||||
userInfo.setOsType(ostype);
|
||||
userInfo.setPassword(UUID.randomUUID().toString());
|
||||
userRepository.save(userInfo);
|
||||
|
||||
return new HttpResult<>(200, "成功", new LoginData("114.115.203.60", "18883", user.getUserId(), user.getUserSig()));
|
||||
requestByGetAndParams("http://114.115.203.60:15672/api/users/" + userInfo.getUserName(), "{\"username\":\"" + userInfo.getUserName() + "\",\"password\":\"" + userInfo.getPassword() + "\",\"tags\":\"\"}");
|
||||
requestByGetAndParams("http://114.115.203.60:15672/api/permissions/%2F/" + userInfo.getUserName(), "{\"username\":\"" + userInfo.getUserName() + "\",\"vhost\":\"" + appid + "\",\"configure\":\".*\",\"write\":\".*\",\"read\":\".*\"}");
|
||||
requestByGetAndParams("http://114.115.203.60:15672/api/permissions/" + appid + "/" + userInfo.getUserName(), "{\"username\":\"" + userInfo.getUserName() + "\",\"vhost\":\"" + appid + "\",\"configure\":\".*\",\"write\":\".*\",\"read\":\".*\"}");
|
||||
requestByGetAndParams("http://114.115.203.60:15672/api/topic-permissions/" + appid + "/" + userInfo.getUserName(), "{\"username\":\"" + userInfo.getUserName() + "\",\"vhost\":\"" + appid + "\",\"exchange\":\"\",\"write\":\".*\",\"read\":\".*\"}");
|
||||
|
||||
}
|
||||
|
||||
return new HttpResult<>(200, "成功", new LoginData("114.115.203.60", "18883", userInfo.getUserName(), userInfo.getPassword()));
|
||||
} else {
|
||||
return new HttpResult<>(201, "参数错误", new LoginData());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void requestByGetAndParams(String requestUrl, String param) throws Exception {
|
||||
System.out.println(requestUrl + ":\n" + param);
|
||||
URL url = new URL(requestUrl);
|
||||
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
|
||||
//设置请求方式,请求参数类型
|
||||
httpURLConnection.setRequestMethod("PUT");
|
||||
httpURLConnection.setRequestProperty("content-type", "application/json;charset=UTF-8");
|
||||
httpURLConnection.setRequestProperty("Authorization", "Basic YWRtaW46YWRtaW4=");
|
||||
httpURLConnection.setDoOutput(true);
|
||||
OutputStream outputStream = httpURLConnection.getOutputStream();
|
||||
//将参数写入输出流,param必须是JSON格式
|
||||
outputStream.write(param.getBytes());
|
||||
outputStream.flush();
|
||||
InputStream inputStream = httpURLConnection.getInputStream();
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||
byte[] bytes = new byte[1024];
|
||||
int len = 0;
|
||||
while ((len = inputStream.read(bytes)) >= 0) {
|
||||
bout.write(bytes, 0, len);
|
||||
}
|
||||
inputStream.close();
|
||||
bout.close();
|
||||
bout.toByteArray();
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,34 @@
|
||||
package cn.org.bjca.trust.java.imserver.entitys;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.annotation.LastModifiedDate;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 所有类的超类
|
||||
* 自动更新创建时间和更新时间
|
||||
*
|
||||
* @author peter
|
||||
*
|
||||
**/
|
||||
@MappedSuperclass
|
||||
@EntityListeners(value = AuditingEntityListener.class)
|
||||
@Getter
|
||||
@Setter
|
||||
public abstract class AbstractBaseTimeEntity {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long _id;
|
||||
|
||||
@CreatedDate
|
||||
@Column(nullable = false, updatable = false)
|
||||
private LocalDateTime createTime;
|
||||
@LastModifiedDate
|
||||
@Column()
|
||||
private LocalDateTime updateTime;
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
package cn.org.bjca.trust.java.imserver.entitys;
|
||||
|
||||
import cn.org.bjca.trust.java.imserver.entitys.message.TextMessage;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.OneToOne;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.Data;
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
public class Message extends AbstractBaseTimeEntity{
|
||||
private String type;
|
||||
@OneToOne
|
||||
@JoinColumn(name="text_id",referencedColumnName="_id")
|
||||
private TextMessage textMessage;
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
package cn.org.bjca.trust.java.imserver.entitys;
|
||||
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Data;
|
||||
|
||||
@Entity
|
||||
@Table(name = "user")
|
||||
@Data
|
||||
public class UserInfo extends AbstractBaseTimeEntity {
|
||||
private String userId;
|
||||
private String userName;
|
||||
private String password;
|
||||
private String appId;
|
||||
private String osType;
|
||||
private String nickName;
|
||||
private String faceUrl;
|
||||
private String gender;
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
package cn.org.bjca.trust.java.imserver.entitys.message;
|
||||
|
||||
import cn.org.bjca.trust.java.imserver.entitys.AbstractBaseTimeEntity;
|
||||
import cn.org.bjca.trust.java.imserver.entitys.Message;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.OneToOne;
|
||||
import lombok.Data;
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
public class TextMessage extends AbstractBaseTimeEntity {
|
||||
private String text;
|
||||
@OneToOne(mappedBy="textMessage")
|
||||
private Message message;
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
package cn.org.bjca.trust.java.imserver.repository;
|
||||
|
||||
import cn.org.bjca.trust.java.imserver.entitys.Message;
|
||||
import cn.org.bjca.trust.java.imserver.entitys.UserInfo;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface MessageRepository extends JpaRepository<Message,Long> {
|
||||
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
package cn.org.bjca.trust.java.imserver.repository;
|
||||
|
||||
import cn.org.bjca.trust.java.imserver.entitys.UserInfo;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface UserRepository extends JpaRepository<UserInfo,Long> {
|
||||
|
||||
UserInfo findUserInfoByUserIdAndOsTypeAndAppId(String userId, String osType, String appId);
|
||||
}
|
||||
@ -1 +1,16 @@
|
||||
server.port=4561
|
||||
|
||||
#????????????
|
||||
spring.jpa.hibernate.ddl-auto=update
|
||||
#mysql?????????????
|
||||
spring.datasource.url = jdbc:mysql://114.115.203.60:3306/szyx-im?serverTimezone=Asia/Shanghai
|
||||
#??????
|
||||
spring.datasource.username = szyx-im
|
||||
#?????
|
||||
spring.datasource.password = nGFYwCMYMNELCeRp
|
||||
#mysql???????????
|
||||
spring.datasource.driver-class-name = com.mysql.cj.jdbc.Driver
|
||||
#jpa?????????Hibernate?sql(??)
|
||||
spring.jpa.show-sql = true
|
||||
#???????Thymeleaf ???
|
||||
spring.thymeleaf.cache = false
|
||||
|
||||
正在加载...
在新工单中引用
屏蔽一个用户