绑定手机号修改为登陆时缓存session_key(用户在小程序活跃,则session_key一直有效),获取手机号直接取值
This commit is contained in:
@ -97,6 +97,7 @@ public class AuthService {
|
|||||||
}
|
}
|
||||||
WxMaService wxMaService = WxMaConfiguration.getWxMaService();
|
WxMaService wxMaService = WxMaConfiguration.getWxMaService();
|
||||||
WxMaJscode2SessionResult session = wxMaService.getUserService().getSessionInfo(code);
|
WxMaJscode2SessionResult session = wxMaService.getUserService().getSessionInfo(code);
|
||||||
|
|
||||||
WxMaUserInfo wxMpUser = wxMaService.getUserService()
|
WxMaUserInfo wxMpUser = wxMaService.getUserService()
|
||||||
.getUserInfo(session.getSessionKey(), encryptedData, iv);
|
.getUserInfo(session.getSessionKey(), encryptedData, iv);
|
||||||
String openid = wxMpUser.getOpenId();
|
String openid = wxMpUser.getOpenId();
|
||||||
@ -157,6 +158,7 @@ public class AuthService {
|
|||||||
userService.updateById(yxUser);
|
userService.updateById(yxUser);
|
||||||
}
|
}
|
||||||
userService.setSpread(spread, returnUser.getUid());
|
userService.setSpread(spread, returnUser.getUid());
|
||||||
|
redisUtils.set(ShopConstants.YSHOP_MINI_SESSION_KET + yxUser.getUid(), session.getSessionKey());
|
||||||
return returnUser;
|
return returnUser;
|
||||||
} catch (WxErrorException e) {
|
} catch (WxErrorException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -14,6 +14,7 @@ import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
|
|||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import co.yixiang.api.ApiResult;
|
import co.yixiang.api.ApiResult;
|
||||||
import co.yixiang.api.YshopException;
|
import co.yixiang.api.YshopException;
|
||||||
|
import co.yixiang.constant.ShopConstants;
|
||||||
import co.yixiang.logging.aop.log.AppLog;
|
import co.yixiang.logging.aop.log.AppLog;
|
||||||
import co.yixiang.common.bean.LocalUser;
|
import co.yixiang.common.bean.LocalUser;
|
||||||
import co.yixiang.common.interceptor.AuthCheck;
|
import co.yixiang.common.interceptor.AuthCheck;
|
||||||
@ -22,7 +23,9 @@ import co.yixiang.modules.user.service.YxUserService;
|
|||||||
import co.yixiang.modules.wechat.rest.param.BindPhoneParam;
|
import co.yixiang.modules.wechat.rest.param.BindPhoneParam;
|
||||||
import co.yixiang.modules.wechat.rest.param.WxPhoneParam;
|
import co.yixiang.modules.wechat.rest.param.WxPhoneParam;
|
||||||
import co.yixiang.modules.mp.config.WxMaConfiguration;
|
import co.yixiang.modules.mp.config.WxMaConfiguration;
|
||||||
|
import co.yixiang.utils.RedisUtil;
|
||||||
import co.yixiang.utils.RedisUtils;
|
import co.yixiang.utils.RedisUtils;
|
||||||
|
import co.yixiang.utils.SecurityUtils;
|
||||||
import co.yixiang.utils.ShopKeyUtils;
|
import co.yixiang.utils.ShopKeyUtils;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
@ -94,17 +97,13 @@ public class WxMaUserController {
|
|||||||
WxMaService wxMaService = WxMaConfiguration.getWxMaService();
|
WxMaService wxMaService = WxMaConfiguration.getWxMaService();
|
||||||
String phone = "";
|
String phone = "";
|
||||||
try {
|
try {
|
||||||
WxMaJscode2SessionResult session = wxMaService.getUserService()
|
String sessionKey = RedisUtil.get(ShopConstants.YSHOP_MINI_SESSION_KET+ user.getUid()).toString();
|
||||||
.getSessionInfo(param.getCode());
|
|
||||||
|
|
||||||
// 解密
|
|
||||||
WxMaPhoneNumberInfo phoneNoInfo = wxMaService.getUserService()
|
WxMaPhoneNumberInfo phoneNoInfo = wxMaService.getUserService()
|
||||||
.getPhoneNoInfo(session.getSessionKey(), param.getEncryptedData(), param.getIv());
|
.getPhoneNoInfo(sessionKey, param.getEncryptedData(), param.getIv());
|
||||||
|
|
||||||
phone = phoneNoInfo.getPhoneNumber();
|
phone = phoneNoInfo.getPhoneNumber();
|
||||||
user.setPhone(phone);
|
user.setPhone(phone);
|
||||||
userService.updateById(user);
|
userService.updateById(user);
|
||||||
} catch (WxErrorException e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
throw new YshopException("绑定失败");
|
throw new YshopException("绑定失败");
|
||||||
}
|
}
|
||||||
|
@ -173,5 +173,5 @@ public interface ShopConstants {
|
|||||||
|
|
||||||
String DEFAULT_UNI_H5_URL = "https://h5.yixiang.co";
|
String DEFAULT_UNI_H5_URL = "https://h5.yixiang.co";
|
||||||
|
|
||||||
|
String YSHOP_MINI_SESSION_KET = "yshop:session_key:";
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user