Skip to content

Commit

Permalink
aaa
Browse files Browse the repository at this point in the history
  • Loading branch information
Qi-Zhen-xin committed Mar 31, 2024
1 parent 053ce22 commit 0c712c2
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
19 changes: 15 additions & 4 deletions src/main/java/com/qzx/xdupartner/controller/VerifyController.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.qzx.xdupartner.controller;

import cn.hutool.core.date.DateUtil;
import com.qzx.xdupartner.constant.RedisConstant;
import com.qzx.xdupartner.entity.vo.R;
import com.qzx.xdupartner.entity.vo.ResultCode;
import com.qzx.xdupartner.util.VerCodeGenerateUtil;
Expand Down Expand Up @@ -57,13 +58,23 @@ public R<String> sendCode(@RequestParam("stuId") String stuId) {
"\t<span style=\"font-size:16px;\">亲爱的用户:</span> \n" +
"</h3>\n" +
"<p>\n" +
"\t<span style=\"font-size:14px;\">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style=\"font-size:14px;\">&nbsp; <span style=\"font-size:16px;\">&nbsp;&nbsp;您好!您正在进行邮箱验证,本次请求的验证码为:<span style=\"font-size:24px;color:#FFE500;\"> " + verCode + "</span>,本验证码10分钟内有效,请在10分钟内完成验证。(请勿泄露此验证码)如非本人操作,请忽略该邮件。(这是一封自动发送的邮件,请不要直接回复)</span></span>\n" +
"\t<span style=\"font-size:14px;\">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style=\"font-size:14px;" +
"\">&nbsp; <span style=\"font-size:16px;\">&nbsp;&nbsp;您正在进行邮箱验证,本次请求的验证码为:<span " +
"style=\"font-size:24px;color:#FFE500;\">" + verCode + "</span>,本验证码10分钟内有效,请在10" +
"分钟内完成验证。(请勿泄露此验证码)如非本人操作,请忽略该邮件。(这是一封自动发送的邮件,请不要直接回复)</span></span>\n" +
"</p>\n" +
"<p style=\"text-align:right;\">\n" +
"\t<span style=\"background-color:#FFFFFF;font-size:16px;color:#000000;\"><span style=\"color:#000000;font-size:16px;background-color:#FFFFFF;\"><span class=\"token string\" style=\"font-family:&quot;font-size:16px;color:#000000;line-height:normal !important;background-color:#FFFFFF;\">Share社区</span></span></span> \n" +
"\t<span style=\"background-color:#FFFFFF;font-size:16px;color:#000000;\"><span " +
"style=\"color:#000000;font-size:16px;background-color:#FFFFFF;\"><span class=\"token string\" " +
"style=\"font-family:&quot;font-size:16px;color:#000000;line-height:normal !important;" +
"background-color:#FFFFFF;\">仙电搭子社区</span></span></span> \n" +
"</p>\n" +
"<p style=\"text-align:right;\">\n" +
"\t<span style=\"background-color:#FFFFFF;font-size:14px;\"><span style=\"color:#FF9900;font-size:18px;\"><span class=\"token string\" style=\"font-family:&quot;font-size:16px;color:#000000;line-height:normal !important;\"><span style=\"font-size:16px;color:#000000;background-color:#FFFFFF;\">" + time + "</span><span style=\"font-size:18px;color:#000000;background-color:#FFFFFF;\"></span></span></span></span> \n" +
"\t<span style=\"background-color:#FFFFFF;font-size:14px;\"><span style=\"color:#FF9900;" +
"font-size:18px;\"><span class=\"token string\" style=\"font-family:&quot;font-size:16px;" +
"color:#000000;line-height:normal !important;\"><span style=\"font-size:16px;color:#000000;" +
"background-color:#FFFFFF;\">" + time + "</span><span style=\"font-size:18px;color:#000000;" +
"background-color:#FFFFFF;\"></span></span></span></span> \n" +
"</p>", true);
//收件人
helper.setTo(stuId + "@stu.xidian.edu.cn");
Expand All @@ -79,7 +90,7 @@ public R<String> sendCode(@RequestParam("stuId") String stuId) {
return new R<>(ResultCode.MAIL_SEND_ERROR, "发送失败-邮箱无效");
}
//发送验证码成功
stringRedisTemplate.opsForValue().set(stuId, verCode, 10, TimeUnit.MINUTES);
stringRedisTemplate.opsForValue().set(RedisConstant.MAIL_CODE_PREFIX + stuId, verCode, 10, TimeUnit.MINUTES);
return new R<>(ResultCode.SUCCESS, "发送成功");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ public class WechatController {
public R<WxMaJscode2SessionResult> registor(
@RequestParam("stuId") String stuId,
@RequestParam("code") String code,
@RequestParam("chsiCode") String chsiCode) {
@RequestParam("verCode") String verCode) {

WxMaJscode2SessionResult register = null;
try {
register = userInfoService.register(stuId, code, chsiCode);
register = userInfoService.register(stuId, code, verCode);
} catch (WxErrorException e) {
return new R<>(ResultCode.WECHAT_ERROR, null);
} catch (MailCodeWrongException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

public interface UserInfoService {

WxMaJscode2SessionResult register(String stuId, String code, String chsiCode) throws WxErrorException, MailCodeWrongException;
WxMaJscode2SessionResult register(String stuId, String code, String verCode) throws WxErrorException, MailCodeWrongException;

WxMaJscode2SessionResult login(String code);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ public class UserInfoServiceImpl implements UserInfoService {
private final StringRedisTemplate stringRedisTemplate;

@Override
public WxMaJscode2SessionResult register(String stuId, String code, String chsiCode) throws WxErrorException,MailCodeWrongException {
public WxMaJscode2SessionResult register(String stuId, String code, String verCode) throws WxErrorException,MailCodeWrongException {
//验证邮箱
if (!code.equals(stringRedisTemplate.opsForValue().get(RedisConstant.MAIL_CODE_PREFIX + stuId))) {
String realCode = stringRedisTemplate.opsForValue().get(RedisConstant.MAIL_CODE_PREFIX + stuId);
if (!verCode.equals(realCode)) {
throw new MailCodeWrongException();
}
WxMaJscode2SessionResult session;
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.yml.demo
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
spring:
mail:
username:[email protected]
username: [email protected]
#邮箱授权码,百度一下很简单
password:
host: smtp.qq.com
Expand Down

0 comments on commit 0c712c2

Please sign in to comment.