|
@@ -1,106 +1,48 @@
|
|
|
-package com.qmth.teachcloud.exchange.common.api;
|
|
|
-
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
-import com.qmth.boot.api.annotation.Aac;
|
|
|
-import com.qmth.boot.api.annotation.BOOL;
|
|
|
-import com.qmth.boot.api.constant.ApiConstant;
|
|
|
-import com.qmth.boot.tools.signature.SignatureEntity;
|
|
|
-import com.qmth.boot.tools.signature.SignatureType;
|
|
|
-import com.qmth.teachcloud.exchange.common.bean.params.OpenParams;
|
|
|
-import com.qmth.teachcloud.exchange.common.contant.SystemConstant;
|
|
|
-import com.qmth.teachcloud.exchange.common.entity.BasicSchool;
|
|
|
-import com.qmth.teachcloud.exchange.common.enums.ExceptionResultEnum;
|
|
|
-import com.qmth.teachcloud.exchange.common.service.BasicSchoolService;
|
|
|
-import com.qmth.teachcloud.exchange.common.util.JacksonUtil;
|
|
|
-import com.qmth.teachcloud.exchange.common.util.Result;
|
|
|
-import com.qmth.teachcloud.exchange.common.util.ServletUtil;
|
|
|
-import io.swagger.annotations.*;
|
|
|
-import org.slf4j.Logger;
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
-import org.springframework.validation.annotation.Validated;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
-import org.springframework.web.bind.annotation.RequestParam;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
-
|
|
|
-import javax.annotation.Resource;
|
|
|
-import javax.servlet.http.HttpServletResponse;
|
|
|
-import java.io.IOException;
|
|
|
-import java.net.URLDecoder;
|
|
|
-import java.net.URLEncoder;
|
|
|
-import java.util.Objects;
|
|
|
-import java.util.Optional;
|
|
|
-import java.util.StringJoiner;
|
|
|
-
|
|
|
-/**
|
|
|
- * <p>
|
|
|
- * 知学知考开放接口前端控制器
|
|
|
- * </p>
|
|
|
- *
|
|
|
- * @author wangliang
|
|
|
- * @since 2022-04-26
|
|
|
- */
|
|
|
-@Api(tags = "公用开放跳转接口Controller")
|
|
|
-@RestController
|
|
|
-@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + "/${prefix.url.open}/common")
|
|
|
-@Validated
|
|
|
-public class CommonOpenApiController {
|
|
|
- private static final Logger log = LoggerFactory.getLogger(CommonOpenApiController.class);
|
|
|
-
|
|
|
- @Resource
|
|
|
- private BasicSchoolService basicSchoolService;
|
|
|
-
|
|
|
- @Value("${cas.config.teachcloudPrintLoginUrl}")
|
|
|
- String teachcloudLoginUrl;
|
|
|
-
|
|
|
- @ApiOperation(value = "公用跳转接口")
|
|
|
- @ApiResponses({@ApiResponse(code = 200, message = "返回消息", response = Result.class)})
|
|
|
- @RequestMapping(value = "/authentication/teachcloud", method = RequestMethod.GET)
|
|
|
- @Aac(auth = BOOL.FALSE)
|
|
|
- public void authenticationTeachcloud(@ApiParam(value = "工号", required = true) @RequestParam String accountCommon,
|
|
|
- @ApiParam(value = "学校code", required = true) @RequestParam String schoolCodeCommon,
|
|
|
- @ApiParam(value = "返回url") @RequestParam(required = false) String returnUrlCommon,
|
|
|
- @ApiParam(value = "其它参数") @RequestParam(required = false) String paramsCommon) throws IOException {
|
|
|
- log.info("公用跳转接口进来了,account:{},schoolCode:{}", accountCommon, schoolCodeCommon);
|
|
|
- Optional.ofNullable(teachcloudLoginUrl).orElseThrow(() -> ExceptionResultEnum.PARAMS_ERROR.exception("知学登录跳转地址不存在"));
|
|
|
- Optional.ofNullable(accountCommon).orElseThrow(() -> ExceptionResultEnum.PARAMS_ERROR.exception("工号不存在"));
|
|
|
- Optional.ofNullable(schoolCodeCommon).orElseThrow(() -> ExceptionResultEnum.PARAMS_ERROR.exception("学校code不存在"));
|
|
|
-
|
|
|
-// accountUser = URLDecoder.decode(accountUser, SystemConstant.CHARSET_NAME);
|
|
|
-
|
|
|
- QueryWrapper<BasicSchool> basicSchoolQueryWrapper = new QueryWrapper<>();
|
|
|
- basicSchoolQueryWrapper.lambda().eq(BasicSchool::getCode, schoolCodeCommon);
|
|
|
- BasicSchool basicSchool = basicSchoolService.getOne(basicSchoolQueryWrapper);
|
|
|
- Optional.ofNullable(basicSchool).orElseThrow(() -> ExceptionResultEnum.PARAMS_ERROR.exception("学校信息不存在"));
|
|
|
-
|
|
|
- if (teachcloudLoginUrl.contains(SystemConstant.PATH_MATCH)) {
|
|
|
- teachcloudLoginUrl = teachcloudLoginUrl.replace(SystemConstant.PATH_MATCH, basicSchool.getCode());
|
|
|
- }
|
|
|
-
|
|
|
- long timestamp = System.currentTimeMillis();
|
|
|
- String path = teachcloudLoginUrl.substring(teachcloudLoginUrl.indexOf(SystemConstant.PATH_SUBSTR), teachcloudLoginUrl.length());
|
|
|
- String signature = SignatureEntity.build(SignatureType.SECRET, SystemConstant.GET, path, timestamp, basicSchool.getAccessKey(), basicSchool.getAccessSecret());
|
|
|
-
|
|
|
- StringJoiner stringJoiner = new StringJoiner("")
|
|
|
- .add(teachcloudLoginUrl)
|
|
|
- .add(SystemConstant.GET_UNKNOWN).add(SystemConstant.HEADER_TIME).add(SystemConstant.GET_EQUAL).add(String.valueOf(timestamp))
|
|
|
- .add(SystemConstant.GET_SYMBOL).add(SystemConstant.SIGNATURE).add(SystemConstant.GET_EQUAL).add(signature)
|
|
|
- .add(SystemConstant.GET_SYMBOL).add(SystemConstant.USER).add(SystemConstant.GET_EQUAL).add(accountCommon);
|
|
|
-
|
|
|
- if (Objects.nonNull(returnUrlCommon) && !Objects.equals(returnUrlCommon, "")) {
|
|
|
- stringJoiner = stringJoiner.add(SystemConstant.GET_SYMBOL).add(SystemConstant.RETURN_URL).add(SystemConstant.GET_EQUAL).add(returnUrlCommon);
|
|
|
- }
|
|
|
- if (Objects.nonNull(paramsCommon) && !Objects.equals(paramsCommon, "")) {
|
|
|
- String decodeJson = URLDecoder.decode(paramsCommon, SystemConstant.CHARSET_NAME);
|
|
|
- OpenParams openParams = JacksonUtil.readJson(decodeJson, OpenParams.class);
|
|
|
- stringJoiner = stringJoiner.add(SystemConstant.GET_SYMBOL).add(SystemConstant.PARAMS).add(SystemConstant.GET_EQUAL).add(JacksonUtil.parseJson(openParams));
|
|
|
- }
|
|
|
- String redirectUrl = URLEncoder.encode(stringJoiner.toString(), SystemConstant.CHARSET);
|
|
|
- log.info("path:{},timestamp:{},account:{},signature:{},redirectUrl:{},redirectUrl_urlencode:{}", path, timestamp, accountCommon, signature, stringJoiner.toString(), redirectUrl);
|
|
|
-
|
|
|
- HttpServletResponse response = ServletUtil.getResponse();
|
|
|
- response.setHeader("Access-Control-Allow-Origin", SystemConstant.PATH_MATCH);
|
|
|
- response.sendRedirect(redirectUrl);
|
|
|
- }
|
|
|
-}
|
|
|
+//package com.qmth.teachcloud.exchange.common.api;
|
|
|
+//
|
|
|
+//import com.qmth.boot.api.annotation.Aac;
|
|
|
+//import com.qmth.boot.api.annotation.BOOL;
|
|
|
+//import com.qmth.boot.api.constant.ApiConstant;
|
|
|
+//import com.qmth.teachcloud.exchange.common.service.CommonService;
|
|
|
+//import com.qmth.teachcloud.exchange.common.util.Result;
|
|
|
+//import io.swagger.annotations.*;
|
|
|
+//import org.slf4j.Logger;
|
|
|
+//import org.slf4j.LoggerFactory;
|
|
|
+//import org.springframework.validation.annotation.Validated;
|
|
|
+//import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+//import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
+//import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+//import org.springframework.web.bind.annotation.RestController;
|
|
|
+//
|
|
|
+//import javax.annotation.Resource;
|
|
|
+//import java.io.IOException;
|
|
|
+//
|
|
|
+///**
|
|
|
+// * <p>
|
|
|
+// * 知学知考开放接口前端控制器
|
|
|
+// * </p>
|
|
|
+// *
|
|
|
+// * @author wangliang
|
|
|
+// * @since 2022-04-26
|
|
|
+// */
|
|
|
+//@Api(tags = "公用开放跳转接口Controller")
|
|
|
+//@RestController
|
|
|
+//@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + "/${prefix.url.open}/common")
|
|
|
+//@Validated
|
|
|
+//public class CommonOpenApiController {
|
|
|
+// private static final Logger log = LoggerFactory.getLogger(CommonOpenApiController.class);
|
|
|
+//
|
|
|
+// @Resource
|
|
|
+// CommonService commonService;
|
|
|
+//
|
|
|
+// @ApiOperation(value = "公用跳转接口")
|
|
|
+// @ApiResponses({@ApiResponse(code = 200, message = "返回消息", response = Result.class)})
|
|
|
+// @RequestMapping(value = "/authentication/teachcloud", method = RequestMethod.POST)
|
|
|
+// @Aac(auth = BOOL.FALSE)
|
|
|
+// public void authenticationTeachcloud(@ApiParam(value = "工号", required = true) @RequestParam String account,
|
|
|
+// @ApiParam(value = "学校code", required = true) @RequestParam String schoolCode,
|
|
|
+// @ApiParam(value = "返回url") @RequestParam(required = false) String returnUrl,
|
|
|
+// @ApiParam(value = "其它参数") @RequestParam(required = false) String params) throws IOException {
|
|
|
+// commonService.redirectLogic(account, schoolCode, returnUrl, params);
|
|
|
+// }
|
|
|
+//}
|