refactor: 增加微信扫码登录

This commit is contained in:
TS-QD1 2025-04-18 19:03:29 +08:00
parent 8741aadccb
commit c51b14ae1b
6 changed files with 56 additions and 17 deletions

View File

@ -35,6 +35,8 @@ public interface IUserExpandDao {
void updateUserId(Map<String, Object> params); void updateUserId(Map<String, Object> params);
void delete(Map<String, Object> params);
UserExpandDTO get(Map<String, Object> params); UserExpandDTO get(Map<String, Object> params);
UserExpandPO getPO(Map<String, Object> params); UserExpandPO getPO(Map<String, Object> params);

View File

@ -45,6 +45,7 @@ public class LoginWxUpdatePhoneConfig extends SecurityConfigurerAdapter<DefaultS
@Override @Override
public void configure(HttpSecurity http) throws Exception { public void configure(HttpSecurity http) throws Exception {
super.configure(http); super.configure(http);
LoginWxUpdatePhoneAuthFilter loginWxUpdatePhoneAuthFilter = new LoginWxUpdatePhoneAuthFilter(smsService); LoginWxUpdatePhoneAuthFilter loginWxUpdatePhoneAuthFilter = new LoginWxUpdatePhoneAuthFilter(smsService);
loginWxUpdatePhoneAuthFilter.setAuthenticationManager(http.getSharedObject(AuthenticationManager.class)); loginWxUpdatePhoneAuthFilter.setAuthenticationManager(http.getSharedObject(AuthenticationManager.class));
loginWxUpdatePhoneAuthFilter.setAuthenticationFailureHandler(new LoginFailureHandler(baseProperties.getLoginFailure())); loginWxUpdatePhoneAuthFilter.setAuthenticationFailureHandler(new LoginFailureHandler(baseProperties.getLoginFailure()));

View File

@ -28,6 +28,7 @@ public class LoginWxUpdatePhoneAuthFilter extends AbstractAuthenticationProcessi
@Override @Override
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException, IOException, ServletException { public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException, IOException, ServletException {
PhoneUpdateVO phoneUpdateVO = getPhoneUpdateVO(request); PhoneUpdateVO phoneUpdateVO = getPhoneUpdateVO(request);
try {
if (StringUtils.isBlank(phoneUpdateVO.getUserId())) { if (StringUtils.isBlank(phoneUpdateVO.getUserId())) {
throw new BadCredentialsException("userId不能为空"); throw new BadCredentialsException("userId不能为空");
} }
@ -37,11 +38,14 @@ public class LoginWxUpdatePhoneAuthFilter extends AbstractAuthenticationProcessi
if (StringUtils.isBlank(phoneUpdateVO.getSmsCode())) { if (StringUtils.isBlank(phoneUpdateVO.getSmsCode())) {
throw new BadCredentialsException("手机验证码不能为空"); throw new BadCredentialsException("手机验证码不能为空");
} }
try {
smsService.checkVerifyCode(phoneUpdateVO.getPhone(), phoneUpdateVO.getSmsCode()); smsService.checkVerifyCode(phoneUpdateVO.getPhone(), phoneUpdateVO.getSmsCode());
} catch (ParamsException e) { } catch (Exception e) {
if (!StringUtils.isBlank(phoneUpdateVO.getErrorRedirectUrl())) {
response.sendRedirect("");
} else {
throw new UserAuthenticationException(e.getMessage()); throw new UserAuthenticationException(e.getMessage());
} }
}
LoginWxUpdatePhoneAuthToken loginWxUpdatePhoneAuthToken = new LoginWxUpdatePhoneAuthToken(phoneUpdateVO.getUserId(), phoneUpdateVO); LoginWxUpdatePhoneAuthToken loginWxUpdatePhoneAuthToken = new LoginWxUpdatePhoneAuthToken(phoneUpdateVO.getUserId(), phoneUpdateVO);
loginWxUpdatePhoneAuthToken.setDetails(authenticationDetailsSource.buildDetails(request)); loginWxUpdatePhoneAuthToken.setDetails(authenticationDetailsSource.buildDetails(request));
return this.getAuthenticationManager().authenticate(loginWxUpdatePhoneAuthToken); return this.getAuthenticationManager().authenticate(loginWxUpdatePhoneAuthToken);
@ -51,18 +55,21 @@ public class LoginWxUpdatePhoneAuthFilter extends AbstractAuthenticationProcessi
String userId = request.getParameter("userId"); String userId = request.getParameter("userId");
String phone = request.getParameter("phone"); String phone = request.getParameter("phone");
String smsCode = request.getParameter("smsCode"); String smsCode = request.getParameter("smsCode");
return new PhoneUpdateVO(userId, phone, smsCode); String errorRedirectUrl = request.getParameter("errorRedirectUrl");
return new PhoneUpdateVO(userId, phone, smsCode, errorRedirectUrl);
} }
public static class PhoneUpdateVO { public static class PhoneUpdateVO {
private String userId; private String userId;
private String phone; private String phone;
private String smsCode; private String smsCode;
private String errorRedirectUrl;
public PhoneUpdateVO(String userId, String phone, String smsCode) { public PhoneUpdateVO(String userId, String phone, String smsCode, String errorRedirectUrl) {
this.userId = userId; this.userId = userId;
this.phone = phone; this.phone = phone;
this.smsCode = smsCode; this.smsCode = smsCode;
this.errorRedirectUrl = errorRedirectUrl;
} }
public String getUserId() { public String getUserId() {
@ -88,6 +95,14 @@ public class LoginWxUpdatePhoneAuthFilter extends AbstractAuthenticationProcessi
public void setSmsCode(String smsCode) { public void setSmsCode(String smsCode) {
this.smsCode = smsCode; this.smsCode = smsCode;
} }
public String getErrorRedirectUrl() {
return errorRedirectUrl == null ? "" : errorRedirectUrl.trim();
}
public void setErrorRedirectUrl(String errorRedirectUrl) {
this.errorRedirectUrl = errorRedirectUrl;
}
} }

View File

@ -5,6 +5,7 @@ import cn.com.tenlion.operator.pojo.pos.sys.callback.SysCallbackPO;
import cn.com.tenlion.operator.service.sys.task.SysTaskService; import cn.com.tenlion.operator.service.sys.task.SysTaskService;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import ink.wgink.exceptions.base.SystemException; import ink.wgink.exceptions.base.SystemException;
import org.apache.commons.lang3.StringUtils;
import org.quartz.Job; import org.quartz.Job;
import org.quartz.JobDataMap; import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext; import org.quartz.JobExecutionContext;
@ -13,9 +14,11 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.nio.charset.StandardCharsets;
public class SysCallbackTask implements Job { public class SysCallbackTask implements Job {
@ -33,10 +36,16 @@ public class SysCallbackTask implements Job {
LOG.debug("回调地址:{}", url); LOG.debug("回调地址:{}", url);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection(); HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setRequestMethod("POST"); httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
httpURLConnection.setDoInput(true); httpURLConnection.setDoInput(true);
httpURLConnection.setDoOutput(true);
httpURLConnection.setConnectTimeout(3000); httpURLConnection.setConnectTimeout(3000);
httpURLConnection.connect(); httpURLConnection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
if (!StringUtils.isBlank(sysCallbackPO.getJsonBody())) {
try (DataOutputStream dos = new DataOutputStream(httpURLConnection.getOutputStream())) {
byte[] input = sysCallbackPO.getJsonBody().getBytes(StandardCharsets.UTF_8);
dos.write(input, 0, input.length);
}
}
int responseCode = httpURLConnection.getResponseCode(); int responseCode = httpURLConnection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) { if (responseCode == HttpURLConnection.HTTP_OK) {
BufferedReader reader = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream())); BufferedReader reader = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));

View File

@ -468,7 +468,9 @@ public class UserExpandServiceImpl extends DefaultBaseService implements IUserEx
userExpandDao.updateUserId(params); userExpandDao.updateUserId(params);
} }
public void deleteByUserIds(List<String> strings) { public void deleteByUserIds(List<String> userIds) {
Map<String, Object> params = getHashMap(4);
params.put("userIds", userIds);
userExpandDao.delete(params);
} }
} }

View File

@ -257,6 +257,16 @@
user_id = #{userId} user_id = #{userId}
</update> </update>
<delete id="delete" parameterType="map">
DELETE FROM
sys_user_expand
WHERE
user_id IN
<foreach collection="userIds" item="userId" open="(" separator="," close=")">
#{userId}
</foreach>
</delete>
<select id="get" parameterType="map" resultMap="userExpandDTO"> <select id="get" parameterType="map" resultMap="userExpandDTO">
SELECT SELECT
price_additional_pkg, price_additional_pkg,