yangys
2025-11-20 537d302507bf5bdc6f6b81ece701abb6e8b6a1e1
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
package com.qianwen.smartman.modules.auth.endpoint;
 
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.qianwen.core.log.annotation.ApiLog;
import com.qianwen.core.social.request.CustomAuthWeChatEntWebRequest;
import com.qianwen.core.tool.api.R;
import com.qianwen.core.tool.support.Kv;
import com.qianwen.smartman.modules.auth.enums.AccountType;
import com.qianwen.smartman.modules.auth.provider.TokenParameter;
import com.qianwen.smartman.modules.auth.service.MicroAppAuthService;
import com.qianwen.smartman.modules.auth.vo.AuthConfigVO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
@RequestMapping({"blade-auth"})
@Api(value = "钉钉企微微应用三方登陆", tags = {"钉钉企微微应用三方登陆"})
@RestController
public class MicroAppAuthEndpoint {
    private MicroAppAuthService microAppAuthService;
 
    public MicroAppAuthEndpoint(final MicroAppAuthService microAppAuthService) {
        this.microAppAuthService = microAppAuthService;
    }
 
    @GetMapping({"/oauth/app/config"})
    @ApiLog("获取配置信息")
    @ApiOperation("获取配置信息")
    public R<AuthConfigVO> config(String source) {
        return R.data(this.microAppAuthService.getAuthConfig(source));
    }
 
    @GetMapping({"/oauth/app/code-login"})
    @ApiLog("钉钉微应用授权码登录")
    @ApiOperation("根据授权码登录")
    public R<Kv> loginByCode(@RequestParam String code, @RequestParam(required = false) String state, @RequestParam String source) {
        TokenParameter tokenParameter = new TokenParameter();
        tokenParameter.getArgs().set("code", code);
        tokenParameter.getArgs().set("source", source);
        tokenParameter.getArgs().set("state", state);
        return this.microAppAuthService.loginByCode(tokenParameter);
    }
 
    @GetMapping({"/oauth/app/login"})
    @ApiLog("用户名密码登录")
    @ApiOperation("用户密码登录")
    public R<Kv> loginByPassword(@RequestParam @ApiParam(value = "账号", required = true) String username, @RequestParam @ApiParam(value = "密码", required = true) String password, @RequestParam(required = false) @ApiParam("认证ID") String oauthId, @RequestParam(required = false) @ApiParam("三方登录标识") String source) {
        return this.microAppAuthService.loginByPassword(username, password, oauthId);
    }
 
    @GetMapping({"/oauth/app/wechat-enterprise-web/sign"})
    @ApiLog("企业微信获取企业签名信息")
    @ApiOperation("企业微信获取企业签名信息")
    public R<CustomAuthWeChatEntWebRequest.SignatureResult> weChatSign(@RequestParam @ApiParam("当前网页的URL, 不包含#及其后面部分") String url, boolean isAgent) {
        return this.microAppAuthService.getWeChatSiginValue(url, isAgent);
    }
 
    @GetMapping({"/oauth/app/change-account"})
    @ApiLog("切换员工和用户token")
    @ApiOperation("切换员工和用户token")
    public R changeAccount(@RequestParam @ApiParam(value = "账号", required = true) String userId, @RequestParam @ApiParam(value = "需要切换的账号类型", required = true) AccountType type) {
        return this.microAppAuthService.loginByToggleAccount(userId, type);
    }
 
    @GetMapping({"/oauth/app/refresh-token"})
    @ApiLog("刷新token")
    @ApiOperation("刷新员工和账号token")
    public R refreshToken(@RequestParam @ApiParam("需要刷新的账号类型") AccountType accountType, @RequestParam @ApiParam("刷新token") String refreshToken) {
        return this.microAppAuthService.refreshToken(accountType, refreshToken);
    }
}