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.

106 lines
2.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# 微信小程序登录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. 创建数据库和表
```sql
# 执行src/main/resources/db/wx_miniapp.sql脚本
```
2. 修改数据库连接信息(`application.yml`
```yaml
spring:
datasource:
url: jdbc:mysql://localhost:3306/wx_miniapp?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
username: root
password: 1234
```
## 微信小程序配置
修改`application.yml`中的微信小程序配置:
```yaml
wechat:
miniapp:
appid: 你的小程序APPID
secret: 你的小程序SECRET
```
## 启动项目
```bash
mvn spring-boot:run
```
## 接口说明
### 1. 登录接口
- URL: `/api/wx/login`
- Method: POST
- Body:
```json
{
"code": "微信临时登录凭证"
}
```
- Response:
```json
{
"success": true,
"code": 200,
"message": "操作成功",
"data": {
"token": "JWT令牌"
}
}
```
### 2. 获取用户信息接口
- URL: `/api/wx/user`
- Method: GET
- Headers:
```
Authorization: 登录接口返回的token
```
- Response:
```json
{
"success": true,
"code": 200,
"message": "操作成功",
"data": {
"id": 1,
"openid": "用户openid",
"nickname": "用户昵称",
"avatarUrl": "头像URL",
"gender": 1,
"country": "国家",
"province": "省份",
"city": "城市",
"language": "语言"
}
}
```