|
|
@@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.uas.account.AccountConfig;
|
|
|
import com.uas.sso.*;
|
|
|
+import com.uas.sso.bihe.entity.OAuthRoot;
|
|
|
+import com.uas.sso.bihe.service.BiHeService;
|
|
|
import com.uas.sso.common.util.HttpUtil;
|
|
|
import com.uas.sso.core.Const;
|
|
|
import com.uas.sso.entity.*;
|
|
|
@@ -21,6 +23,7 @@ import org.springframework.util.StringUtils;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
import java.io.IOException;
|
|
|
import java.util.*;
|
|
|
|
|
|
@@ -72,6 +75,9 @@ public class LoginController extends BaseController {
|
|
|
@Autowired
|
|
|
private WeChatService weChatService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private BiHeService biHeService;
|
|
|
+
|
|
|
@RequestMapping(method = RequestMethod.POST)
|
|
|
public ModelMap login() {
|
|
|
// 获取登录信息
|
|
|
@@ -824,4 +830,45 @@ public class LoginController extends BaseController {
|
|
|
return success(login(user.getUserUU(), appId, spaceUU, returnUrl));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 碧合登录接口
|
|
|
+ * @param appId 应用id(优软云应用id)
|
|
|
+ * @param code 第三方获取用户信息code
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/bhLogin", method = RequestMethod.POST)
|
|
|
+ public ModelMap bhLogin(@RequestParam(defaultValue = "city") String appId, String code) {
|
|
|
+ // 获取用户信息
|
|
|
+ User user = null;
|
|
|
+ OAuthRoot oAuthInfo = biHeService.getOAuthInfoByCode(code);
|
|
|
+
|
|
|
+ String accessToken = Optional.ofNullable(oAuthInfo).map(OAuthRoot::getData).map(com.uas.sso.bihe.entity.OAuthInfo::getAccessToken).orElse(null);
|
|
|
+ if (StringUtils.isEmpty(accessToken)) {
|
|
|
+ Long userUU = (Long) request.getSession().getAttribute("userUU");
|
|
|
+ if (userUU == null) {
|
|
|
+ return error("验证信息过期");
|
|
|
+ }
|
|
|
+ user = new User(userUU);
|
|
|
+ } else {
|
|
|
+ user = userService.findByBhOpenId(oAuthInfo.getData().getOpenId());
|
|
|
+ request.getSession().setAttribute("userUU", user.getUserUU());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (user == null) {
|
|
|
+ // 提示前端用户微信未绑定账号
|
|
|
+ Token token = new Token(oAuthInfo, oAuthInfo.getData().getExpires_in());
|
|
|
+ tokenService.save(token);
|
|
|
+ ModelMap data = new ModelMap("hasRegister", false);
|
|
|
+ data.put("token", token.getId());
|
|
|
+ return success(data);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 登录
|
|
|
+ WafRequestWrapper wr = new WafRequestWrapper(request);
|
|
|
+ String spaceUU = wr.getParameter("spaceUU");
|
|
|
+ String returnUrl = wr.getParameter("returnUrl");
|
|
|
+ String baseUrl = wr.getParameter("baseUrl");
|
|
|
+ request.getSession().setAttribute("baseUrl", baseUrl);
|
|
|
+ return success(login(user.getUserUU(), appId, spaceUU, returnUrl));
|
|
|
+ }
|
|
|
}
|