|
|
@@ -1,8 +1,8 @@
|
|
|
package com.uas.sso.bihe.controller;
|
|
|
|
|
|
-import com.uas.sso.bihe.entity.OAuthInfo;
|
|
|
-import com.uas.sso.bihe.entity.OAuthRoot;
|
|
|
-import com.uas.sso.bihe.entity.UserRoot;
|
|
|
+import com.uas.sso.bihe.entity.BiHeInfo;
|
|
|
+import com.uas.sso.bihe.entity.BiHeResult;
|
|
|
+import com.uas.sso.bihe.entity.BiHeUserInfo;
|
|
|
import com.uas.sso.bihe.service.BiHeService;
|
|
|
import com.uas.sso.controller.BaseController;
|
|
|
import com.uas.sso.entity.Token;
|
|
|
@@ -11,16 +11,17 @@ import com.uas.sso.service.UserService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.ui.ModelMap;
|
|
|
import org.springframework.util.Assert;
|
|
|
-import org.springframework.web.bind.annotation.PathVariable;
|
|
|
-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.*;
|
|
|
+
|
|
|
+import java.util.Optional;
|
|
|
|
|
|
/**
|
|
|
* @author wangmh
|
|
|
* @create 2018-07-19 10:52
|
|
|
* @desc 碧合controller
|
|
|
**/
|
|
|
+@RestController
|
|
|
+@RequestMapping("/bh")
|
|
|
public class BiHeController extends BaseController {
|
|
|
|
|
|
@Autowired
|
|
|
@@ -37,18 +38,24 @@ public class BiHeController extends BaseController {
|
|
|
*/
|
|
|
@RequestMapping(value = "/addAccount", method = RequestMethod.POST)
|
|
|
public ModelMap addAccount(@RequestParam String t, String username, String password) {
|
|
|
+ // 获取token
|
|
|
Token token = tokenService.findOne(t);
|
|
|
if (token == null || token.isExpired()) {
|
|
|
return error("绑定失败");
|
|
|
}
|
|
|
|
|
|
- Token unionidToken = tokenService.findOne(t);
|
|
|
- if (unionidToken != null) {
|
|
|
- OAuthRoot oAuthInfo = (OAuthRoot) unionidToken.getBind();
|
|
|
- User user = userService.bindBhUnionId(username, password, oAuthInfo.getData().getOpenId());
|
|
|
- request.getSession().setAttribute("userUU", user.getUserUU());
|
|
|
+ // 获取碧合AccessToken
|
|
|
+ ModelMap data = (ModelMap) token.getBind();
|
|
|
+ Optional<BiHeInfo> biHeInfo = Optional.ofNullable(data).map(value -> (BiHeInfo) value.get("data"));
|
|
|
+ if (!biHeInfo.isPresent()) {
|
|
|
+ return error("参数错误,绑定失败");
|
|
|
}
|
|
|
|
|
|
+ // 绑定bhOpenId
|
|
|
+ User user = userService.bindBhOpenId(username, password, biHeInfo.get().getOpenId());
|
|
|
+ request.getSession().setAttribute("userUU", user.getUserUU());
|
|
|
+
|
|
|
+ // 删除token
|
|
|
tokenService.delete(t);
|
|
|
|
|
|
return success();
|
|
|
@@ -56,16 +63,24 @@ public class BiHeController extends BaseController {
|
|
|
|
|
|
/**
|
|
|
* 获取用户
|
|
|
- * @param t
|
|
|
- * @return
|
|
|
+ * @param t tokenId,存储碧合AccessToken信息
|
|
|
+ * @return 碧合用户头像和名称
|
|
|
*/
|
|
|
- @RequestMapping(value = "/userinfo/{token}",method = RequestMethod.GET)
|
|
|
- public ModelMap findUserByToken(@PathVariable("token")String t){
|
|
|
- Token token =tokenService.findOne(t);
|
|
|
+ @RequestMapping(value = "/userInfo/{token}",method = RequestMethod.GET)
|
|
|
+ public ModelMap findUserByToken(@PathVariable("token") String t) {
|
|
|
+ // 获取token
|
|
|
+ Token token = tokenService.findOne(t);
|
|
|
Assert.notNull(token, "验证信息过期");
|
|
|
- Assert.isTrue(token.getBind() instanceof OAuthInfo, "参数错误");
|
|
|
- OAuthInfo oAuthInfo = (OAuthInfo) token.getBind();
|
|
|
- UserRoot userRoot = biHeService.getUserInfoByAccessToken(oAuthInfo.getOpenId(), oAuthInfo.getAccessToken());
|
|
|
+
|
|
|
+ // 获取token中碧合AccessToken信息
|
|
|
+ ModelMap data = (ModelMap) token.getBind();
|
|
|
+ Optional<BiHeInfo> biHeInfo = Optional.ofNullable(data).map(value -> (BiHeInfo) value.get("data"));
|
|
|
+ if (!biHeInfo.isPresent()) {
|
|
|
+ return error("参数错误,绑定失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 根据AccessToken获取用户信息
|
|
|
+ BiHeResult<BiHeUserInfo> userRoot = biHeService.getUserInfoByAccessToken(biHeInfo.get().getAccessToken(), biHeInfo.get().getOpenId());
|
|
|
return success(userRoot);
|
|
|
}
|
|
|
}
|