Parcourir la source

登录获取基础信息

xuqm il y a 1 an
Parent
commit
581fe4422a

+ 32 - 0
src/main/java/cn/org/bjca/trust/java/imserver/GlobalCorsConfig.java

@@ -0,0 +1,32 @@
+package cn.org.bjca.trust.java.imserver;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.CorsRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+@Configuration
+public class GlobalCorsConfig {
+    @Bean
+    public WebMvcConfigurer corsConfigurer() {
+        return new WebMvcConfigurer() {
+            @Override
+            //重写父类提供的跨域请求处理的接口
+            public void addCorsMappings(CorsRegistry registry) {
+                //添加映射路径
+                registry.addMapping("/**")
+                        //放行哪些原始域
+                        .allowedOrigins("*")
+                        //是否发送Cookie信息
+                        .allowCredentials(false)
+                        //放行哪些原始域(请求方式)
+                        .allowedMethods("GET", "POST", "PUT", "DELETE")
+                        //放行哪些原始域(头部信息)
+                        .allowedHeaders("*")
+                        //暴露哪些头部信息(因为跨域访问默认不能获取全部头部信息)
+                        .exposedHeaders("Header1", "Header2");
+            }
+        };
+    }
+}
+

+ 43 - 0
src/main/java/cn/org/bjca/trust/java/imserver/HttpResult.java

@@ -0,0 +1,43 @@
+package cn.org.bjca.trust.java.imserver;
+
+public class HttpResult<T> {
+    /**
+     * "code": 200
+     * "message": "success"
+     * data :
+     */
+
+    private int code;
+    private String msg;
+    private T data;
+
+    public HttpResult(int code, String msg, T data) {
+        this.code = code;
+        this.msg = msg;
+        this.data = data;
+    }
+
+    public int getCode() {
+        return code;
+    }
+
+    public void setCode(int code) {
+        this.code = code;
+    }
+
+    public String getMsg() {
+        return msg;
+    }
+
+    public void setMsg(String msg) {
+        this.msg = msg;
+    }
+
+    public T getData() {
+        return data;
+    }
+
+    public void setData(T data) {
+        this.data = data;
+    }
+}

+ 1 - 1
src/main/java/cn/org/bjca/trust/java/imserver/controller/HelloController.java

@@ -11,6 +11,6 @@ public class HelloController {
     @GetMapping("/{id}")
     public String getById(@PathVariable String id) throws Exception {
         System.out.println("id ==> " + id);
-        return "{\n" + "    \"msg\": \"qdxorigin\",\n" + "    \"status\": \"201\",\n" + "    \"data\": \"Sbfuiaefhaikufhcsauik\"\n" + "}";
+        return "{\"msg\":\"qdxorigin\",\"code\":200,\"data\":\"Sbfuiaefhaikufhcsauik\"}";
     }
 }

+ 43 - 0
src/main/java/cn/org/bjca/trust/java/imserver/controller/user/v1/LoginBean.java

@@ -0,0 +1,43 @@
+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;
+    private DeviceEntity device;
+
+    public String getUserId() {
+        return userId;
+    }
+
+    public void setUserId(String userId) {
+        this.userId = userId;
+    }
+
+    public String getUserSig() {
+        return userSig;
+    }
+
+    public void setUserSig(String userSig) {
+        this.userSig = userSig;
+    }
+
+    public DeviceEntity getDevice() {
+        return device;
+    }
+
+    public void setDevice(DeviceEntity device) {
+        this.device = device;
+    }
+
+    @Override
+    public String toString() {
+        return "LoginBean{" +
+                "userId='" + userId + '\'' +
+                ", userSig='" + userSig + '\'' +
+                ", device=" + device +
+                '}';
+    }
+}

+ 50 - 0
src/main/java/cn/org/bjca/trust/java/imserver/controller/user/v1/LoginData.java

@@ -0,0 +1,50 @@
+package cn.org.bjca.trust.java.imserver.controller.user.v1;
+
+public class LoginData {
+    private String host;
+    private String port;
+    private String clientId;
+    private String sign;
+
+    public LoginData() {
+    }
+
+    public LoginData(String host, String port, String clientId, String sign) {
+        this.host = host;
+        this.port = port;
+        this.clientId = clientId;
+        this.sign = sign;
+    }
+
+    public String getHost() {
+        return host;
+    }
+
+    public void setHost(String host) {
+        this.host = host;
+    }
+
+    public String getPort() {
+        return port;
+    }
+
+    public void setPort(String port) {
+        this.port = port;
+    }
+
+    public String getClientId() {
+        return clientId;
+    }
+
+    public void setClientId(String clientId) {
+        this.clientId = clientId;
+    }
+
+    public String getSign() {
+        return sign;
+    }
+
+    public void setSign(String sign) {
+        this.sign = sign;
+    }
+}

+ 23 - 0
src/main/java/cn/org/bjca/trust/java/imserver/controller/user/v1/UserV1Controller.java

@@ -0,0 +1,23 @@
+package cn.org.bjca.trust.java.imserver.controller.user.v1;
+
+import cn.org.bjca.trust.java.imserver.HttpResult;
+import jakarta.servlet.http.HttpServletRequest;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpHeaders;
+import org.springframework.web.bind.annotation.*;
+
+@RestController
+@RequestMapping("user/v1")
+public class UserV1Controller {
+
+    @Autowired
+    private HttpServletRequest request;
+
+    @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"));
+
+        return new HttpResult<>(200, "成功", new LoginData("114.115.203.60", "18883", user.getUserId(), user.getUserSig()));
+    }
+}

+ 121 - 0
src/main/java/cn/org/bjca/trust/java/imserver/entitys/DeviceEntity.java

@@ -0,0 +1,121 @@
+package cn.org.bjca.trust.java.imserver.entitys;
+
+
+import org.springframework.lang.NonNull;
+
+public class DeviceEntity {
+    private int _uid;
+    private String deviceId;
+    // 厂商 MANUFACTURER
+    private String manufacturer;
+    // 品牌 BRAND
+    private String brand;
+    // 型号 MODEL
+    private String model;
+    // cpu CPU_ABI
+    private String cpuAbi;
+    // 指纹  FINGERPRINT
+    private String fingerprint;
+    // SUPPORTED_32_BIT_ABIS
+    private String supported32BitAbis;
+    // SUPPORTED_64_BIT_ABIS
+    private String supported64BitAbis;
+    // SUPPORTED_ABIS
+    private String supportedAbis;
+
+    public void set_uid(int _uid) {
+        this._uid = _uid;
+    }
+
+    public int get_uid() {
+        return _uid;
+    }
+
+    public String getDeviceId() {
+        return deviceId;
+    }
+
+    public void setDeviceId(String deviceId) {
+        this.deviceId = deviceId;
+    }
+
+    public String getManufacturer() {
+        return manufacturer;
+    }
+
+    public void setManufacturer(String manufacturer) {
+        this.manufacturer = manufacturer;
+    }
+
+    public String getBrand() {
+        return brand;
+    }
+
+    public void setBrand(String brand) {
+        this.brand = brand;
+    }
+
+    public String getModel() {
+        return model;
+    }
+
+    public void setModel(String model) {
+        this.model = model;
+    }
+
+    public String getCpuAbi() {
+        return cpuAbi;
+    }
+
+    public void setCpuAbi(String cpuAbi) {
+        this.cpuAbi = cpuAbi;
+    }
+
+    public String getFingerprint() {
+        return fingerprint;
+    }
+
+    public void setFingerprint(String fingerprint) {
+        this.fingerprint = fingerprint;
+    }
+
+    public String getSupported32BitAbis() {
+        return supported32BitAbis;
+    }
+
+    public void setSupported32BitAbis(String supported32BitAbis) {
+        this.supported32BitAbis = supported32BitAbis;
+    }
+
+    public String getSupported64BitAbis() {
+        return supported64BitAbis;
+    }
+
+    public void setSupported64BitAbis(String supported64BitAbis) {
+        this.supported64BitAbis = supported64BitAbis;
+    }
+
+    public String getSupportedAbis() {
+        return supportedAbis;
+    }
+
+    public void setSupportedAbis(String supportedAbis) {
+        this.supportedAbis = supportedAbis;
+    }
+
+    @NonNull
+    @Override
+    public String toString() {
+        return "DeviceEntity{" +
+                "deviceId='" + deviceId + '\'' +
+                ", manufacturer='" + manufacturer + '\'' +
+                ", brand='" + brand + '\'' +
+                ", model='" + model + '\'' +
+                ", cpuAbi='" + cpuAbi + '\'' +
+                ", fingerprint='" + fingerprint + '\'' +
+                ", supported32BitAbis='" + supported32BitAbis + '\'' +
+                ", supported64BitAbis='" + supported64BitAbis + '\'' +
+                ", supportedAbis='" + supportedAbis + '\'' +
+                '}';
+    }
+}

+ 50 - 0
src/main/java/cn/org/bjca/trust/java/imserver/entitys/HttpHeaders.java

@@ -0,0 +1,50 @@
+package cn.org.bjca.trust.java.imserver.entitys;
+
+public class HttpHeaders {
+    private String AppID;
+    private String UserId;
+    private String Version;
+    private String OsType;
+
+    public String getAppID() {
+        return AppID;
+    }
+
+    public void setAppID(String appID) {
+        AppID = appID;
+    }
+
+    public String getUserId() {
+        return UserId;
+    }
+
+    public void setUserId(String userId) {
+        UserId = userId;
+    }
+
+    public String getVersion() {
+        return Version;
+    }
+
+    public void setVersion(String version) {
+        Version = version;
+    }
+
+    public String getOsType() {
+        return OsType;
+    }
+
+    public void setOsType(String osType) {
+        OsType = osType;
+    }
+
+    @Override
+    public String toString() {
+        return "HttpHeaders{" +
+                "AppID='" + AppID + '\'' +
+                ", UserId='" + UserId + '\'' +
+                ", Version='" + Version + '\'' +
+                ", OsType='" + OsType + '\'' +
+                '}';
+    }
+}

+ 35 - 0
src/main/java/cn/org/bjca/trust/java/imserver/enums/MsgType.java

@@ -0,0 +1,35 @@
+package cn.org.bjca.trust.java.imserver.enums;
+
+public enum MsgType {
+    UNKNOWN(-1)     /* 未知 */,
+    Text(1)         /* 文本 */,
+    Voice(2)        /* 语音 */,
+    Image(3)        /* 图片 */,
+    Location(4)     /* 位置 */,
+    Video(5)        /* 视频 */,
+    File(6)         /* 文件 */,
+    At(7)          /* @我 */,
+    READ(8)          /* 已读 */,
+    REVOKE(9)          /* 撤回 */,
+    DELETE(10)          /* 删除 */,
+    Other(101)          /* 自定义消息 */,
+
+    Notify(999);
+
+    private int type = -1;
+    MsgType(final int type) {
+        this.type = type;
+    }
+    public int type() {
+        return this.type;
+    }
+
+    public static MsgType getType(final int type) {
+        for (final MsgType value : MsgType.values()) {
+            if (value.type == type) {
+                return value;
+            }
+        }
+        return UNKNOWN;
+    }
+}

+ 29 - 0
src/main/java/cn/org/bjca/trust/java/imserver/enums/OsType.java

@@ -0,0 +1,29 @@
+package cn.org.bjca.trust.java.imserver.enums;
+
+public enum OsType {
+    UNKNOWN(-1),
+    ANDROID(1),
+    WEB(2),
+    IOS(3),
+    MAC(4),
+    PC(5);
+
+    private int type = -1;
+
+    OsType(final int type) {
+        this.type = type;
+    }
+
+    public int type() {
+        return this.type;
+    }
+
+    public static OsType getType(final int type) {
+        for (final OsType value : OsType.values()) {
+            if (value.type == type) {
+                return value;
+            }
+        }
+        return UNKNOWN;
+    }
+}