leutu
2024-06-03 3ef35e6cd16bbfa206b26bb3271eac40ad020bcb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package com.fastbee.data.controller;
 
import com.fastbee.common.core.domain.AjaxResult;
import com.fastbee.common.core.domain.model.BindLoginBody;
import com.fastbee.common.core.domain.model.BindRegisterBody;
import com.fastbee.iot.service.ISocialLoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import me.zhyd.oauth.model.AuthCallback;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
 
/**
 * 第三方登录接口Controller
 *
 * @author json
 * @date 2022-04-12
 */
@Api(tags = "第三方登录接口")
@RestController
@RequestMapping("/auth")
public class SocialLoginController {
 
    @Autowired
    private ISocialLoginService iSocialLoginService;
 
 
    @GetMapping("/render/{source}")
    @ApiOperation("微信登录跳转二维码")
    @ApiImplicitParam(name = "source", value = "登录类型", required = true, dataType = "String", paramType = "path", dataTypeClass = String.class)
    public void renderAuth(HttpServletResponse httpServletResponse, HttpServletRequest httpServletRequest, @PathVariable String source) throws IOException {
        // 生成授权页面
        httpServletResponse.sendRedirect(iSocialLoginService.renderAuth(source, httpServletRequest));
    }
 
    @GetMapping("/callback/{source}")
    @ApiOperation("微信登录扫码回调api")
    @ApiImplicitParam(name = "source", value = "平台来源", required = true, dataType = "String", paramType = "path", dataTypeClass = String.class)
    public void login(@PathVariable("source") String source, AuthCallback authCallback, HttpServletResponse httpServletResponse, HttpServletRequest httpServletRequest) throws IOException {
        //回调接口
        httpServletResponse.sendRedirect(iSocialLoginService.callback(source, authCallback, httpServletRequest));
    }
 
    @GetMapping("/checkBindId/{bindId}")
    @ApiOperation("检查bindId")
    @ApiImplicitParam(name = "bindId", value = "绑定ID", required = true, dataType = "String", paramType = "path", dataTypeClass = String.class)
    public AjaxResult checkBindId(@PathVariable String bindId) {
        return iSocialLoginService.checkBindId(bindId);
    }
 
    @GetMapping("/getErrorMsg/{errorId}")
    @ApiOperation("获取errorMsg")
    @ApiImplicitParam(name = "errorId", value = "错误提示ID", required = true, dataType = "String", paramType = "path", dataTypeClass = String.class)
    public AjaxResult getErrorMsg(@PathVariable String errorId) {
        return iSocialLoginService.getErrorMsg(errorId);
    }
 
    /**
     * 已经绑定账户,跳转登录接口
     *
     * @param loginId
     * @return
     */
    @GetMapping("/login/{loginId}")
    @ApiOperation("跳转登录api")
    @ApiImplicitParam(name = "loginId", value = "登录Id", required = true, dataType = "String", paramType = "path", dataTypeClass = String.class)
    public AjaxResult socialLogin(@PathVariable String loginId) {
        // 生成授权页面
        return iSocialLoginService.socialLogin(loginId);
    }
 
    /**
     * 登录方法
     *
     * @param bindLoginBody 绑定登录信息
     * @return 结果
     */
    @ApiOperation("绑定登录方法")
    @PostMapping("/bind/login")
    public AjaxResult bindLogin(@RequestBody BindLoginBody bindLoginBody) {
        return iSocialLoginService.bindLogin(bindLoginBody);
    }
 
    /**
     * 注册绑定接口
     *
     * @param bindRegisterBody 注册信息
     * @return 注册绑定信息
     */
    @ApiOperation("注册绑定")
    @PostMapping("/bind/register")
    public AjaxResult bindRegister(@RequestBody BindRegisterBody bindRegisterBody) {
        return iSocialLoginService.bindRegister(bindRegisterBody);
    }
 
}