初始化

This commit is contained in:
2026-01-18 21:49:20 +08:00
parent e60298df01
commit 2f119ebf7f
11 changed files with 1144 additions and 0 deletions

34
ruoyi-client/pom.xml Normal file
View File

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>ruoyi</artifactId>
<groupId>com.ruoyi</groupId>
<version>3.9.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ruoyi-client</artifactId>
<description>
用户端服务模块,支持第三方登录(微信、支付宝、抖音)
</description>
<dependencies>
<!-- 通用工具-->
<dependency>
<groupId>com.ruoyi</groupId>
<artifactId>ruoyi-common</artifactId>
</dependency>
<!-- 系统模块包含第三方SDK -->
<dependency>
<groupId>com.ruoyi</groupId>
<artifactId>ruoyi-system</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,184 @@
package com.ruoyi.client.controller;
import com.ruoyi.system.domain.thirdparty.LoginRequest;
import com.ruoyi.system.domain.thirdparty.LoginResponse;
import com.ruoyi.system.service.thirdparty.ThirdPartyLoginService;
import com.ruoyi.system.service.thirdparty.impl.WeChatLoginServiceImpl;
import com.ruoyi.system.service.thirdparty.impl.AlipayLoginServiceImpl;
import com.ruoyi.system.service.thirdparty.impl.DouyinLoginServiceImpl;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.Map;
/**
* 第三方登录Controller
*/
@RestController
@RequestMapping("/client/login")
public class ThirdPartyLoginController extends BaseController
{
@Autowired
private WeChatLoginServiceImpl weChatLoginService;
@Autowired
private AlipayLoginServiceImpl alipayLoginService;
@Autowired
private DouyinLoginServiceImpl douyinLoginService;
/**
* 统一第三方登录接口
*/
@Anonymous
@PostMapping("/thirdParty")
public AjaxResult thirdPartyLogin(@RequestBody LoginRequest request)
{
try
{
ThirdPartyLoginService loginService = getLoginService(request.getLoginType());
if (loginService == null)
{
return AjaxResult.error("不支持的登录类型");
}
LoginResponse response = loginService.login(request);
Map<String, Object> result = new HashMap<>();
result.put("userId", response.getUserId());
result.put("username", response.getUsername());
result.put("nickname", response.getNickname());
result.put("avatar", response.getAvatar());
result.put("token", response.getToken());
result.put("userLevel", response.getUserLevel());
result.put("coin", response.getCoin());
result.put("diamond", response.getDiamond());
result.put("isNewUser", response.getIsNewUser());
return AjaxResult.success(result);
}
catch (Exception e)
{
logger.error("第三方登录失败", e);
return AjaxResult.error("登录失败:" + e.getMessage());
}
}
/**
* 微信登录
*/
@Anonymous
@PostMapping("/wechat")
public AjaxResult wechatLogin(@RequestBody LoginRequest request)
{
try
{
LoginResponse response = weChatLoginService.login(request);
Map<String, Object> result = new HashMap<>();
result.put("userId", response.getUserId());
result.put("username", response.getUsername());
result.put("nickname", response.getNickname());
result.put("avatar", response.getAvatar());
result.put("token", response.getToken());
result.put("userLevel", response.getUserLevel());
result.put("coin", response.getCoin());
result.put("diamond", response.getDiamond());
result.put("isNewUser", response.getIsNewUser());
return AjaxResult.success(result);
}
catch (Exception e)
{
logger.error("微信登录失败", e);
return AjaxResult.error("登录失败:" + e.getMessage());
}
}
/**
* 支付宝登录
*/
@Anonymous
@PostMapping("/alipay")
public AjaxResult alipayLogin(@RequestBody LoginRequest request)
{
try
{
LoginResponse response = alipayLoginService.login(request);
Map<String, Object> result = new HashMap<>();
result.put("userId", response.getUserId());
result.put("username", response.getUsername());
result.put("nickname", response.getNickname());
result.put("avatar", response.getAvatar());
result.put("token", response.getToken());
result.put("userLevel", response.getUserLevel());
result.put("coin", response.getCoin());
result.put("diamond", response.getDiamond());
result.put("isNewUser", response.getIsNewUser());
return AjaxResult.success(result);
}
catch (Exception e)
{
logger.error("支付宝登录失败", e);
return AjaxResult.error("登录失败:" + e.getMessage());
}
}
/**
* 抖音登录
*/
@Anonymous
@PostMapping("/douyin")
public AjaxResult douyinLogin(@RequestBody LoginRequest request)
{
try
{
LoginResponse response = douyinLoginService.login(request);
Map<String, Object> result = new HashMap<>();
result.put("userId", response.getUserId());
result.put("username", response.getUsername());
result.put("nickname", response.getNickname());
result.put("avatar", response.getAvatar());
result.put("token", response.getToken());
result.put("userLevel", response.getUserLevel());
result.put("coin", response.getCoin());
result.put("diamond", response.getDiamond());
result.put("isNewUser", response.getIsNewUser());
return AjaxResult.success(result);
}
catch (Exception e)
{
logger.error("抖音登录失败", e);
return AjaxResult.error("登录失败:" + e.getMessage());
}
}
/**
* 根据登录类型获取对应的服务
*/
private ThirdPartyLoginService getLoginService(String loginType)
{
if ("wechat".equalsIgnoreCase(loginType))
{
return weChatLoginService;
}
else if ("alipay".equalsIgnoreCase(loginType))
{
return alipayLoginService;
}
else if ("douyin".equalsIgnoreCase(loginType))
{
return douyinLoginService;
}
return null;
}
}