feat:微信认证

This commit is contained in:
haoxr 2020-10-10 00:55:12 +08:00
parent 96f4080b8a
commit 47177c506f
2 changed files with 8 additions and 6 deletions

View File

@ -19,7 +19,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
http
.authorizeRequests().requestMatchers(EndpointRequest.toAnyEndpoint()).permitAll()
.and()
.authorizeRequests().antMatchers("/rsa/publicKey","/wx/auth/login").permitAll().anyRequest().authenticated()
.authorizeRequests().antMatchers("/rsa/publicKey").permitAll().anyRequest().authenticated()
.and()
.csrf().disable();
}

View File

@ -3,6 +3,7 @@ package com.youlai.auth.controller;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
@ -91,8 +92,8 @@ public class AuthController {
String sessionKey = session.getSessionKey();
MemberDTO memberDTO = remoteUmsMemberService.loadMemberByOpenid(openid);
UmsMember member=new UmsMember();
if (memberDTO == null) {
UmsMember member = new UmsMember();
if (memberDTO == null || memberDTO.getId() == null) {
// 注册会员
String encryptedData = parameters.get("encryptedData");
String iv = parameters.get("iv");
@ -108,12 +109,13 @@ public class AuthController {
if (!ResultCode.SUCCESS.getCode().equals(result.getCode())) {
throw new BizException("注册会员失败");
}
} else {
BeanUtil.copyProperties(memberDTO, member);
}
// 微信授权登录数据模拟生成token
parameters.put("username",member.getUsername());
parameters.put("password",member.getPassword());
parameters.put("username", member.getUsername());
parameters.put("password", member.getUsername());
oAuth2AccessToken = tokenEndpoint.postAccessToken(principal, parameters).getBody();
oauth2Token = Oauth2Token.builder()
.token(oAuth2AccessToken.getValue())