fengjiajia 1 week ago
parent
commit
a36a3fd9b5

+ 11 - 10
pom.xml

@@ -15,6 +15,16 @@
     </properties>
     <dependencies>
         <dependency>
+            <groupId>com.google.zxing</groupId>
+            <artifactId>core</artifactId>
+            <version>3.5.1</version>
+        </dependency>
+        <dependency>
+            <groupId>com.google.zxing</groupId>
+            <artifactId>javase</artifactId>
+            <version>3.5.1</version>
+        </dependency>
+        <dependency>
             <groupId>com.aliyun.oss</groupId>
             <artifactId>aliyun-sdk-oss</artifactId>
             <version>3.17.4</version>
@@ -116,16 +126,7 @@
             <version>3.15.1</version> <!-- 使用最新稳定版本 -->
         </dependency>
 <!--二维码-->
-        <dependency>
-            <groupId>com.google.zxing</groupId>
-            <artifactId>core</artifactId>
-            <version>3.5.1</version>
-        </dependency>
-        <dependency>
-            <groupId>com.google.zxing</groupId>
-            <artifactId>javase</artifactId>
-            <version>3.5.1</version>
-        </dependency>
+
         <dependency>
             <groupId>com.belerweb</groupId>
             <artifactId>pinyin4j</artifactId>

+ 60 - 0
src/main/java/com/zhentao/osspicture/OssConfig.java

@@ -1,6 +1,7 @@
 package com.zhentao.osspicture;
 
 import lombok.Data;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.context.properties.ConfigurationProperties;
 import org.springframework.context.annotation.Configuration;
 
@@ -8,10 +9,69 @@ import org.springframework.context.annotation.Configuration;
 @Configuration
 @ConfigurationProperties(prefix = "aliyun.oss")
 public class OssConfig {
+    @Value("${aliyun.oss.endpoint}")
     private String endpoint;
+    @Value("${aliyun.oss.accessKeyId}")
     private String accessKeyId;
+    @Value("${aliyun.oss.accessKeySecret}")
     private String accessKeySecret;
+    @Value("${aliyun.oss.bucketName}")
     private String bucketName;
     private String fileHost;
     private Integer urlExpireTime;
+    /**
+     //     * 上传配置
+     //     */
+    private Upload upload = new Upload();
+
+    /**
+     * 上传配置内部类
+     */
+    @Data
+    public static class Upload {
+
+        /**
+         * 图片上传配置
+         */
+        private Image image = new Image();
+
+        /**
+         * 视频上传配置
+         */
+        private Video video = new Video();
+
+        /**
+         * 图片上传配置内部类
+         */
+        @Data
+        public static class Image {
+
+            /**
+             * 图片上传目录
+             */
+            private String dir = "moments/images/";
+
+            /**
+             * 图片最大大小(字节),默认10MB
+             */
+            private long maxSize = 10 * 1024 * 1024;
+        }
+
+        /**
+         * 视频上传配置内部类
+         */
+        @Data
+        public static class Video {
+
+            /**
+             * 视频上传目录
+             */
+            private String dir = "moments/videos/";
+
+            /**
+             * 视频最大大小(字节),默认50MB
+             */
+            private long maxSize = 50 * 1024 * 1024;
+        }
+    }
 }

+ 0 - 1
src/main/java/com/zhentao/osspicture/OssUtil.java

@@ -7,7 +7,6 @@ import org.springframework.stereotype.Component;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.io.IOException;
-import java.io.InputStream;
 import java.util.UUID;
 
 @Component

+ 60 - 0
src/main/java/com/zhentao/user/controller/QrCodeController.java

@@ -0,0 +1,60 @@
+package com.zhentao.user.controller;
+
+import com.google.zxing.BarcodeFormat;
+import com.google.zxing.MultiFormatWriter;
+import com.google.zxing.client.j2se.MatrixToImageWriter;
+import com.google.zxing.common.BitMatrix;
+import com.zhentao.config.NullLogin;
+import com.zhentao.user.dto.UserInfo;
+import org.springframework.web.bind.annotation.*;
+
+import javax.imageio.ImageIO;
+import java.awt.image.BufferedImage;
+import java.io.ByteArrayOutputStream;
+import java.util.Base64;
+import java.util.HashMap;
+import java.util.Map;
+
+@RestController
+@RequestMapping("api")
+public class QrCodeController {
+
+    // 生成带用户数据的二维码接口
+    @PostMapping("/generate")
+    @NullLogin
+    public Map<String, Object> generateQrCode(@RequestBody UserInfo userInfo) {
+        Map<String, Object> result = new HashMap<>();
+        try {
+            // 1. 处理用户数据
+
+            String dataToEncode = userInfo.getUserId().toString();
+
+            // 2. 生成二维码图片
+            int width = 300;
+            int height = 300;
+//            使用ZXIng ("Zebra Crossing")库来生成一个二维码图像
+            BitMatrix bitMatrix = new MultiFormatWriter().encode(dataToEncode, BarcodeFormat.QR_CODE, width, height);
+//            用于将bitMatrix变成图片
+            BufferedImage image = MatrixToImageWriter.toBufferedImage(bitMatrix);
+
+            // 3. 转换为Base64字符串
+//            这是一个输出流
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+//            把对象写入到创建的输出流中
+            ImageIO.write(image, "png", baos);
+//            将字节数组转换成byte数组
+            byte[] imageBytes = baos.toByteArray();
+//            这个字符串可以方便地在文本环境中传输和存储图像数据
+            String base64Image = Base64.getEncoder().encodeToString(imageBytes);
+
+            // 4. 返回结果
+            result.put("success", true);
+            result.put("qrCodeUrl", "data:image/png;base64," + base64Image);
+            result.put("expireTime", System.currentTimeMillis() + 3600000); // 1小时有效期
+        } catch (Exception e) {
+            result.put("success", false);
+            result.put("message", "生成二维码失败: " + e.getMessage());
+        }
+        return result;
+    }
+}

+ 1 - 1
src/main/java/com/zhentao/user/controller/UserController.java

@@ -67,7 +67,7 @@ public class UserController {
         return userLoginService.UserPassLogin(userPassDto);
     }
 
-//    忘记密码
+    //    忘记密码
     @PostMapping("/ForgetPass")
     @NullLogin
     public Result ForgetPass(@RequestBody @Valid ForgetPassDto forgetPassDto) {

+ 18 - 13
src/main/java/com/zhentao/user/domain/UserLogin.java

@@ -6,8 +6,6 @@ import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import java.io.Serializable;
 import java.util.Date;
-
-import com.fasterxml.jackson.annotation.JsonFormat;
 import lombok.Data;
 
 /**
@@ -21,7 +19,6 @@ public class UserLogin implements Serializable {
      * 用户ID
      */
     @TableId
-    @JsonFormat(shape = JsonFormat.Shape.STRING)
     private Long id;
 
     /**
@@ -50,11 +47,6 @@ public class UserLogin implements Serializable {
     private String avatar;
 
     /**
-     * 用户名称
-     */
-    private String userName;
-
-    /**
      * 性别1男2女3未知
      */
     private Integer gender;
@@ -95,7 +87,7 @@ public class UserLogin implements Serializable {
     private Integer days;
 
     /**
-     * 标签列表
+     * 背景
      */
     private String labelList;
 
@@ -125,22 +117,35 @@ public class UserLogin implements Serializable {
     private Date updatedTime;
 
     /**
-     *
+     * 
      */
     private String openId;
 
     /**
-     *
+     * 
      */
     private String sessionKey;
 
     /**
-     *
+     * 
      */
     private String uniId;
 
+    /**
+     * 邮箱
+     */
+    private String email;
 
+    /**
+     * 用户名称
+     */
+    private String userName;
+
+    /**
+     * 二维码
+     */
+    private String qwcode;
 
     @TableField(exist = false)
     private static final long serialVersionUID = 1L;
-}
+}

+ 1 - 1
src/main/java/com/zhentao/user/dto/UserInfo.java

@@ -4,7 +4,7 @@ import lombok.Data;
 
 @Data
 public class UserInfo {
-    private Integer userId;
+    private String userId;
 
     private String UserUsername;
 

+ 24 - 0
src/main/java/com/zhentao/user/dto/UserQwCodeDto.java

@@ -0,0 +1,24 @@
+package com.zhentao.user.dto;
+
+import com.baomidou.mybatisplus.annotation.TableId;
+import lombok.Data;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.Date;
+
+@Data
+public class UserQwCodeDto {
+
+    /**
+     * 用户ID
+     */
+    @TableId
+    private Long id;
+
+
+
+
+
+
+}

+ 2 - 2
src/main/java/com/zhentao/user/mapper/UserLoginMapper.java

@@ -4,9 +4,9 @@ import com.zhentao.user.domain.UserLogin;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 
 /**
-* @author 86183
+* @author lenovo
 * @description 针对表【user_login(用户)】的数据库操作Mapper
-* @createDate 2025-06-03 18:38:51
+* @createDate 2025-06-18 17:17:14
 * @Entity com.zhentao.user.domain.UserLogin
 */
 public interface UserLoginMapper extends BaseMapper<UserLogin> {

+ 4 - 4
src/main/java/com/zhentao/user/service/UserLoginService.java

@@ -10,10 +10,10 @@ import java.util.List;
 import java.util.Optional;
 
 /**
-* @author 86183
-* @description 针对表【user_login(用户)】的数据库操作Service
-* @createDate 2025-06-03 18:38:51
-*/
+ * @author 86183
+ * @description 针对表【user_login(用户)】的数据库操作Service
+ * @createDate 2025-06-03 18:38:51
+ */
 public interface UserLoginService extends IService<UserLogin> {
     //注册
     Result register(UserRegister userRegister);

+ 5 - 6
src/main/java/com/zhentao/user/service/impl/UserLoginServiceImpl.java

@@ -27,13 +27,13 @@ import java.util.UUID;
 import java.util.concurrent.TimeUnit;
 
 /**
-* @author 86183
-* @description 针对表【user_login(用户)】的数据库操作Service实现
-* @createDate 2025-06-03 18:38:51
-*/
+ * @author 86183
+ * @description 针对表【user_login(用户)】的数据库操作Service实现
+ * @createDate 2025-06-03 18:38:51
+ */
 @Service
 public class UserLoginServiceImpl extends ServiceImpl<UserLoginMapper, UserLogin>
-    implements UserLoginService{
+        implements UserLoginService{
     @Autowired
     private UserLoginMapper userLoginMapper;
     @Autowired
@@ -298,4 +298,3 @@ public class UserLoginServiceImpl extends ServiceImpl<UserLoginMapper, UserLogin
 
 
 
-

+ 1 - 1
src/main/java/com/zhentao/userRelationships/controller/UserRelationshipsController.java

@@ -30,7 +30,7 @@ public class UserRelationshipsController {
     }
 
     //添加好友发送申请
-    @PostMapping("/sendFriendRequest")
+    @PostMapping( "/sendFriendRequest")
     @NullLogin
     public Result sendFriendRequest(@RequestHeader("token") String token, @RequestParam Long receiverId, @RequestParam String message) {
         String userIdFromToken = TokenUtils.getUserIdFromToken(token);

+ 13 - 5
src/main/resources/application.yml

@@ -30,12 +30,20 @@ spring:
       port: 27017
       database: im_message_db
   redis:
-    host: 47.110.46.22
+    host: 101.200.59.170
     port: 6379
     database: 0
 aliyun:
   oss:
-    endpoint: https://oss-cn-beijing.aliyuncs.com
-    accessKeyId: LTAI5tH9VHPZwGJu4UX3hrL5
-    accessKeySecret: mbsutFJYLkzosvvKNr0DD28XSg4mqA
-    bucketName: fjj1
+    endpoint: https://oss-cn-beijing.aliyuncs.com  # OSS服务区域节点
+    accessKeyId: LTAI5tH9VHPZwGJu4UX3hrL5          # 替换为您的AccessKey ID
+    accessKeySecret: mbsutFJYLkzosvvKNr0DD28XSg4mqA  # 替换为您的AccessKey Secret
+    bucketName: fjj1             # 替换为您的Bucket名称
+    upload:
+      image:
+        dir: moments/images/                 # 图片上传目录
+        maxSize: 20971520                   # 图片最大大小(字节),默认10MB
+      video:
+        dir: moments/videos/                 # 视频上传目录
+        maxSize: 52428800
+

+ 10 - 7
src/main/resources/mapper/UserLoginMapper.xml

@@ -11,7 +11,6 @@
             <result property="salt" column="salt" jdbcType="VARCHAR"/>
             <result property="nickName" column="nick_name" jdbcType="VARCHAR"/>
             <result property="avatar" column="avatar" jdbcType="VARCHAR"/>
-            <result property="userName" column="user_name" jdbcType="VARCHAR"/>
             <result property="gender" column="gender" jdbcType="INTEGER"/>
             <result property="userIntro" column="user_intro" jdbcType="VARCHAR"/>
             <result property="userMobile" column="user_mobile" jdbcType="VARCHAR"/>
@@ -29,16 +28,20 @@
             <result property="openId" column="open_id" jdbcType="VARCHAR"/>
             <result property="sessionKey" column="session_key" jdbcType="VARCHAR"/>
             <result property="uniId" column="uni_id" jdbcType="VARCHAR"/>
+            <result property="email" column="email" jdbcType="VARCHAR"/>
+            <result property="userName" column="user_name" jdbcType="VARCHAR"/>
+            <result property="qwcode" column="qwcode" jdbcType="VARCHAR"/>
     </resultMap>
 
     <sql id="Base_Column_List">
         id,user_username,user_password,
         salt,nick_name,avatar,
-        user_name,gender,user_intro,
-        user_mobile,iden_no,grade_desc,
-        birth_day,birth_month,days,
-        label_list,status,remark,
-        created_time,updated_by,updated_time,
-        open_id,session_key,uni_id
+        gender,user_intro,user_mobile,
+        iden_no,grade_desc,birth_day,
+        birth_month,days,label_list,
+        status,remark,created_time,
+        updated_by,updated_time,open_id,
+        session_key,uni_id,email,
+        user_name,qwcode
     </sql>
 </mapper>