| | |
| | | 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 com.vincent.rsf.openApi.service.TokenService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | public class AuthController { |
| | | |
| | | @Autowired |
| | | private AppAuthService appAuthService; |
| | | private TokenService tokenService; |
| | | |
| | | @ApiOperation("获取App认证Token") |
| | | @PostMapping("/getToken") |
| | |
| | | if (Cools.isEmpty(appId, appSecret)) { |
| | | return CommonResponse.error("AppId和AppSecret不能为空"); |
| | | } |
| | | if (!appAuthService.validateApp(appId, appSecret)) { |
| | | String token = tokenService.issueToken(appId, appSecret); |
| | | if (token == null) { |
| | | return CommonResponse.error("AppId或AppSecret无效"); |
| | | } |
| | | String token = Constants.TOKEN_PREFIX + TokenUtils.generateToken(appId, appSecret); |
| | | return CommonResponse.ok().setMsg("获取Token成功").setData(token); |
| | | } |
| | | } |