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 delete(Map<String, Object> params);
UserExpandDTO get(Map<String, Object> params);
UserExpandPO getPO(Map<String, Object> params);

View File

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

View File

@ -28,19 +28,23 @@ public class LoginWxUpdatePhoneAuthFilter extends AbstractAuthenticationProcessi
@Override
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException, IOException, ServletException {
PhoneUpdateVO phoneUpdateVO = getPhoneUpdateVO(request);
if (StringUtils.isBlank(phoneUpdateVO.getUserId())) {
throw new BadCredentialsException("userId不能为空");
}
if (StringUtils.isBlank(phoneUpdateVO.getPhone())) {
throw new BadCredentialsException("更新手机号不能为空");
}
if (StringUtils.isBlank(phoneUpdateVO.getSmsCode())) {
throw new BadCredentialsException("手机验证码不能为空");
}
try {
if (StringUtils.isBlank(phoneUpdateVO.getUserId())) {
throw new BadCredentialsException("userId不能为空");
}
if (StringUtils.isBlank(phoneUpdateVO.getPhone())) {
throw new BadCredentialsException("更新手机号不能为空");
}
if (StringUtils.isBlank(phoneUpdateVO.getSmsCode())) {
throw new BadCredentialsException("手机验证码不能为空");
}
smsService.checkVerifyCode(phoneUpdateVO.getPhone(), phoneUpdateVO.getSmsCode());
} catch (ParamsException e) {
throw new UserAuthenticationException(e.getMessage());
} catch (Exception e) {
if (!StringUtils.isBlank(phoneUpdateVO.getErrorRedirectUrl())) {
response.sendRedirect("");
} else {
throw new UserAuthenticationException(e.getMessage());
}
}
LoginWxUpdatePhoneAuthToken loginWxUpdatePhoneAuthToken = new LoginWxUpdatePhoneAuthToken(phoneUpdateVO.getUserId(), phoneUpdateVO);
loginWxUpdatePhoneAuthToken.setDetails(authenticationDetailsSource.buildDetails(request));
@ -51,18 +55,21 @@ public class LoginWxUpdatePhoneAuthFilter extends AbstractAuthenticationProcessi
String userId = request.getParameter("userId");
String phone = request.getParameter("phone");
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 {
private String userId;
private String phone;
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.phone = phone;
this.smsCode = smsCode;
this.errorRedirectUrl = errorRedirectUrl;
}
public String getUserId() {
@ -88,6 +95,14 @@ public class LoginWxUpdatePhoneAuthFilter extends AbstractAuthenticationProcessi
public void setSmsCode(String 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 com.alibaba.fastjson.JSONObject;
import ink.wgink.exceptions.base.SystemException;
import org.apache.commons.lang3.StringUtils;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
@ -13,9 +14,11 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
public class SysCallbackTask implements Job {
@ -33,10 +36,16 @@ public class SysCallbackTask implements Job {
LOG.debug("回调地址:{}", url);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
httpURLConnection.setDoInput(true);
httpURLConnection.setDoOutput(true);
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();
if (responseCode == HttpURLConnection.HTTP_OK) {
BufferedReader reader = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));

View File

@ -468,7 +468,9 @@ public class UserExpandServiceImpl extends DefaultBaseService implements IUserEx
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}
</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
price_additional_pkg,