微信用户登录接口修正

master
382696293@qq.com 2 years ago
parent f9662eab18
commit ca6a94194c

@ -119,7 +119,7 @@ public class SysLoginService
if (username.length() < UserConstants.USERNAME_MIN_LENGTH
|| username.length() > UserConstants.USERNAME_MAX_LENGTH)
{
throw new ServiceException("账户长度必须在2到20个字符之间");
throw new ServiceException("账户长度必须在2到30个字符之间");
}
if (password.length() < UserConstants.PASSWORD_MIN_LENGTH
|| password.length() > UserConstants.PASSWORD_MAX_LENGTH)

@ -69,7 +69,7 @@ public class UserConstants
*/
public static final int USERNAME_MIN_LENGTH = 2;
public static final int USERNAME_MAX_LENGTH = 20;
public static final int USERNAME_MAX_LENGTH = 30;
/**
*
@ -81,5 +81,5 @@ public class UserConstants
/**
*
*/
public static final String WX_SYSTEM_USER_PASSWORD = "hzUserName.nonymous.@123";
public static final String WX_SYSTEM_USER_PASSWORD = "hzwx.nonymous.@123";
}

@ -149,10 +149,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="isAbutment != null">#{isAbutment},</if>
<if test="collagenDay != null">#{collagenDay},</if>
<if test="collagenMount != null">#{collagenMount},</if>
sysdate(),
<if test="loginTime != null">#{loginTime},</if>
<if test="status != null">#{status},</if>
<if test="createBy != null">#{createBy},</if>
sysdate(),
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="remark != null">#{remark},</if>

@ -9,6 +9,7 @@ import com.flossom.common.core.domain.R;
import com.flossom.common.core.domain.RegisterBody;
import com.flossom.common.core.domain.entity.WxUserMember;
import com.flossom.common.core.exception.ServiceException;
import com.flossom.common.core.utils.DateUtils;
import com.flossom.common.core.web.domain.AjaxResult;
import com.flossom.common.redis.service.RedisService;
import com.flossom.common.security.utils.SecurityUtils;
@ -50,18 +51,23 @@ public class WxUserMemberServiceImpl implements IWxUserMemberService {
public LoginUserVo login(String code) throws Exception {
// 1、使用临时凭证 code 获取 appi + appsecret + unionid
WxCode2SessionRet wxCode2SessionRet = JSON.parseObject(MiniProgramUtils.getSessionKeyAndOpenId(code), WxCode2SessionRet.class);
if (200 != wxCode2SessionRet.getErrcode()) {
if (wxCode2SessionRet.getErrcode() != null) {
logger.error(wxCode2SessionRet.getErrmsg());
throw new ServiceException("校验失败");
}
logger.info("openid", wxCode2SessionRet.getOpenid());
logger.info("unionid", wxCode2SessionRet.getUnionid());
// 2、根据 openid 查询用户信息
WxUserMember wxUserMember = wxUserMemberMapper.selectWxUserMemberByOpenId(wxCode2SessionRet.getOpenid());
if (wxUserMember == null) {
// 未注册用户,就注册游客账户
// 2.1、封装微信用户信息
wxUserMember = new WxUserMember();
wxUserMember.setOpenid(wxCode2SessionRet.getOpenid());
wxUserMember.setUnionid(wxCode2SessionRet.getUnionid());
wxUserMember.setLoginTime(DateUtils.getNowDate());
wxUserMember.setCreateTime(DateUtils.getNowDate());
// 3.2、微信用户表注册
wxUserMemberMapper.insertWxUserMember(wxUserMember);
// 3.3、系统表注册
@ -70,6 +76,7 @@ public class WxUserMemberServiceImpl implements IWxUserMemberService {
registerBody.setPassword(UserConstants.WX_SYSTEM_USER_PASSWORD);
R<?> registerResult = remoteAuthService.register(registerBody);
if (R.FAIL == registerResult.getCode()) {
logger.error("测试后台账号失败:{}", registerResult.getMsg());
throw new ServiceException(registerResult.getMsg());
}
}
@ -77,6 +84,7 @@ public class WxUserMemberServiceImpl implements IWxUserMemberService {
// 3、登录请求获取 token
R<Map<String, String>> loginResult = remoteAuthService.wxLogin(wxUserMember);
if (loginResult.getCode() == R.FAIL) {
logger.error("获取token失败{}", loginResult.getMsg());
throw new ServiceException(loginResult.getMsg());
}
@ -90,6 +98,7 @@ public class WxUserMemberServiceImpl implements IWxUserMemberService {
LoginUserVo loginUserVo = new LoginUserVo();
BeanUtils.copyProperties(wxUserMember, loginUserVo);
loginUserVo.setToken(loginResult.getData().get("access_token"));
logger.info("登录用户信息id = {}, username = {}", loginUserVo.getId(), loginUserVo.getUsername());
return loginUserVo;
}

@ -71,7 +71,7 @@ public class MiniProgramUtils {
Map<String, String> params = new HashMap<>();
params.put("appid", appid);
params.put("secret", secret);
params.put("jsCode", jsCode);
params.put("js_code", jsCode);
params.put("grant_type", grant_type);
return HttpClientUtils.getParameters(wxConfig.getLoginUrl(), params);
}

Loading…
Cancel
Save