初始化
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user