|
@@ -4,6 +4,7 @@ import cn.binarywang.wx.miniapp.api.WxMaUserService;
|
|
|
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
|
|
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
|
|
|
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
|
|
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
|
|
|
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
|
|
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
|
|
|
|
|
+import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
|
|
|
import cn.hutool.core.date.DateTime;
|
|
import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.druid.support.json.JSONUtils;
|
|
import com.alibaba.druid.support.json.JSONUtils;
|
|
@@ -50,7 +51,7 @@ public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, MallUserInf
|
|
|
private IWxAppConfigService wxAppConfigService;
|
|
private IWxAppConfigService wxAppConfigService;
|
|
|
@Resource
|
|
@Resource
|
|
|
private RedisTemplate redisTemplate;
|
|
private RedisTemplate redisTemplate;
|
|
|
- @Autowired
|
|
|
|
|
|
|
+ @Resource
|
|
|
private RedisUtil redisUtil;
|
|
private RedisUtil redisUtil;
|
|
|
@Resource
|
|
@Resource
|
|
|
private IWxUserService wxUserService;
|
|
private IWxUserService wxUserService;
|
|
@@ -73,7 +74,8 @@ private IWxAppConfigService wxAppConfigService;
|
|
|
//通过code获取微信用户信息
|
|
//通过code获取微信用户信息
|
|
|
try {
|
|
try {
|
|
|
WxMaInRedisConfigStorage configStorage = new WxMaInRedisConfigStorage(redisTemplate);
|
|
WxMaInRedisConfigStorage configStorage = new WxMaInRedisConfigStorage(redisTemplate);
|
|
|
- configStorage.setAppid(wxApp.getId());
|
|
|
|
|
|
|
+// WxMaDefaultConfigImpl configStorage = new WxMaDefaultConfigImpl();
|
|
|
|
|
+ configStorage.setAppid(wxApp.getAppId());
|
|
|
configStorage.setSecret(wxApp.getAppSecret());
|
|
configStorage.setSecret(wxApp.getAppSecret());
|
|
|
WxMaService wxMaService = new WxMaServiceImpl();
|
|
WxMaService wxMaService = new WxMaServiceImpl();
|
|
|
wxMaService.setWxMaConfig(configStorage);
|
|
wxMaService.setWxMaConfig(configStorage);
|
|
@@ -92,6 +94,7 @@ private IWxAppConfigService wxAppConfigService;
|
|
|
wxUser.setUnionId(jscode2session.getUnionid());
|
|
wxUser.setUnionId(jscode2session.getUnionid());
|
|
|
} catch (WxErrorException e) {
|
|
} catch (WxErrorException e) {
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
|
|
+
|
|
|
throw new JeecgBootException("小程序获取登录后的微信用户失败:" + e.getMessage());
|
|
throw new JeecgBootException("小程序获取登录后的微信用户失败:" + e.getMessage());
|
|
|
}
|
|
}
|
|
|
System.out.println("【授权登录前】" + wxUser.toString());
|
|
System.out.println("【授权登录前】" + wxUser.toString());
|
|
@@ -99,6 +102,7 @@ private IWxAppConfigService wxAppConfigService;
|
|
|
if (wxUser == null || StrUtil.isBlank(wxUser.getId())) {
|
|
if (wxUser == null || StrUtil.isBlank(wxUser.getId())) {
|
|
|
//新增微信用户
|
|
//新增微信用户
|
|
|
wxUser.setAppId(wxApp.getId());
|
|
wxUser.setAppId(wxApp.getId());
|
|
|
|
|
+ wxUser.setTenantId(TenantContextHolder.getTenantId());
|
|
|
wxUser.setAppType(wxApp.getAppType());
|
|
wxUser.setAppType(wxApp.getAppType());
|
|
|
wxUserService.saveOrUpdate(wxUser);
|
|
wxUserService.saveOrUpdate(wxUser);
|
|
|
}
|
|
}
|
|
@@ -113,7 +117,7 @@ private IWxAppConfigService wxAppConfigService;
|
|
|
String token = UUID.randomUUID().toString();
|
|
String token = UUID.randomUUID().toString();
|
|
|
ThirdSession thirdSession = new ThirdSession();
|
|
ThirdSession thirdSession = new ThirdSession();
|
|
|
thirdSession.setTenantId(wxApp.getTenantId());
|
|
thirdSession.setTenantId(wxApp.getTenantId());
|
|
|
- thirdSession.setAppId(wxApp.getId());
|
|
|
|
|
|
|
+ thirdSession.setAppId(wxApp.getAppId());
|
|
|
thirdSession.setSessionKey(wxUser.getSessionKey());
|
|
thirdSession.setSessionKey(wxUser.getSessionKey());
|
|
|
thirdSession.setWxUserId(wxUser.getId());
|
|
thirdSession.setWxUserId(wxUser.getId());
|
|
|
thirdSession.setOpenId(wxUser.getOpenId());
|
|
thirdSession.setOpenId(wxUser.getOpenId());
|
|
@@ -122,7 +126,7 @@ private IWxAppConfigService wxAppConfigService;
|
|
|
String key = CommonConstant.PREFIX_WX_APP_USER_TOKEN + token;
|
|
String key = CommonConstant.PREFIX_WX_APP_USER_TOKEN + token;
|
|
|
|
|
|
|
|
// 设置token缓存有效时间
|
|
// 设置token缓存有效时间
|
|
|
- redisUtil.set(key, JSONUtils.toJSONString(thirdSession));
|
|
|
|
|
|
|
+ redisUtil.set(key, com.alibaba.fastjson.JSON.toJSONString(thirdSession));
|
|
|
redisUtil.expire(key, JwtUtil.EXPIRE_TIME * 24 * 30 / 1000);
|
|
redisUtil.expire(key, JwtUtil.EXPIRE_TIME * 24 * 30 / 1000);
|
|
|
userInfo.setToken(token);
|
|
userInfo.setToken(token);
|
|
|
return userInfo;
|
|
return userInfo;
|
|
@@ -137,6 +141,7 @@ private IWxAppConfigService wxAppConfigService;
|
|
|
ThirdSession thirdSession = ThirdSessionHolder.getThirdSession();
|
|
ThirdSession thirdSession = ThirdSessionHolder.getThirdSession();
|
|
|
String key = CommonConstant.PREFIX_WX_APP_USER_TOKEN + token;
|
|
String key = CommonConstant.PREFIX_WX_APP_USER_TOKEN + token;
|
|
|
dto.setSessionKey(thirdSession.getSessionKey());
|
|
dto.setSessionKey(thirdSession.getSessionKey());
|
|
|
|
|
+ dto.setAppId(thirdSession.getAppId());
|
|
|
//解密获取手机号
|
|
//解密获取手机号
|
|
|
LambdaQueryWrapper<WxAppConfig> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
LambdaQueryWrapper<WxAppConfig> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
lambdaQueryWrapper.eq(WxAppConfig::getAppId, dto.getAppId());
|
|
lambdaQueryWrapper.eq(WxAppConfig::getAppId, dto.getAppId());
|
|
@@ -147,7 +152,7 @@ private IWxAppConfigService wxAppConfigService;
|
|
|
String phone = "";
|
|
String phone = "";
|
|
|
try {
|
|
try {
|
|
|
WxMaInRedisConfigStorage configStorage = new WxMaInRedisConfigStorage(redisTemplate);
|
|
WxMaInRedisConfigStorage configStorage = new WxMaInRedisConfigStorage(redisTemplate);
|
|
|
- configStorage.setAppid(wxApp.getId());
|
|
|
|
|
|
|
+ configStorage.setAppid(wxApp.getAppId());
|
|
|
configStorage.setSecret(wxApp.getAppSecret());
|
|
configStorage.setSecret(wxApp.getAppSecret());
|
|
|
WxMaService wxMaService = new WxMaServiceImpl();
|
|
WxMaService wxMaService = new WxMaServiceImpl();
|
|
|
wxMaService.setWxMaConfig(configStorage);
|
|
wxMaService.setWxMaConfig(configStorage);
|
|
@@ -172,6 +177,7 @@ private IWxAppConfigService wxAppConfigService;
|
|
|
.eq(MallUserInfo::getMobile, mobile));
|
|
.eq(MallUserInfo::getMobile, mobile));
|
|
|
if (userInfo == null) {//不是商城用户,则新增
|
|
if (userInfo == null) {//不是商城用户,则新增
|
|
|
userInfo = new MallUserInfo();
|
|
userInfo = new MallUserInfo();
|
|
|
|
|
+ userInfo.setTenantId(TenantContextHolder.getTenantId());
|
|
|
userInfo.setCreateTime(DateTime.now());
|
|
userInfo.setCreateTime(DateTime.now());
|
|
|
userInfo.setUpdateTime(DateTime.now());
|
|
userInfo.setUpdateTime(DateTime.now());
|
|
|
}
|
|
}
|
|
@@ -210,6 +216,7 @@ private IWxAppConfigService wxAppConfigService;
|
|
|
String mallUserId = userInfo.getId();
|
|
String mallUserId = userInfo.getId();
|
|
|
wxUser.setUserId(mallUserId);
|
|
wxUser.setUserId(mallUserId);
|
|
|
wxUser.setMobile(mobile);
|
|
wxUser.setMobile(mobile);
|
|
|
|
|
+ wxUserService.saveOrUpdate(wxUser);
|
|
|
|
|
|
|
|
userInfo.setToken(StrUtil.removeAll(key, CommonConstant.PREFIX_WX_APP_USER_TOKEN));
|
|
userInfo.setToken(StrUtil.removeAll(key, CommonConstant.PREFIX_WX_APP_USER_TOKEN));
|
|
|
//更新微信用户
|
|
//更新微信用户
|
|
@@ -217,7 +224,7 @@ private IWxAppConfigService wxAppConfigService;
|
|
|
//更新redis中的thirdSession
|
|
//更新redis中的thirdSession
|
|
|
thirdSession.setUserId(mallUserId);
|
|
thirdSession.setUserId(mallUserId);
|
|
|
// 设置token缓存有效时间
|
|
// 设置token缓存有效时间
|
|
|
- redisUtil.set(key, JSONUtils.toJSONString(thirdSession));
|
|
|
|
|
|
|
+ redisUtil.set(key, com.alibaba.fastjson.JSON.toJSONString(thirdSession));
|
|
|
redisUtil.expire(key, JwtUtil.EXPIRE_TIME * 24 * 30 / 1000);
|
|
redisUtil.expire(key, JwtUtil.EXPIRE_TIME * 24 * 30 / 1000);
|
|
|
return userInfo;
|
|
return userInfo;
|
|
|
}
|
|
}
|