You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
guo-yao-whu d40a16a1b6
后端轮数
2 months ago
..
.idea 立论和复盘 3 months ago
src/main 后端轮数 2 months ago
target/classes 后端轮数 2 months ago
README.md yhf_4/1 4 months ago
pom.xml yhf_4/1 4 months ago

README.md

微信小程序登录Demo后端

项目介绍

本项目是一个微信小程序登录的后端Demo实现了微信小程序登录、获取用户信息等功能。

技术栈

  • Spring Boot 3.0.12
  • MyBatis 3.0.1
  • MySQL 8.0
  • JWT

项目结构

src/main/java/com/learning/newdemo
├── config         // 配置类
├── controller     // 控制器
├── entity         // 实体类
├── mapper         // 数据访问层
├── service        // 服务层
│   └── impl       // 服务实现
├── util           // 工具类
└── common         // 通用类

运行环境

  • JDK 17+
  • MySQL 8.0+
  • Maven 3.6+

数据库配置

  1. 创建数据库和表
# 执行src/main/resources/db/wx_miniapp.sql脚本
  1. 修改数据库连接信息(application.yml
spring:
  datasource:
    url: jdbc:mysql://localhost:3306/wx_miniapp?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
    username: root
    password: 1234

微信小程序配置

修改application.yml中的微信小程序配置:

wechat:
  miniapp:
    appid: 你的小程序APPID
    secret: 你的小程序SECRET

启动项目

mvn spring-boot:run

接口说明

1. 登录接口

  • URL: /api/wx/login
  • Method: POST
  • Body:
{
    "code": "微信临时登录凭证"
}
  • Response:
{
    "success": true,
    "code": 200,
    "message": "操作成功",
    "data": {
        "token": "JWT令牌"
    }
}

2. 获取用户信息接口

  • URL: /api/wx/user
  • Method: GET
  • Headers:
Authorization: 登录接口返回的token
  • Response:
{
    "success": true,
    "code": 200,
    "message": "操作成功",
    "data": {
        "id": 1,
        "openid": "用户openid",
        "nickname": "用户昵称",
        "avatarUrl": "头像URL",
        "gender": 1,
        "country": "国家",
        "province": "省份",
        "city": "城市",
        "language": "语言"
    }
}