chen.lin
1 天以前 b003a49794f49a329e2702918ecfc8d14b371d0d
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
package com.vincent.rsf.openApi.controller;
 
import com.vincent.rsf.framework.common.Cools;
import com.vincent.rsf.openApi.entity.constant.Constants;
import com.vincent.rsf.openApi.entity.dto.CommonResponse;
import com.vincent.rsf.openApi.entity.params.GetTokenParam;
import com.vincent.rsf.openApi.security.service.AppAuthService;
import com.vincent.rsf.openApi.security.utils.TokenUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
 
@RestController
@Api(tags = "应用认证管理")
public class AuthController {
 
    @Autowired
    private AppAuthService appAuthService;
 
    @ApiOperation("获取App认证Token")
    @PostMapping("/getToken")
    public CommonResponse getToken(@RequestBody GetTokenParam param) {
        String appId = param != null ? param.getAppId() : null;
        String appSecret = param != null ? param.getAppSecret() : null;
        if (Cools.isEmpty(appId, appSecret)) {
            return CommonResponse.error("AppId和AppSecret不能为空");
        }
        if (!appAuthService.validateApp(appId, appSecret)) {
            return CommonResponse.error("AppId或AppSecret无效");
        }
        String token = Constants.TOKEN_PREFIX + TokenUtils.generateToken(appId, appSecret);
        return CommonResponse.ok().setMsg("获取Token成功").setData(token);
    }
}