Переглянути джерело

"微信一键登录实现"

yu_u66 2 тижнів тому
батько
коміт
7fc469f13c

+ 40 - 0
src/main/java/com/futu/course/common/utils/CopyUtil.java

@@ -0,0 +1,40 @@
+package com.futu.course.common.utils;
+
+import org.springframework.beans.BeanUtils;
+import org.springframework.util.CollectionUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 实体字段的值复制工具类
+ */
+public class CopyUtil {
+
+    public static <T> List<T> copyList(List source, Class<T> clazz) {
+        List<T> target = new ArrayList<>();
+        if (!CollectionUtils.isEmpty(source)){
+            if (!CollectionUtils.isEmpty(source)){
+                for (Object c: source) {
+                    T obj = copy(c, clazz);
+                    target.add(obj);
+                }
+            }
+        }
+        return target;
+    }
+
+    public static <T> T copy(Object source, Class<T> clazz) {
+        if (source == null) {
+            return null;
+        }
+        T obj = null;
+        try {
+            obj = clazz.newInstance();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        BeanUtils.copyProperties(source, obj);
+        return obj;
+    }
+}

+ 66 - 0
src/main/java/com/futu/course/common/utils/EmojiConverterUtil.java

@@ -0,0 +1,66 @@
+package com.futu.course.common.utils;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * @author 杨杨吖
+ * @QQ 823208782
+ * @WX yjqi12345678
+ * @create 2022-03-24 10:38
+ */
+public class EmojiConverterUtil {
+
+    /**
+     * 将字符串中的emoji表情转换成可以在utf-8字符集数据库中保存的格式(表情占4个字节,需要utf8mb4字符集)
+     * @param str
+     * @return
+     */
+    public static String emojiConvert(String str)
+    {
+        String patternString = "([\\x{10000}-\\x{10ffff}\ud800-\udfff])";
+
+        Pattern pattern = Pattern.compile(patternString);
+        Matcher matcher = pattern.matcher(str);
+        StringBuffer sb = new StringBuffer();
+        while(matcher.find()) {
+            try {
+                matcher.appendReplacement(
+                        sb,
+                        "[["
+                                + URLEncoder.encode(matcher.group(1),
+                                "UTF-8") + "]]");
+            } catch(UnsupportedEncodingException e) {
+            }
+        }
+        matcher.appendTail(sb);
+        return sb.toString();
+    }
+
+    /**
+     * 还原utf8数据库中保存的含转换后emoji表情的字符串
+     * @param str
+     * @return
+     */
+    public static String emojiRecovery(String str){
+        String patternString = "\\[\\[(.*?)\\]\\]";
+
+        Pattern pattern = Pattern.compile(patternString);
+        Matcher matcher = pattern.matcher(str);
+
+        StringBuffer sb = new StringBuffer();
+        while(matcher.find()) {
+            try {
+                matcher.appendReplacement(sb,
+                        URLDecoder.decode(matcher.group(1), "UTF-8"));
+            } catch(UnsupportedEncodingException e) {
+
+            }
+        }
+        matcher.appendTail(sb);
+        return sb.toString();
+    }
+}

+ 73 - 0
src/main/java/com/futu/course/common/utils/SnowflakeIdWorker.java

@@ -0,0 +1,73 @@
+package com.futu.course.common.utils;
+
+import java.util.concurrent.atomic.AtomicLong;
+
+public class SnowflakeIdWorker {
+    // 时间起始标记点,作为基准,一般取系统的最近时间(一旦确定不能变动)
+    private final long twepoch = 1288834974657L;
+    // 机器标识位数
+    private final long workerIdBits = 5L;
+    // 数据标识位数
+    private final long datacenterIdBits = 5L;
+    // 支持的最大机器标识数
+    private final long maxWorkerId = -1L ^ (-1L << workerIdBits);
+    // 支持的最大数据标识数
+    private final long maxDatacenterId = -1L ^ (-1L << datacenterIdBits);
+    // 序列在id中占的位数
+    private final long sequenceBits = 12L;
+    // 机器ID向左移12位
+    private final long workerIdShift = sequenceBits;
+    // 数据标识符向左移17位(12+5)
+    private final long datacenterIdShift = sequenceBits + workerIdBits;
+    // 时间戳向左移22位(5+5+12)
+    private final long timestampLeftShift = sequenceBits + workerIdBits + datacenterIdBits;
+    private final long sequenceMask = -1L ^ (-1L << sequenceBits);
+    private long workerId;
+    private long datacenterId;
+    private long sequence = 0L;
+    private long lastTimestamp = -1L;
+    private final AtomicLong sequenceGenerator = new AtomicLong(0L);
+
+    public SnowflakeIdWorker(long workerId, long datacenterId) {
+        if (workerId > maxWorkerId || workerId < 0) {
+            throw new IllegalArgumentException(String.format("worker Id can't be greater than %d or less than 0", maxWorkerId));
+        }
+        if (datacenterId > maxDatacenterId || datacenterId < 0) {
+            throw new IllegalArgumentException(String.format("datacenter Id can't be greater than %d or less than 0", maxDatacenterId));
+        }
+        this.workerId = workerId;
+        this.datacenterId = datacenterId;
+    }
+
+    public synchronized long nextId() {
+        long timestamp = timeGen();
+        if (timestamp < lastTimestamp) {
+            throw new RuntimeException(String.format("Clock moved backwards. Refusing to generate id for %d milliseconds", lastTimestamp - timestamp));
+        }
+        if (lastTimestamp == timestamp) {
+            sequence = (sequence + 1) & sequenceMask;
+            if (sequence == 0) {
+                timestamp = tilNextMillis(lastTimestamp);
+            }
+        } else {
+            sequence = 0L;
+        }
+        lastTimestamp = timestamp;
+        return ((timestamp - twepoch) << timestampLeftShift) |
+                (datacenterId << datacenterIdShift) |
+                (workerId << workerIdShift) |
+                sequence;
+    }
+
+    protected long tilNextMillis(long lastTimestamp) {
+        long timestamp = timeGen();
+        while (timestamp <= lastTimestamp) {
+            timestamp = timeGen();
+        }
+        return timestamp;
+    }
+
+    protected long timeGen() {
+        return System.currentTimeMillis();
+    }
+}

+ 32 - 0
src/main/java/com/futu/course/user/controller/UserController.java

@@ -1,5 +1,6 @@
 package com.futu.course.user.controller;
 
+<<<<<<< HEAD
 import com.futu.course.user.service.impl.UserServiceImpl;
 import io.minio.errors.*;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -25,5 +26,36 @@ public class UserController {
     @PostMapping("unload")
     public String unload(MultipartFile multipartFile,Long uid) throws ServerException, InvalidBucketNameException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
         return userService.unload(multipartFile,uid);
+=======
+import com.futu.course.common.annotation.NonLoginRequired;
+import com.futu.course.common.entity.R;
+import com.futu.course.user.dto.UserDTO;
+import com.futu.course.user.service.UserService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping("user")
+public class UserController {
+
+
+    @Autowired
+    private UserService userService;
+
+    @NonLoginRequired
+    @PostMapping("wx_login")
+    public R wxLogin(@RequestBody UserDTO dto) {
+        return  userService.appLogin(dto);
+    }
+
+    @NonLoginRequired
+    @PostMapping("logout")
+    public R logout(@RequestBody UserDTO dto) {
+        System.out.println(dto);
+        return userService.logout(dto);
+>>>>>>> bba2fa3 ("微信一键登录实现")
     }
 }

+ 159 - 0
src/main/java/com/futu/course/user/domain/User.java

@@ -0,0 +1,159 @@
+package com.futu.course.user.domain;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import java.io.Serializable;
+import java.util.Date;
+import lombok.Data;
+
+/**
+ * 用户表
+ * @TableName user
+ */
+@TableName(value ="user")
+@Data
+public class User implements Serializable {
+    /**
+     * 用户ID(使用Snowflake算法生成)
+     */
+    @TableId
+    private Long id;
+
+    /**
+     *
+     */
+    private String openId;
+
+    /**
+     *
+     */
+    private String unionId;
+    @TableField(exist = false)
+    private String token;
+
+    /**
+     *
+     */
+    private String sessionKey;
+
+    /**
+     * 登录账号
+     */
+    private String username;
+
+    /**
+     * 加密后的密码
+     */
+    private String password;
+
+    /**
+     * 盐
+     */
+    private String salt;
+
+    /**
+     * 昵称
+     */
+    private String nickname;
+
+    /**
+     * 头像URL
+     */
+    private String avatar;
+
+    /**
+     * 手机号
+     */
+    private String mobile;
+
+    /**
+     * 会员等级(0-普通用户)
+     */
+    private Integer memberLevel;
+
+    /**
+     * 状态(0-禁用 1-正常)
+     */
+    private Integer status;
+
+    /**
+     *
+     */
+    private Date createTime;
+
+    @TableField(exist = false)
+    private static final long serialVersionUID = 1L;
+
+    @Override
+    public boolean equals(Object that) {
+        if (this == that) {
+            return true;
+        }
+        if (that == null) {
+            return false;
+        }
+        if (getClass() != that.getClass()) {
+            return false;
+        }
+        User other = (User) that;
+        return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
+            && (this.getOpenId() == null ? other.getOpenId() == null : this.getOpenId().equals(other.getOpenId()))
+            && (this.getUnionId() == null ? other.getUnionId() == null : this.getUnionId().equals(other.getUnionId()))
+            && (this.getSessionKey() == null ? other.getSessionKey() == null : this.getSessionKey().equals(other.getSessionKey()))
+            && (this.getUsername() == null ? other.getUsername() == null : this.getUsername().equals(other.getUsername()))
+            && (this.getPassword() == null ? other.getPassword() == null : this.getPassword().equals(other.getPassword()))
+            && (this.getSalt() == null ? other.getSalt() == null : this.getSalt().equals(other.getSalt()))
+            && (this.getNickname() == null ? other.getNickname() == null : this.getNickname().equals(other.getNickname()))
+            && (this.getAvatar() == null ? other.getAvatar() == null : this.getAvatar().equals(other.getAvatar()))
+            && (this.getMobile() == null ? other.getMobile() == null : this.getMobile().equals(other.getMobile()))
+            && (this.getMemberLevel() == null ? other.getMemberLevel() == null : this.getMemberLevel().equals(other.getMemberLevel()))
+            && (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus()))
+            && (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime()));
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
+        result = prime * result + ((getOpenId() == null) ? 0 : getOpenId().hashCode());
+        result = prime * result + ((getUnionId() == null) ? 0 : getUnionId().hashCode());
+        result = prime * result + ((getSessionKey() == null) ? 0 : getSessionKey().hashCode());
+        result = prime * result + ((getUsername() == null) ? 0 : getUsername().hashCode());
+        result = prime * result + ((getPassword() == null) ? 0 : getPassword().hashCode());
+        result = prime * result + ((getSalt() == null) ? 0 : getSalt().hashCode());
+        result = prime * result + ((getNickname() == null) ? 0 : getNickname().hashCode());
+        result = prime * result + ((getAvatar() == null) ? 0 : getAvatar().hashCode());
+        result = prime * result + ((getMobile() == null) ? 0 : getMobile().hashCode());
+        result = prime * result + ((getMemberLevel() == null) ? 0 : getMemberLevel().hashCode());
+        result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode());
+        result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode());
+        return result;
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        sb.append(getClass().getSimpleName());
+        sb.append(" [");
+        sb.append("Hash = ").append(hashCode());
+        sb.append(", id=").append(id);
+        sb.append(", openId=").append(openId);
+        sb.append(", unionId=").append(unionId);
+        sb.append(", sessionKey=").append(sessionKey);
+        sb.append(", username=").append(username);
+        sb.append(", password=").append(password);
+        sb.append(", salt=").append(salt);
+        sb.append(", nickname=").append(nickname);
+        sb.append(", avatar=").append(avatar);
+        sb.append(", mobile=").append(mobile);
+        sb.append(", memberLevel=").append(memberLevel);
+        sb.append(", status=").append(status);
+        sb.append(", createTime=").append(createTime);
+        sb.append(", serialVersionUID=").append(serialVersionUID);
+        sb.append("]");
+        return sb.toString();
+    }
+}

+ 885 - 0
src/main/java/com/futu/course/user/domain/UserExample.java

@@ -0,0 +1,885 @@
+package com.futu.course.user.domain;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class UserExample {
+    protected String orderByClause;
+
+    protected boolean distinct;
+
+    protected List<Criteria> oredCriteria;
+
+    public UserExample() {
+        oredCriteria = new ArrayList<Criteria>();
+    }
+
+    public void setOrderByClause(String orderByClause) {
+        this.orderByClause = orderByClause;
+    }
+
+    public String getOrderByClause() {
+        return orderByClause;
+    }
+
+    public void setDistinct(boolean distinct) {
+        this.distinct = distinct;
+    }
+
+    public boolean isDistinct() {
+        return distinct;
+    }
+
+    public List<Criteria> getOredCriteria() {
+        return oredCriteria;
+    }
+
+    public void or(Criteria criteria) {
+        oredCriteria.add(criteria);
+    }
+
+    public Criteria or() {
+        Criteria criteria = createCriteriaInternal();
+        oredCriteria.add(criteria);
+        return criteria;
+    }
+
+    public Criteria createCriteria() {
+        Criteria criteria = createCriteriaInternal();
+        if (oredCriteria.size() == 0) {
+            oredCriteria.add(criteria);
+        }
+        return criteria;
+    }
+
+    protected Criteria createCriteriaInternal() {
+        Criteria criteria = new Criteria();
+        return criteria;
+    }
+
+    public void clear() {
+        oredCriteria.clear();
+        orderByClause = null;
+        distinct = false;
+    }
+
+    protected abstract static class GeneratedCriteria {
+        protected List<Criterion> criteria;
+
+        protected GeneratedCriteria() {
+            super();
+            criteria = new ArrayList<Criterion>();
+        }
+
+        public boolean isValid() {
+            return criteria.size() > 0;
+        }
+
+        public List<Criterion> getAllCriteria() {
+            return criteria;
+        }
+
+        public List<Criterion> getCriteria() {
+            return criteria;
+        }
+
+        protected void addCriterion(String condition) {
+            if (condition == null) {
+                throw new RuntimeException("Value for condition cannot be null");
+            }
+            criteria.add(new Criterion(condition));
+        }
+
+        protected void addCriterion(String condition, Object value, String property) {
+            if (value == null) {
+                throw new RuntimeException("Value for " + property + " cannot be null");
+            }
+            criteria.add(new Criterion(condition, value));
+        }
+
+        protected void addCriterion(String condition, Object value1, Object value2, String property) {
+            if (value1 == null || value2 == null) {
+                throw new RuntimeException("Between values for " + property + " cannot be null");
+            }
+            criteria.add(new Criterion(condition, value1, value2));
+        }
+
+        public Criteria andIdIsNull() {
+            addCriterion("id is null");
+            return (Criteria) this;
+        }
+
+        public Criteria andIdIsNotNull() {
+            addCriterion("id is not null");
+            return (Criteria) this;
+        }
+
+        public Criteria andIdEqualTo(String value) {
+            addCriterion("id =", value, "id");
+            return (Criteria) this;
+        }
+
+        public Criteria andIdNotEqualTo(String value) {
+            addCriterion("id <>", value, "id");
+            return (Criteria) this;
+        }
+
+        public Criteria andIdGreaterThan(String value) {
+            addCriterion("id >", value, "id");
+            return (Criteria) this;
+        }
+
+        public Criteria andIdGreaterThanOrEqualTo(String value) {
+            addCriterion("id >=", value, "id");
+            return (Criteria) this;
+        }
+
+        public Criteria andIdLessThan(String value) {
+            addCriterion("id <", value, "id");
+            return (Criteria) this;
+        }
+
+        public Criteria andIdLessThanOrEqualTo(String value) {
+            addCriterion("id <=", value, "id");
+            return (Criteria) this;
+        }
+
+        public Criteria andIdLike(String value) {
+            addCriterion("id like", value, "id");
+            return (Criteria) this;
+        }
+
+        public Criteria andIdNotLike(String value) {
+            addCriterion("id not like", value, "id");
+            return (Criteria) this;
+        }
+
+        public Criteria andIdIn(List<String> values) {
+            addCriterion("id in", values, "id");
+            return (Criteria) this;
+        }
+
+        public Criteria andIdNotIn(List<String> values) {
+            addCriterion("id not in", values, "id");
+            return (Criteria) this;
+        }
+
+        public Criteria andIdBetween(String value1, String value2) {
+            addCriterion("id between", value1, value2, "id");
+            return (Criteria) this;
+        }
+
+        public Criteria andIdNotBetween(String value1, String value2) {
+            addCriterion("id not between", value1, value2, "id");
+            return (Criteria) this;
+        }
+
+        public Criteria andWxIdIsNull() {
+            addCriterion("wx_id is null");
+            return (Criteria) this;
+        }
+
+        public Criteria andWxIdIsNotNull() {
+            addCriterion("wx_id is not null");
+            return (Criteria) this;
+        }
+
+        public Criteria andWxIdEqualTo(String value) {
+            addCriterion("wx_id =", value, "wxId");
+            return (Criteria) this;
+        }
+
+        public Criteria andWxIdNotEqualTo(String value) {
+            addCriterion("wx_id <>", value, "wxId");
+            return (Criteria) this;
+        }
+
+        public Criteria andWxIdGreaterThan(String value) {
+            addCriterion("wx_id >", value, "wxId");
+            return (Criteria) this;
+        }
+
+        public Criteria andWxIdGreaterThanOrEqualTo(String value) {
+            addCriterion("wx_id >=", value, "wxId");
+            return (Criteria) this;
+        }
+
+        public Criteria andWxIdLessThan(String value) {
+            addCriterion("wx_id <", value, "wxId");
+            return (Criteria) this;
+        }
+
+        public Criteria andWxIdLessThanOrEqualTo(String value) {
+            addCriterion("wx_id <=", value, "wxId");
+            return (Criteria) this;
+        }
+
+        public Criteria andWxIdLike(String value) {
+            addCriterion("wx_id like", value, "wxId");
+            return (Criteria) this;
+        }
+
+        public Criteria andWxIdNotLike(String value) {
+            addCriterion("wx_id not like", value, "wxId");
+            return (Criteria) this;
+        }
+
+        public Criteria andWxIdIn(List<String> values) {
+            addCriterion("wx_id in", values, "wxId");
+            return (Criteria) this;
+        }
+
+        public Criteria andWxIdNotIn(List<String> values) {
+            addCriterion("wx_id not in", values, "wxId");
+            return (Criteria) this;
+        }
+
+        public Criteria andWxIdBetween(String value1, String value2) {
+            addCriterion("wx_id between", value1, value2, "wxId");
+            return (Criteria) this;
+        }
+
+        public Criteria andWxIdNotBetween(String value1, String value2) {
+            addCriterion("wx_id not between", value1, value2, "wxId");
+            return (Criteria) this;
+        }
+
+        public Criteria andHeadPicIsNull() {
+            addCriterion("head_pic is null");
+            return (Criteria) this;
+        }
+
+        public Criteria andHeadPicIsNotNull() {
+            addCriterion("head_pic is not null");
+            return (Criteria) this;
+        }
+
+        public Criteria andHeadPicEqualTo(String value) {
+            addCriterion("head_pic =", value, "headPic");
+            return (Criteria) this;
+        }
+
+        public Criteria andHeadPicNotEqualTo(String value) {
+            addCriterion("head_pic <>", value, "headPic");
+            return (Criteria) this;
+        }
+
+        public Criteria andHeadPicGreaterThan(String value) {
+            addCriterion("head_pic >", value, "headPic");
+            return (Criteria) this;
+        }
+
+        public Criteria andHeadPicGreaterThanOrEqualTo(String value) {
+            addCriterion("head_pic >=", value, "headPic");
+            return (Criteria) this;
+        }
+
+        public Criteria andHeadPicLessThan(String value) {
+            addCriterion("head_pic <", value, "headPic");
+            return (Criteria) this;
+        }
+
+        public Criteria andHeadPicLessThanOrEqualTo(String value) {
+            addCriterion("head_pic <=", value, "headPic");
+            return (Criteria) this;
+        }
+
+        public Criteria andHeadPicLike(String value) {
+            addCriterion("head_pic like", value, "headPic");
+            return (Criteria) this;
+        }
+
+        public Criteria andHeadPicNotLike(String value) {
+            addCriterion("head_pic not like", value, "headPic");
+            return (Criteria) this;
+        }
+
+        public Criteria andHeadPicIn(List<String> values) {
+            addCriterion("head_pic in", values, "headPic");
+            return (Criteria) this;
+        }
+
+        public Criteria andHeadPicNotIn(List<String> values) {
+            addCriterion("head_pic not in", values, "headPic");
+            return (Criteria) this;
+        }
+
+        public Criteria andHeadPicBetween(String value1, String value2) {
+            addCriterion("head_pic between", value1, value2, "headPic");
+            return (Criteria) this;
+        }
+
+        public Criteria andHeadPicNotBetween(String value1, String value2) {
+            addCriterion("head_pic not between", value1, value2, "headPic");
+            return (Criteria) this;
+        }
+
+        public Criteria andWxHeadPicIsNull() {
+            addCriterion("wx_head_pic is null");
+            return (Criteria) this;
+        }
+
+        public Criteria andWxHeadPicIsNotNull() {
+            addCriterion("wx_head_pic is not null");
+            return (Criteria) this;
+        }
+
+        public Criteria andWxHeadPicEqualTo(String value) {
+            addCriterion("wx_head_pic =", value, "wxHeadPic");
+            return (Criteria) this;
+        }
+
+        public Criteria andWxHeadPicNotEqualTo(String value) {
+            addCriterion("wx_head_pic <>", value, "wxHeadPic");
+            return (Criteria) this;
+        }
+
+        public Criteria andWxHeadPicGreaterThan(String value) {
+            addCriterion("wx_head_pic >", value, "wxHeadPic");
+            return (Criteria) this;
+        }
+
+        public Criteria andWxHeadPicGreaterThanOrEqualTo(String value) {
+            addCriterion("wx_head_pic >=", value, "wxHeadPic");
+            return (Criteria) this;
+        }
+
+        public Criteria andWxHeadPicLessThan(String value) {
+            addCriterion("wx_head_pic <", value, "wxHeadPic");
+            return (Criteria) this;
+        }
+
+        public Criteria andWxHeadPicLessThanOrEqualTo(String value) {
+            addCriterion("wx_head_pic <=", value, "wxHeadPic");
+            return (Criteria) this;
+        }
+
+        public Criteria andWxHeadPicLike(String value) {
+            addCriterion("wx_head_pic like", value, "wxHeadPic");
+            return (Criteria) this;
+        }
+
+        public Criteria andWxHeadPicNotLike(String value) {
+            addCriterion("wx_head_pic not like", value, "wxHeadPic");
+            return (Criteria) this;
+        }
+
+        public Criteria andWxHeadPicIn(List<String> values) {
+            addCriterion("wx_head_pic in", values, "wxHeadPic");
+            return (Criteria) this;
+        }
+
+        public Criteria andWxHeadPicNotIn(List<String> values) {
+            addCriterion("wx_head_pic not in", values, "wxHeadPic");
+            return (Criteria) this;
+        }
+
+        public Criteria andWxHeadPicBetween(String value1, String value2) {
+            addCriterion("wx_head_pic between", value1, value2, "wxHeadPic");
+            return (Criteria) this;
+        }
+
+        public Criteria andWxHeadPicNotBetween(String value1, String value2) {
+            addCriterion("wx_head_pic not between", value1, value2, "wxHeadPic");
+            return (Criteria) this;
+        }
+
+        public Criteria andPhoneIsNull() {
+            addCriterion("phone is null");
+            return (Criteria) this;
+        }
+
+        public Criteria andPhoneIsNotNull() {
+            addCriterion("phone is not null");
+            return (Criteria) this;
+        }
+
+        public Criteria andPhoneEqualTo(String value) {
+            addCriterion("phone =", value, "phone");
+            return (Criteria) this;
+        }
+
+        public Criteria andPhoneNotEqualTo(String value) {
+            addCriterion("phone <>", value, "phone");
+            return (Criteria) this;
+        }
+
+        public Criteria andPhoneGreaterThan(String value) {
+            addCriterion("phone >", value, "phone");
+            return (Criteria) this;
+        }
+
+        public Criteria andPhoneGreaterThanOrEqualTo(String value) {
+            addCriterion("phone >=", value, "phone");
+            return (Criteria) this;
+        }
+
+        public Criteria andPhoneLessThan(String value) {
+            addCriterion("phone <", value, "phone");
+            return (Criteria) this;
+        }
+
+        public Criteria andPhoneLessThanOrEqualTo(String value) {
+            addCriterion("phone <=", value, "phone");
+            return (Criteria) this;
+        }
+
+        public Criteria andPhoneLike(String value) {
+            addCriterion("phone like", value, "phone");
+            return (Criteria) this;
+        }
+
+        public Criteria andPhoneNotLike(String value) {
+            addCriterion("phone not like", value, "phone");
+            return (Criteria) this;
+        }
+
+        public Criteria andPhoneIn(List<String> values) {
+            addCriterion("phone in", values, "phone");
+            return (Criteria) this;
+        }
+
+        public Criteria andPhoneNotIn(List<String> values) {
+            addCriterion("phone not in", values, "phone");
+            return (Criteria) this;
+        }
+
+        public Criteria andPhoneBetween(String value1, String value2) {
+            addCriterion("phone between", value1, value2, "phone");
+            return (Criteria) this;
+        }
+
+        public Criteria andPhoneNotBetween(String value1, String value2) {
+            addCriterion("phone not between", value1, value2, "phone");
+            return (Criteria) this;
+        }
+
+        public Criteria andRoleIdIsNull() {
+            addCriterion("role_id is null");
+            return (Criteria) this;
+        }
+
+        public Criteria andRoleIdIsNotNull() {
+            addCriterion("role_id is not null");
+            return (Criteria) this;
+        }
+
+        public Criteria andRoleIdEqualTo(Integer value) {
+            addCriterion("role_id =", value, "roleId");
+            return (Criteria) this;
+        }
+
+        public Criteria andRoleIdNotEqualTo(Integer value) {
+            addCriterion("role_id <>", value, "roleId");
+            return (Criteria) this;
+        }
+
+        public Criteria andRoleIdGreaterThan(Integer value) {
+            addCriterion("role_id >", value, "roleId");
+            return (Criteria) this;
+        }
+
+        public Criteria andRoleIdGreaterThanOrEqualTo(Integer value) {
+            addCriterion("role_id >=", value, "roleId");
+            return (Criteria) this;
+        }
+
+        public Criteria andRoleIdLessThan(Integer value) {
+            addCriterion("role_id <", value, "roleId");
+            return (Criteria) this;
+        }
+
+        public Criteria andRoleIdLessThanOrEqualTo(Integer value) {
+            addCriterion("role_id <=", value, "roleId");
+            return (Criteria) this;
+        }
+
+        public Criteria andRoleIdIn(List<Integer> values) {
+            addCriterion("role_id in", values, "roleId");
+            return (Criteria) this;
+        }
+
+        public Criteria andRoleIdNotIn(List<Integer> values) {
+            addCriterion("role_id not in", values, "roleId");
+            return (Criteria) this;
+        }
+
+        public Criteria andRoleIdBetween(Integer value1, Integer value2) {
+            addCriterion("role_id between", value1, value2, "roleId");
+            return (Criteria) this;
+        }
+
+        public Criteria andRoleIdNotBetween(Integer value1, Integer value2) {
+            addCriterion("role_id not between", value1, value2, "roleId");
+            return (Criteria) this;
+        }
+
+        public Criteria andSexIsNull() {
+            addCriterion("sex is null");
+            return (Criteria) this;
+        }
+
+        public Criteria andSexIsNotNull() {
+            addCriterion("sex is not null");
+            return (Criteria) this;
+        }
+
+        public Criteria andSexEqualTo(Integer value) {
+            addCriterion("sex =", value, "sex");
+            return (Criteria) this;
+        }
+
+        public Criteria andSexNotEqualTo(Integer value) {
+            addCriterion("sex <>", value, "sex");
+            return (Criteria) this;
+        }
+
+        public Criteria andSexGreaterThan(Integer value) {
+            addCriterion("sex >", value, "sex");
+            return (Criteria) this;
+        }
+
+        public Criteria andSexGreaterThanOrEqualTo(Integer value) {
+            addCriterion("sex >=", value, "sex");
+            return (Criteria) this;
+        }
+
+        public Criteria andSexLessThan(Integer value) {
+            addCriterion("sex <", value, "sex");
+            return (Criteria) this;
+        }
+
+        public Criteria andSexLessThanOrEqualTo(Integer value) {
+            addCriterion("sex <=", value, "sex");
+            return (Criteria) this;
+        }
+
+        public Criteria andSexIn(List<Integer> values) {
+            addCriterion("sex in", values, "sex");
+            return (Criteria) this;
+        }
+
+        public Criteria andSexNotIn(List<Integer> values) {
+            addCriterion("sex not in", values, "sex");
+            return (Criteria) this;
+        }
+
+        public Criteria andSexBetween(Integer value1, Integer value2) {
+            addCriterion("sex between", value1, value2, "sex");
+            return (Criteria) this;
+        }
+
+        public Criteria andSexNotBetween(Integer value1, Integer value2) {
+            addCriterion("sex not between", value1, value2, "sex");
+            return (Criteria) this;
+        }
+
+        public Criteria andUsernameIsNull() {
+            addCriterion("username is null");
+            return (Criteria) this;
+        }
+
+        public Criteria andUsernameIsNotNull() {
+            addCriterion("username is not null");
+            return (Criteria) this;
+        }
+
+        public Criteria andUsernameEqualTo(String value) {
+            addCriterion("username =", value, "username");
+            return (Criteria) this;
+        }
+
+        public Criteria andUsernameNotEqualTo(String value) {
+            addCriterion("username <>", value, "username");
+            return (Criteria) this;
+        }
+
+        public Criteria andUsernameGreaterThan(String value) {
+            addCriterion("username >", value, "username");
+            return (Criteria) this;
+        }
+
+        public Criteria andUsernameGreaterThanOrEqualTo(String value) {
+            addCriterion("username >=", value, "username");
+            return (Criteria) this;
+        }
+
+        public Criteria andUsernameLessThan(String value) {
+            addCriterion("username <", value, "username");
+            return (Criteria) this;
+        }
+
+        public Criteria andUsernameLessThanOrEqualTo(String value) {
+            addCriterion("username <=", value, "username");
+            return (Criteria) this;
+        }
+
+        public Criteria andUsernameLike(String value) {
+            addCriterion("username like", value, "username");
+            return (Criteria) this;
+        }
+
+        public Criteria andUsernameNotLike(String value) {
+            addCriterion("username not like", value, "username");
+            return (Criteria) this;
+        }
+
+        public Criteria andUsernameIn(List<String> values) {
+            addCriterion("username in", values, "username");
+            return (Criteria) this;
+        }
+
+        public Criteria andUsernameNotIn(List<String> values) {
+            addCriterion("username not in", values, "username");
+            return (Criteria) this;
+        }
+
+        public Criteria andUsernameBetween(String value1, String value2) {
+            addCriterion("username between", value1, value2, "username");
+            return (Criteria) this;
+        }
+
+        public Criteria andUsernameNotBetween(String value1, String value2) {
+            addCriterion("username not between", value1, value2, "username");
+            return (Criteria) this;
+        }
+
+        public Criteria andWxUsernameIsNull() {
+            addCriterion("wx_username is null");
+            return (Criteria) this;
+        }
+
+        public Criteria andWxUsernameIsNotNull() {
+            addCriterion("wx_username is not null");
+            return (Criteria) this;
+        }
+
+        public Criteria andWxUsernameEqualTo(String value) {
+            addCriterion("wx_username =", value, "wxUsername");
+            return (Criteria) this;
+        }
+
+        public Criteria andWxUsernameNotEqualTo(String value) {
+            addCriterion("wx_username <>", value, "wxUsername");
+            return (Criteria) this;
+        }
+
+        public Criteria andWxUsernameGreaterThan(String value) {
+            addCriterion("wx_username >", value, "wxUsername");
+            return (Criteria) this;
+        }
+
+        public Criteria andWxUsernameGreaterThanOrEqualTo(String value) {
+            addCriterion("wx_username >=", value, "wxUsername");
+            return (Criteria) this;
+        }
+
+        public Criteria andWxUsernameLessThan(String value) {
+            addCriterion("wx_username <", value, "wxUsername");
+            return (Criteria) this;
+        }
+
+        public Criteria andWxUsernameLessThanOrEqualTo(String value) {
+            addCriterion("wx_username <=", value, "wxUsername");
+            return (Criteria) this;
+        }
+
+        public Criteria andWxUsernameLike(String value) {
+            addCriterion("wx_username like", value, "wxUsername");
+            return (Criteria) this;
+        }
+
+        public Criteria andWxUsernameNotLike(String value) {
+            addCriterion("wx_username not like", value, "wxUsername");
+            return (Criteria) this;
+        }
+
+        public Criteria andWxUsernameIn(List<String> values) {
+            addCriterion("wx_username in", values, "wxUsername");
+            return (Criteria) this;
+        }
+
+        public Criteria andWxUsernameNotIn(List<String> values) {
+            addCriterion("wx_username not in", values, "wxUsername");
+            return (Criteria) this;
+        }
+
+        public Criteria andWxUsernameBetween(String value1, String value2) {
+            addCriterion("wx_username between", value1, value2, "wxUsername");
+            return (Criteria) this;
+        }
+
+        public Criteria andWxUsernameNotBetween(String value1, String value2) {
+            addCriterion("wx_username not between", value1, value2, "wxUsername");
+            return (Criteria) this;
+        }
+
+        public Criteria andPasswordIsNull() {
+            addCriterion("`password` is null");
+            return (Criteria) this;
+        }
+
+        public Criteria andPasswordIsNotNull() {
+            addCriterion("`password` is not null");
+            return (Criteria) this;
+        }
+
+        public Criteria andPasswordEqualTo(String value) {
+            addCriterion("`password` =", value, "password");
+            return (Criteria) this;
+        }
+
+        public Criteria andPasswordNotEqualTo(String value) {
+            addCriterion("`password` <>", value, "password");
+            return (Criteria) this;
+        }
+
+        public Criteria andPasswordGreaterThan(String value) {
+            addCriterion("`password` >", value, "password");
+            return (Criteria) this;
+        }
+
+        public Criteria andPasswordGreaterThanOrEqualTo(String value) {
+            addCriterion("`password` >=", value, "password");
+            return (Criteria) this;
+        }
+
+        public Criteria andPasswordLessThan(String value) {
+            addCriterion("`password` <", value, "password");
+            return (Criteria) this;
+        }
+
+        public Criteria andPasswordLessThanOrEqualTo(String value) {
+            addCriterion("`password` <=", value, "password");
+            return (Criteria) this;
+        }
+
+        public Criteria andPasswordLike(String value) {
+            addCriterion("`password` like", value, "password");
+            return (Criteria) this;
+        }
+
+        public Criteria andPasswordNotLike(String value) {
+            addCriterion("`password` not like", value, "password");
+            return (Criteria) this;
+        }
+
+        public Criteria andPasswordIn(List<String> values) {
+            addCriterion("`password` in", values, "password");
+            return (Criteria) this;
+        }
+
+        public Criteria andPasswordNotIn(List<String> values) {
+            addCriterion("`password` not in", values, "password");
+            return (Criteria) this;
+        }
+
+        public Criteria andPasswordBetween(String value1, String value2) {
+            addCriterion("`password` between", value1, value2, "password");
+            return (Criteria) this;
+        }
+
+        public Criteria andPasswordNotBetween(String value1, String value2) {
+            addCriterion("`password` not between", value1, value2, "password");
+            return (Criteria) this;
+        }
+
+        public Criteria andOpenIdEqualTo(String wxId) {
+            addCriterion("open_id =", wxId, "openId");
+            return (Criteria) this;
+        }
+    }
+
+    public static class Criteria extends GeneratedCriteria {
+
+        protected Criteria() {
+            super();
+        }
+    }
+
+    public static class Criterion {
+        private String condition;
+
+        private Object value;
+
+        private Object secondValue;
+
+        private boolean noValue;
+
+        private boolean singleValue;
+
+        private boolean betweenValue;
+
+        private boolean listValue;
+
+        private String typeHandler;
+
+        public String getCondition() {
+            return condition;
+        }
+
+        public Object getValue() {
+            return value;
+        }
+
+        public Object getSecondValue() {
+            return secondValue;
+        }
+
+        public boolean isNoValue() {
+            return noValue;
+        }
+
+        public boolean isSingleValue() {
+            return singleValue;
+        }
+
+        public boolean isBetweenValue() {
+            return betweenValue;
+        }
+
+        public boolean isListValue() {
+            return listValue;
+        }
+
+        public String getTypeHandler() {
+            return typeHandler;
+        }
+
+        protected Criterion(String condition) {
+            super();
+            this.condition = condition;
+            this.typeHandler = null;
+            this.noValue = true;
+        }
+
+        protected Criterion(String condition, Object value, String typeHandler) {
+            super();
+            this.condition = condition;
+            this.value = value;
+            this.typeHandler = typeHandler;
+            if (value instanceof List<?>) {
+                this.listValue = true;
+            } else {
+                this.singleValue = true;
+            }
+        }
+
+        protected Criterion(String condition, Object value) {
+            this(condition, value, null);
+        }
+
+        protected Criterion(String condition, Object value, Object secondValue, String typeHandler) {
+            super();
+            this.condition = condition;
+            this.value = value;
+            this.secondValue = secondValue;
+            this.typeHandler = typeHandler;
+            this.betweenValue = true;
+        }
+
+        protected Criterion(String condition, Object value, Object secondValue) {
+            this(condition, value, secondValue, null);
+        }
+    }
+}

+ 16 - 0
src/main/java/com/futu/course/user/dto/LoginDTO.java

@@ -0,0 +1,16 @@
+package com.futu.course.user.dto;
+
+import lombok.Data;
+
+@Data
+public class LoginDTO {
+    private String openid;
+
+    private String session_key;
+
+    private String unionId;
+
+    private Integer errCode;
+
+    private String errMsg;
+}

+ 38 - 0
src/main/java/com/futu/course/user/dto/UserDTO.java

@@ -0,0 +1,38 @@
+package com.futu.course.user.dto;
+
+import lombok.Data;
+
+@Data
+public class UserDTO {
+    private String id;
+
+    private String wxId;
+
+    private String headPic;
+
+    private String wxHeadPic;
+
+    private String phone;
+
+    private Integer roleId;
+
+    private Integer sex;
+
+    private String username;
+
+    private String wxUsername;
+
+    private String code;
+
+    private String token;
+
+    private String password;
+
+    private String captcha;
+
+    private String correctCaptcha;
+    private String encryptedData;
+    private String iv;
+
+
+}

+ 18 - 0
src/main/java/com/futu/course/user/mapper/UserMapper.java

@@ -0,0 +1,18 @@
+package com.futu.course.user.mapper;
+
+import com.futu.course.user.domain.User;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+* @author yuu
+* @description 针对表【user(用户表)】的数据库操作Mapper
+* @createDate 2025-05-07 08:26:30
+* @Entity com.futu.course.user.domain.User
+*/
+public interface UserMapper extends BaseMapper<User> {
+
+}
+
+
+
+

+ 17 - 0
src/main/java/com/futu/course/user/service/UserService.java

@@ -1,13 +1,30 @@
 package com.futu.course.user.service;
 
+<<<<<<< HEAD
 import com.futu.course.user.domain.User;
 import com.baomidou.mybatisplus.extension.service.IService;
+=======
+import com.futu.course.common.entity.R;
+import com.futu.course.user.domain.User;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.futu.course.user.dto.UserDTO;
+>>>>>>> bba2fa3 ("微信一键登录实现")
 
 /**
 * @author yuu
 * @description 针对表【user(用户表)】的数据库操作Service
+<<<<<<< HEAD
 * @createDate 2025-05-05 18:52:53
 */
 public interface UserService extends IService<User> {
 
+=======
+* @createDate 2025-05-07 08:26:30
+*/
+public interface UserService extends IService<User> {
+
+    R appLogin(UserDTO dto);
+
+    R logout(UserDTO dto);
+>>>>>>> bba2fa3 ("微信一键登录实现")
 }

+ 167 - 0
src/main/java/com/futu/course/user/service/impl/UserServiceImpl.java

@@ -1,5 +1,6 @@
 package com.futu.course.user.service.impl;
 
+<<<<<<< HEAD
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.futu.course.user.domain.User;
 import com.futu.course.user.service.UserService;
@@ -10,12 +11,178 @@ import org.springframework.stereotype.Service;
 * @author yuu
 * @description 针对表【user(用户表)】的数据库操作Service实现
 * @createDate 2025-05-05 18:52:53
+=======
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.futu.course.common.entity.R;
+import com.futu.course.common.utils.SnowflakeIdWorker;
+import com.futu.course.common.utils.TokenUtils;
+import com.futu.course.user.domain.User;
+import com.futu.course.user.dto.LoginDTO;
+import com.futu.course.user.dto.UserDTO;
+import com.futu.course.user.service.UserService;
+import com.futu.course.user.mapper.UserMapper;
+import io.jsonwebtoken.Jwts;
+import io.jsonwebtoken.SignatureAlgorithm;
+import io.jsonwebtoken.security.Keys;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.core.StringRedisTemplate;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import javax.crypto.Cipher;
+import javax.crypto.SecretKey;
+import javax.crypto.spec.IvParameterSpec;
+import javax.crypto.spec.SecretKeySpec;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+/**
+* @author yuu
+* @description 针对表【user(用户表)】的数据库操作Service实现
+* @createDate 2025-05-07 08:26:30
+>>>>>>> bba2fa3 ("微信一键登录实现")
 */
 @Service
 public class UserServiceImpl extends ServiceImpl<UserMapper, User>
     implements UserService{
+<<<<<<< HEAD
 
 }
+=======
+    @Autowired
+    private UserMapper userMapper;
+
+    @Autowired
+    private RedisTemplate redisTemplate;
+
+    // 填写上你的AppID,如何获取AppID自行百度,这步骤很简单
+    private final static String APP_ID = "wxdbcbc020c8e4b0d9";
+    // 填写上你的AppSecret,如何获取AppSecret自行百度,这步骤很简单
+    private final static String APP_SECRET = "60efa9e4ff7fae35c7f561de7763da7a";
+    // 微信小程序登录校验请求地址
+    private final static String LOGIN_URL = "https://api.weixin.qq.com/sns/jscode2session";
+    @Override
+    public R appLogin(UserDTO dto) {
+
+        SnowflakeIdWorker worker=new SnowflakeIdWorker(1,1);
+        System.out.println(dto);
+        String url = LOGIN_URL + "?appid=" + APP_ID + "&secret="+ APP_SECRET + "&grant_type=authorization_code&js_code=" + dto.getCode();
+        HttpClient client = HttpClients.createDefault(); // 创建默认http连接
+        HttpGet getRequest = new HttpGet(url);// 创建一个post请求
+        LoginDTO loginDTO = new LoginDTO();
+        try {
+            // 用http连接去执行get请求并且获得http响应
+            HttpResponse response = client.execute(getRequest);
+            // 从response中取到响实体
+            HttpEntity entity = response.getEntity();
+            // 把响应实体转成文本
+            String html = EntityUtils.toString(entity);
+            loginDTO = JSON.parseObject(html, LoginDTO.class);
+            if(null == loginDTO.getErrCode()) {
+                dto.setWxId(loginDTO.getOpenid());
+            } else {
+                return R.restResult(loginDTO,loginDTO.getErrCode(),loginDTO.getErrMsg());
+            }
+            List<User> users = userMapper.selectList(new LambdaQueryWrapper<User>().eq(User::getOpenId, dto.getWxId()));
+            if(users.size() > 0) {
+                User user = users.get(0);
+                // 生成一个 256 位(32 字节)的安全密钥
+                SecretKey key = Keys.secretKeyFor(SignatureAlgorithm.HS256);
+                // 使用密钥生成 JWT
+                String jws = Jwts.builder()
+                        .setSubject(user.getId().toString())
+                        .signWith(key)
+                        .compact();
+                user.setToken(jws);
+                redisTemplate.opsForValue().set("user",user,1, TimeUnit.DAYS);
+                return R.ok(user);
+            }
+              else {
+                User user = new User();
+                String sessionKey = loginDTO.getSession_key();
+
+                String encryptedData = dto.getEncryptedData();
+
+                String iv = dto.getIv();
+
+                String decryptedData1 = decryptData(encryptedData, sessionKey, iv);
+                System.out.println("解密后的数据:" + decryptedData1);
+                String decryptedData = decryptData(encryptedData, sessionKey, iv);
+                JSONObject jsonObject = JSON.parseObject(decryptedData);
+
+                String unionId = jsonObject.getString("unionId"); // 提取 unionId
+
+                user.setOpenId(loginDTO.getOpenid());
+                user.setSessionKey(loginDTO.getSession_key());
+                user.setUnionId(dto.getWxId());
+                user.setAvatar(dto.getWxHeadPic());
+                    user.setUsername(dto.getWxUsername());
+                   user.setNickname(dto.getWxUsername());
+                    user.setId(worker.nextId());
+                    user.setPassword(null);
+                // 生成一个 256 位(32 字节)的安全密钥
+                SecretKey key = Keys.secretKeyFor(SignatureAlgorithm.HS256);
+                // 使用密钥生成 JWT
+                String jws = Jwts.builder()
+                        .setSubject(user.getId().toString())
+                        .signWith(key)
+                        .compact();
+                user.setToken(jws);
+                    userMapper.insert(user);
+                redisTemplate.opsForValue().set("user",user,1, TimeUnit.DAYS);
+                    return R.ok(user);
+                }
+            } catch (ClientProtocolException e) {
+            throw new RuntimeException(e);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+
+    }
+
+    @Override
+    public R logout(UserDTO dto) {
+        if (redisTemplate.opsForValue().get("user") != null)
+        {
+            redisTemplate.delete("user");
+        }
+        return R.ok("登出成功");
+    }
+
+
+    public static String decryptData(String encryptedData, String sessionKey, String iv) throws Exception {
+        // Base64 解码
+        byte[] encryptedDataBytes = Base64.decodeBase64(encryptedData);
+        byte[] sessionKeyBytes = Base64.decodeBase64(sessionKey);
+        byte[] ivBytes = Base64.decodeBase64(iv);
+
+        // 初始化 AES 解密器
+        Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
+        SecretKeySpec keySpec = new SecretKeySpec(sessionKeyBytes, "AES");
+        IvParameterSpec ivSpec = new IvParameterSpec(ivBytes);
+        cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);
+
+        // 执行解密
+        byte[] decryptedBytes = cipher.doFinal(encryptedDataBytes);
+        return new String(decryptedBytes, StandardCharsets.UTF_8);
+    }
+
+    }
+>>>>>>> bba2fa3 ("微信一键登录实现")
 
 
 

+ 30 - 0
src/main/resources/mapper/UserMapper.xml

@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.futu.course.user.mapper.UserMapper">
+
+    <resultMap id="BaseResultMap" type="com.futu.course.user.domain.User">
+            <id property="id" column="id" jdbcType="BIGINT"/>
+            <result property="openId" column="open_id" jdbcType="VARCHAR"/>
+            <result property="unionId" column="union_id" jdbcType="VARCHAR"/>
+            <result property="sessionKey" column="session_key" jdbcType="VARCHAR"/>
+            <result property="username" column="username" jdbcType="VARCHAR"/>
+            <result property="password" column="password" jdbcType="VARCHAR"/>
+            <result property="salt" column="salt" jdbcType="VARCHAR"/>
+            <result property="nickname" column="nickname" jdbcType="VARCHAR"/>
+            <result property="avatar" column="avatar" jdbcType="VARCHAR"/>
+            <result property="mobile" column="mobile" jdbcType="VARCHAR"/>
+            <result property="memberLevel" column="member_level" jdbcType="TINYINT"/>
+            <result property="status" column="status" jdbcType="TINYINT"/>
+            <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
+    </resultMap>
+
+    <sql id="Base_Column_List">
+        id,open_id,union_id,
+        session_key,username,password,
+        salt,nickname,avatar,
+        mobile,member_level,status,
+        create_time
+    </sql>
+</mapper>