|
|
@@ -1,6 +1,5 @@
|
|
|
package com.cyksj.web.controller.cps;
|
|
|
|
|
|
-import cn.hutool.core.codec.Base64;
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
@@ -29,7 +28,6 @@ import com.cyksj.service.authorization.AuthorizationService;
|
|
|
import com.cyksj.service.cps.CpsManageService;
|
|
|
import com.cyksj.service.wechat.WeChatService;
|
|
|
import com.cyksj.web.util.StpCpsManageUser;
|
|
|
-import com.cyksj.web.util.StpUserUtil;
|
|
|
import com.ejlchina.searcher.BeanSearcher;
|
|
|
import com.ejlchina.searcher.SearchResult;
|
|
|
import com.ejlchina.searcher.util.MapBuilder;
|
|
|
@@ -37,7 +35,6 @@ import com.ejlchina.searcher.util.MapUtils;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
-import javax.servlet.http.Cookie;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.math.BigDecimal;
|
|
|
@@ -110,7 +107,8 @@ public class CpsBackLoginController {
|
|
|
public Result<String> wxAuthorize() throws Exception {
|
|
|
String wxAuthUrl = redisService.getStr(RedisService.key.WX_LOGIN_AUTH_URI.getNameFormat(wxOpenPlatYHLXLoginConfig.getAppId()));
|
|
|
Long mappingId = SEQUENCE.nextId();
|
|
|
- redisService.set(mappingId.toString(), wxOpenPlatYHLXLoginConfig.getCpsLoginUrl(), 60 * 60 * 24L);
|
|
|
+ String authState = mappingId.toString();
|
|
|
+ redisService.set(authState, authState, 60 * 60 * 24L);
|
|
|
AuthRedirect redirect = new AuthRedirect().setMappingId(mappingId);
|
|
|
String state = Codec.DoBase64.custom().setData(Jsons.toJson(redirect)).encodeAsText();
|
|
|
if (StrUtil.isEmpty(wxAuthUrl)) {
|
|
|
@@ -124,7 +122,8 @@ public class CpsBackLoginController {
|
|
|
*/
|
|
|
@GetMapping("/wx/authLogin/baseRedirect")
|
|
|
public void wxAuthLoginRedirect(String code, String state, HttpServletResponse response) throws Exception {
|
|
|
-
|
|
|
+ String json = Codec.DoBase64.custom().setData(state).decodeAsText();
|
|
|
+ AuthRedirect re = Jsons.parseObject(json, AuthRedirect.class);
|
|
|
AuthToken token = weChatService.getAuthToken(code, wxOpenPlatYHLXLoginConfig.getAppId());
|
|
|
GzhOAuth2UserInfo userinfo = weChatService.getUserInfo(token.getAccessToken(), token.getOpenid());
|
|
|
String unionId = userinfo.getUnionid();
|
|
|
@@ -139,30 +138,28 @@ public class CpsBackLoginController {
|
|
|
if (user == null) throw BusinessRuntimeException.getInstance("用户信息不存在");
|
|
|
UserDistribute userDistribute = userDistributeMapper.selectOne(Wrappers.lambdaQuery(UserDistribute.class).eq(UserDistribute::getUserId, user.getId()).select(UserDistribute::getId).last("limit 1"));
|
|
|
if (userDistribute == null) throw BusinessRuntimeException.getInstance("只支持渠道分销用户登录");
|
|
|
-
|
|
|
- //写回登陆信息
|
|
|
+ JSONObject res = new JSONObject();
|
|
|
StpCpsManageUser.login(user.getId());
|
|
|
- response.addHeader("satoken-cpsUser", StpCpsManageUser.getTokenValue());
|
|
|
-
|
|
|
- Cookie cookie = new Cookie("satoken-cpsUser", StpCpsManageUser.getTokenValue());
|
|
|
- cookie.setMaxAge(31536000);
|
|
|
- cookie.setPath("/");
|
|
|
- response.addCookie(cookie);
|
|
|
- JSONObject jsonObject = new JSONObject();
|
|
|
- jsonObject.putOpt("img", user.getHeadimgurl());
|
|
|
- jsonObject.putOpt("nickname", user.getNickname());
|
|
|
+ String cpsToken = StpCpsManageUser.getTokenValue();
|
|
|
+ res.putOpt("satoken-cpsUser", cpsToken);
|
|
|
+ res.putOpt("img", user.getHeadimgurl());
|
|
|
+ res.putOpt("nickname", user.getNickname());
|
|
|
+ redisService.set(RedisService.key.CPS_AUTH_SUCCESS_KEY.getNameFormat(re.getMappingId()), res.toString(), RedisService.key.CPS_BACK_LOGIN_KEY.getTimeout());
|
|
|
+ }
|
|
|
|
|
|
- Cookie userInfo = new Cookie("info", Base64.encode(jsonObject.toString()));
|
|
|
- cookie.setMaxAge(31536000);
|
|
|
- cookie.setPath("/");
|
|
|
- response.addCookie(userInfo);
|
|
|
- // 转跳参数
|
|
|
- String json = Codec.DoBase64.custom().setData(state).decodeAsText();
|
|
|
- AuthRedirect re = Jsons.parseObject(json, AuthRedirect.class);
|
|
|
- String url = redisService.getStr(re.getMappingId().toString());
|
|
|
- response.sendRedirect(url.contains("?") ? url + "&t=" + StpUserUtil.getTokenValue() : url + "?t=" + StpUserUtil.getTokenValue());
|
|
|
+ /**
|
|
|
+ * 用户是否已授权
|
|
|
+ */
|
|
|
+ @GetMapping("/get/userInfo")
|
|
|
+ public Result<String> getCpsUserInfo(String authState) {
|
|
|
+ String key = RedisService.key.CPS_AUTH_SUCCESS_KEY.getNameFormat(authState);
|
|
|
+ Object o = redisService.get(key);
|
|
|
+ if (o == null) return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
+ redisService.del(key);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(o.toString());
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 个人分销平台数据详情
|
|
|
*/
|