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);
|
}
|
}
|